@@ -428,6 +428,60 @@ def test_savecopy():
428428 assert idf .idfname == 'test.idf'
429429
430430
431+ def test_shallowcopy ():
432+ """Test that copies made of the IDF using idf.copy remain linked.
433+
434+ Fails if changes to a copy are not reflected in the original, and vice
435+ versa.
436+
437+ """
438+ idf_txt = "Building, The White House, , , , , , , ;"
439+ idf1 = IDF ()
440+ idf1 .initreadtxt (idf_txt )
441+
442+ # make a shallow copy that should remain "entangled" with idf1
443+ idf2 = idf1 .shallowcopy ()
444+
445+ # change building name in idf1 and check in idf2
446+ obj = idf1 .getobject ('BUILDING' , 'The White House' )
447+ obj .Name = 'Big Ben'
448+ assert idf2 .getobject ('BUILDING' , 'Big Ben' )
449+ assert idf1 .idfstr () == idf2 .idfstr () # the two IDFs are the same
450+
451+ # change building name in idf2 and check in idf1
452+ obj = idf2 .getobject ('BUILDING' , 'Big Ben' )
453+ obj .Name = 'The Colosseum'
454+ assert idf1 .getobject ('BUILDING' , 'The Colosseum' )
455+ assert idf1 .idfstr () == idf2 .idfstr () # the two IDFs are the same
456+
457+
458+ def test_deepcopy ():
459+ """Test that copies made of the IDF using idf.deepcopy do not remain linked.
460+
461+ Fails if changes to a copy are reflected in the original, and vice
462+ versa.
463+
464+ """
465+ idf_txt = "Building, The White House, , , , , , , ;"
466+ idf1 = IDF ()
467+ idf1 .initreadtxt (idf_txt )
468+
469+ # make a deep copy that is not linked to the original IDF
470+ idf2 = idf1 .deepcopy ()
471+
472+ # change building name in idf1 and check in idf2
473+ obj = idf1 .getobject ('BUILDING' , 'The White House' )
474+ obj .Name = 'Big Ben'
475+ assert idf2 .getobject ('BUILDING' , 'The White House' ) # unchanged
476+ assert idf1 .idfstr () != idf2 .idfstr () # the two IDFs are not the same
477+
478+ # change building name in idf2 and check in idf1
479+ obj = idf2 .getobject ('BUILDING' , 'The White House' )
480+ obj .Name = 'The Colosseum'
481+ assert not idf1 .getobject ('BUILDING' , 'The Colosseum' )
482+ assert idf1 .idfstr () != idf2 .idfstr () # the two IDFs are not the same
483+
484+
431485def test_initread ():
432486 """Test for IDF.initread() with filename in unicode and as python str.
433487 """
0 commit comments