Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sdk/basyx/aas/backend/local_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def __len__(self) -> int:
:return: The number of objects (determined from the number of documents)
"""
logger.debug("Fetching number of documents from database ...")
return len(os.listdir(self.directory_path))
return sum(1 for f in os.listdir(self.directory_path) if f.endswith(".json"))
Comment thread
zrgt marked this conversation as resolved.
Outdated

def __iter__(self) -> Iterator[model.Identifiable]:
"""
Expand Down
13 changes: 13 additions & 0 deletions sdk/test/backend/test_local_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,19 @@ def test_key_errors(self) -> None:
self.assertEqual("'No AAS object with id https://example.org/Test_Submodel exists in "
"local file database'", str(cm.exception))

def test_len_ignores_non_json_files(self) -> None:
example_data = create_full_example()
for item in example_data:
self.identifiable_store.add(item)
self.assertEqual(5, len(self.identifiable_store))

# Stray files must not be counted
stray = os.path.join(store_path, ".DS_Store")
with open(stray, "w") as f:
f.write("stray")
self.assertEqual(5, len(self.identifiable_store))
os.remove(stray)

def test_reload_discard(self) -> None:
# Load example submodel
example_submodel = create_example_submodel()
Expand Down
Loading