Skip to content

Commit 9bbbeb9

Browse files
committed
merge: incorporate fix/b6-local-file-iter into fix/b10-local-file-len
Merge __iter__ fix (filter non-.json files, use name[:-5] for suffix removal) together with __len__ fix (case-insensitive .json filter). Apply consistent f.lower().endswith(".json") to both methods. Keep both test_add_and_len_consistent and test_iter_ignores_non_json_files. Closes #499
2 parents effc30c + 8feebf0 commit 9bbbeb9

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

sdk/basyx/aas/backend/local_file.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,8 @@ def __iter__(self) -> Iterator[model.Identifiable]:
161161
"""
162162
logger.debug("Iterating over objects in database ...")
163163
for name in os.listdir(self.directory_path):
164-
yield self.get_identifiable_by_hash(name.rstrip(".json"))
164+
if name.lower().endswith(".json"):
165+
yield self.get_identifiable_by_hash(name[:-5])
165166

166167
@staticmethod
167168
def _transform_id(identifier: model.Identifier) -> str:

sdk/test/backend/test_local_file.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,19 @@ def test_add_and_len_consistent(self) -> None:
121121
self.assertEqual(len(example_data), len(self.identifiable_store))
122122
os.remove(stray)
123123

124+
def test_iter_ignores_non_json_files(self) -> None:
125+
example_data = create_full_example()
126+
for item in example_data:
127+
self.identifiable_store.add(item)
128+
129+
# Stray files must not crash the iterator or be yielded
130+
stray = os.path.join(store_path, ".DS_Store")
131+
with open(stray, "w") as f:
132+
f.write("stray")
133+
items = list(self.identifiable_store)
134+
self.assertEqual(5, len(items))
135+
os.remove(stray)
136+
124137
def test_reload_discard(self) -> None:
125138
# Load example submodel
126139
example_submodel = create_example_submodel()

0 commit comments

Comments
 (0)