File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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 .endswith (".json" ):
165+ yield self .get_identifiable_by_hash (name .removesuffix (".json" ))
165166
166167 @staticmethod
167168 def _transform_id (identifier : model .Identifier ) -> str :
Original file line number Diff line number Diff line change @@ -107,6 +107,19 @@ def test_key_errors(self) -> None:
107107 self .assertEqual ("'No AAS object with id https://example.org/Test_Submodel exists in "
108108 "local file database'" , str (cm .exception ))
109109
110+ def test_iter_ignores_non_json_files (self ) -> None :
111+ example_data = create_full_example ()
112+ for item in example_data :
113+ self .identifiable_store .add (item )
114+
115+ # Stray files must not crash the iterator or be yielded
116+ stray = os .path .join (store_path , ".DS_Store" )
117+ with open (stray , "w" ) as f :
118+ f .write ("stray" )
119+ items = list (self .identifiable_store )
120+ self .assertEqual (5 , len (items ))
121+ os .remove (stray )
122+
110123 def test_reload_discard (self ) -> None :
111124 # Load example submodel
112125 example_submodel = create_example_submodel ()
You can’t perform that action at this time.
0 commit comments