@@ -70,7 +70,7 @@ def test_value(self):
7070 p5 .extend ("[a, b, c]" )
7171 self .assertEqual (len (p5 ), 5 )
7272
73- p6 = Property ("test" , {"name" : "Marie" , "name" :"Johanna" })
73+ p6 = Property ("test" , {"name" : "Marie" , "name" : "Johanna" })
7474 self .assertEqual (len (p6 ), 1 )
7575
7676 # Test tuple dtype value.
@@ -83,14 +83,6 @@ def test_value(self):
8383 with self .assertRaises (ValueError ):
8484 _ = Property (name = "Public-Key" , value = '(5689; 1254; 687)' , dtype = '2-tuple' )
8585
86- # Test missing tuple length.
87- with self .assertRaises (ValueError ):
88- _ = Property (name = "Public-Key" , value = '(5689; 1254; 687)' , dtype = '-tuple' )
89-
90- # Test invalid tuple format.
91- with self .assertRaises (ValueError ):
92- _ = Property (name = "Public-Key" , value = '5689; 1254; 687' , dtype = '3-tuple' )
93-
9486 def test_get_set_value (self ):
9587 values = [1 , 2 , 3 , 4 , 5 ]
9688 p = Property ("property" , value = values )
@@ -185,7 +177,34 @@ def test_parent(self):
185177 Property ("property_doc" , parent = Document ())
186178
187179 def test_dtype (self ):
188- pass
180+ prop = Property (name = "prop" )
181+
182+ # Test assignment of all supported dtypes.
183+ for curr_type in DType :
184+ prop .dtype = curr_type
185+ self .assertEqual (prop .dtype , curr_type )
186+
187+ # Test assignment of dtype alias.
188+ prop .dtype = "bool"
189+ self .assertEqual (prop .dtype , "bool" )
190+ prop .dtype = "str"
191+ self .assertEqual (prop .dtype , "str" )
192+
193+ # Test assignment of tuple.
194+ prop .dtype = "2-tuple"
195+ self .assertEqual (prop .dtype , "2-tuple" )
196+
197+ # Test set None
198+ prop .dtype = None
199+ self .assertIsNone (prop .dtype )
200+
201+ # Test assignment fails.
202+ with self .assertRaises (AttributeError ):
203+ prop .dtype = 1
204+ with self .assertRaises (AttributeError ):
205+ prop .dtype = "crash and burn"
206+ with self .assertRaises (AttributeError ):
207+ prop .dtype = "x-tuple"
189208
190209 def test_get_path (self ):
191210 doc = Document ()
@@ -207,7 +226,7 @@ def test_value_origin(self):
207226 p .value_origin = ""
208227 self .assertEqual (p .value_origin , None )
209228
210- def test_set_id (self ):
229+ def test_id (self ):
211230 p = Property (name = "P" )
212231 self .assertIsNotNone (p .id )
213232
@@ -221,6 +240,24 @@ def test_set_id(self):
221240 with self .assertRaises (AttributeError ):
222241 p .id = "someId"
223242
243+ def test_new_id (self ):
244+ prop = Property (name = "prop" )
245+ old_id = prop .id
246+
247+ # Test assign new generated id.
248+ prop .new_id ()
249+ self .assertNotEqual (old_id , prop .id )
250+
251+ # Test assign new custom id.
252+ old_id = prop .id
253+ prop .new_id ("79b613eb-a256-46bf-84f6-207df465b8f7" )
254+ self .assertNotEqual (old_id , prop .id )
255+ self .assertEqual ("79b613eb-a256-46bf-84f6-207df465b8f7" , prop .id )
256+
257+ # Test invalid custom id exception.
258+ with self .assertRaises (ValueError ):
259+ prop .new_id ("crash and burn" )
260+
224261 def test_merge (self ):
225262 p_dst = Property ("p1" , value = [1 , 2 , 3 ], unit = "Hz" , definition = "Freude\t schoener\n Goetterfunken\n " ,
226263 reference = "portal.g-node.org" , uncertainty = 0.0 )
0 commit comments