Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 2 additions & 1 deletion sdk/basyx/aas/backend/local_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,8 @@ def __iter__(self) -> Iterator[model.Identifiable]:
"""
logger.debug("Iterating over objects in database ...")
for name in os.listdir(self.directory_path):
yield self.get_identifiable_by_hash(name.rstrip(".json"))
if name.endswith(".json"):
yield self.get_identifiable_by_hash(name.removesuffix(".json"))

@staticmethod
def _transform_id(identifier: model.Identifier) -> str:
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_iter_ignores_non_json_files(self) -> None:
example_data = create_full_example()
for item in example_data:
self.identifiable_store.add(item)

# Stray files must not crash the iterator or be yielded
stray = os.path.join(store_path, ".DS_Store")
with open(stray, "w") as f:
f.write("stray")
items = list(self.identifiable_store)
self.assertEqual(5, len(items))
os.remove(stray)

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