@@ -187,8 +187,17 @@ def test_parent(self):
187187 def test_dtype (self ):
188188 pass
189189
190- def test_path (self ):
191- pass
190+ def test_get_path (self ):
191+ doc = Document ()
192+ sec = Section (name = "parent" , parent = doc )
193+
194+ # Check root path for a detached Property.
195+ prop = Property (name = "prop" )
196+ self .assertEqual ("/" , prop .get_path ())
197+
198+ # Check absolute path of Property in a Document.
199+ prop .parent = sec
200+ self .assertEqual ("/%s:%s" % (sec .name , prop .name ), prop .get_path ())
192201
193202 def test_value_origin (self ):
194203 p = Property ("P" )
@@ -199,12 +208,19 @@ def test_value_origin(self):
199208 self .assertEqual (p .value_origin , None )
200209
201210 def test_set_id (self ):
211+ p = Property (name = "P" )
212+ self .assertIsNotNone (p .id )
213+
202214 p = Property ("P" , id = "79b613eb-a256-46bf-84f6-207df465b8f7" )
203215 self .assertEqual (p .id , "79b613eb-a256-46bf-84f6-207df465b8f7" )
204216
205- Property ("P" , id = "id" )
217+ p = Property ("P" , id = "id" )
206218 self .assertNotEqual (p .id , "id" )
207219
220+ # Make sure id cannot be reset programmatically.
221+ with self .assertRaises (AttributeError ):
222+ p .id = "someId"
223+
208224 def test_merge (self ):
209225 p_dst = Property ("p1" , value = [1 , 2 , 3 ], unit = "Hz" , definition = "Freude\t schoener\n Goetterfunken\n " ,
210226 reference = "portal.g-node.org" , uncertainty = 0.0 )
@@ -255,6 +271,48 @@ def test_merge(self):
255271 int_p .merge (double_p , strict = False )
256272 self .assertEqual (len (int_p ), 2 )
257273
274+ def test_clone (self ):
275+ sec = Section (name = "parent" )
276+
277+ # Check different id.
278+ prop = Property (name = "original" )
279+ clone_prop = prop .clone ()
280+ self .assertNotEqual (prop .id , clone_prop .id )
281+
282+ # Check parent removal in clone.
283+ prop .parent = sec
284+ clone_prop = prop .clone ()
285+ self .assertIsNotNone (prop .parent )
286+ self .assertIsNone (clone_prop .parent )
287+
288+ def test_get_merged_equivalent (self ):
289+ sec = Section (name = "parent" )
290+ mersec = Section (name = "merged_section" )
291+ merprop_other = Property (name = "other_prop" , value = "other" )
292+ merprop = Property (name = "prop" , value = [1 , 2 , 3 ])
293+
294+ # Check None on unset parent.
295+ prop = Property (name = "prop" )
296+ self .assertIsNone (prop .get_merged_equivalent ())
297+
298+ # Check None on parent without merged Section.
299+ prop .parent = sec
300+ self .assertIsNone (prop .get_merged_equivalent ())
301+
302+ # Check None on parent with merged Section but no attached Property.
303+ sec .merge (mersec )
304+ self .assertIsNone (prop .get_merged_equivalent ())
305+
306+ # Check None on parent with merged Section and unequal Property.
307+ merprop_other .parent = mersec
308+ self .assertIsNone (prop .get_merged_equivalent ())
309+
310+ # Check receiving merged equivalent Property.
311+ merprop .parent = mersec
312+ self .assertIsNotNone (prop .get_merged_equivalent ())
313+ self .assertEqual (prop .get_merged_equivalent (), merprop )
314+
315+
258316if __name__ == "__main__" :
259317 print ("TestProperty" )
260318 tp = TestProperty ()
0 commit comments