1111
1212
1313class ProvidersTest (unittest .TestCase ):
14+ _STORE_CLASSES = (model .DictIdentifiableStore , model .SetIdentifiableStore )
15+
1416 def setUp (self ) -> None :
1517 self .aas1 = model .AssetAdministrationShell (
1618 model .AssetInformation (global_asset_id = "http://example.org/TestAsset1/" ), "urn:x-test:aas1" )
@@ -20,58 +22,76 @@ def setUp(self) -> None:
2022 self .submodel2 = model .Submodel ("urn:x-test:submodel2" )
2123
2224 def test_store_retrieve (self ) -> None :
23- identifiable_store : model .DictIdentifiableStore [model .AssetAdministrationShell ] = model .DictIdentifiableStore ()
24- identifiable_store .add (self .aas1 )
25- identifiable_store .add (self .aas2 )
26- self .assertIn (self .aas1 , identifiable_store )
27- property = model .Property ('test' , model .datatypes .String )
28- self .assertFalse (property in identifiable_store )
29- aas3 = model .AssetAdministrationShell (model .AssetInformation (global_asset_id = "http://example.org/TestAsset/" ),
30- "urn:x-test:aas1" )
31- with self .assertRaises (KeyError ) as cm :
32- identifiable_store .add (aas3 )
33- self .assertEqual ("'Identifiable object with same id urn:x-test:aas1 is already "
34- "stored in this store'" , str (cm .exception ))
35- self .assertEqual (2 , len (identifiable_store ))
36- self .assertIs (self .aas1 ,
37- identifiable_store .get_item ("urn:x-test:aas1" ))
38- self .assertIs (self .aas1 ,
39- identifiable_store .get ("urn:x-test:aas1" ))
40- identifiable_store .discard (self .aas1 )
41- identifiable_store .discard (self .aas1 )
42- with self .assertRaises (KeyError ) as cm :
43- identifiable_store .get_item ("urn:x-test:aas1" )
44- self .assertIsNone (identifiable_store .get ("urn:x-test:aas1" ))
45- self .assertEqual ("'urn:x-test:aas1'" , str (cm .exception ))
46- self .assertIs (self .aas2 , identifiable_store .pop ())
47- self .assertEqual (0 , len (identifiable_store ))
25+ for store_class in self ._STORE_CLASSES :
26+ with self .subTest (store = store_class .__name__ ):
27+ store = store_class ([self .aas1 ])
28+ store .add (self .aas2 )
29+
30+ store .add (self .aas1 )
31+ self .assertEqual (2 , len (store ))
32+
33+ self .assertIn (self .aas1 , store )
34+ self .assertIn ("urn:x-test:aas1" , store )
35+ self .assertNotIn ("urn:x-test:missing" , store )
36+ property = model .Property ('test' , model .datatypes .String )
37+ self .assertFalse (property in store )
38+ aas3 = model .AssetAdministrationShell (
39+ model .AssetInformation (global_asset_id = "http://example.org/TestAsset/" ), "urn:x-test:aas1" )
40+ with self .assertRaises (KeyError ) as cm :
41+ store .add (aas3 )
42+ self .assertEqual ("'Identifiable object with same id urn:x-test:aas1 is already "
43+ "stored in this store'" , str (cm .exception ))
44+ self .assertEqual (2 , len (store ))
45+ self .assertIs (self .aas1 , store .get_item ("urn:x-test:aas1" ))
46+ self .assertIs (self .aas1 , store .get ("urn:x-test:aas1" ))
47+ store .discard (self .aas1 )
48+ store .discard (self .aas1 )
49+ with self .assertRaises (KeyError ) as cm :
50+ store .get_item ("urn:x-test:aas1" )
51+ self .assertIsNone (store .get ("urn:x-test:aas1" ))
52+ self .assertEqual ("'urn:x-test:aas1'" , str (cm .exception ))
53+ self .assertIs (self .aas2 , store .pop ())
54+ self .assertEqual (0 , len (store ))
4855
4956 def test_store_update (self ) -> None :
50- identifiable_store1 : model .DictIdentifiableStore [model .AssetAdministrationShell ] = model .DictIdentifiableStore ()
51- identifiable_store1 .add (self .aas1 )
52- identifiable_store2 : model .DictIdentifiableStore [model .AssetAdministrationShell ] = model .DictIdentifiableStore ()
53- identifiable_store2 .add (self .aas2 )
54- identifiable_store1 .update (identifiable_store2 )
55- self .assertIsInstance (identifiable_store1 , model .DictIdentifiableStore )
56- self .assertIn (self .aas2 , identifiable_store1 )
57+ for store_class in self ._STORE_CLASSES :
58+ with self .subTest (store = store_class .__name__ ):
59+ store1 = store_class ()
60+ store1 .add (self .aas1 )
61+ store2 = store_class ()
62+ store2 .add (self .aas2 )
63+ store1 .update (store2 )
64+ self .assertIsInstance (store1 , store_class )
65+ self .assertIn (self .aas2 , store1 )
5766
5867 def test_store_sync (self ) -> None :
59- aas_identifiable_store : model .DictIdentifiableStore [model .Identifiable ] = model .DictIdentifiableStore ()
68+ for store_class in self ._STORE_CLASSES :
69+ with self .subTest (store = store_class .__name__ ):
70+ store = store_class ()
71+ self .assertEqual (store .sync ([self .aas1 , self .aas2 ], overwrite = False ), (2 , 0 , 0 ))
72+ self .assertIn (self .aas1 , store )
73+ self .assertIn (self .aas2 , store )
6074
61- self .assertEqual (aas_identifiable_store .sync ([self .aas1 , self .aas2 ], overwrite = False ), (2 , 0 , 0 ))
62- self .assertIn (self .aas1 , aas_identifiable_store )
63- self .assertIn (self .aas2 , aas_identifiable_store )
75+ self .assertEqual (store .sync ([self .aas1 ], overwrite = False ), (0 , 0 , 1 ))
6476
65- self .assertEqual (aas_identifiable_store .sync ([self .aas1 ], overwrite = False ), (0 , 0 , 1 ))
77+ self .assertEqual (store .sync ([self .aas1 ], overwrite = True ), (0 , 1 , 0 ))
78+ self .assertIn (self .aas1 , store )
6679
67- self .assertEqual (aas_identifiable_store .sync ([self .aas1 ], overwrite = True ), (0 , 1 , 0 ))
68- self .assertIn (self .aas1 , aas_identifiable_store )
80+ self .assertEqual (store .sync ([self .aas1 , self .submodel1 ], overwrite = True ), (1 , 1 , 0 ))
6981
70- self .assertEqual (aas_identifiable_store .sync ([self .aas1 , self .submodel1 ], overwrite = True ), (1 , 1 , 0 ))
82+ self .assertEqual (store .sync ([self .aas1 , self .submodel2 ], overwrite = False ), (1 , 0 , 1 ))
7183
72- self .assertEqual (aas_identifiable_store .sync ([self . aas1 , self . submodel2 ], overwrite = False ), (1 , 0 , 1 ))
84+ self .assertEqual (store .sync ([], overwrite = False ), (0 , 0 , 0 ))
7385
74- self .assertEqual (aas_identifiable_store .sync ([], overwrite = False ), (0 , 0 , 0 ))
86+ def test_store_remove (self ) -> None :
87+ for store_class in self ._STORE_CLASSES :
88+ with self .subTest (store = store_class .__name__ ):
89+ store = store_class ()
90+ store .add (self .aas1 )
91+ store .remove (self .aas1 )
92+ self .assertEqual (0 , len (store ))
93+ with self .assertRaises (KeyError ):
94+ store .remove (self .aas1 )
7595
7696 def test_provider_multiplexer (self ) -> None :
7797 aas_identifiable_store : model .DictIdentifiableStore [model .Identifiable ] = (
0 commit comments