@@ -123,17 +123,20 @@ def test_node_empty_init(NodeClass, base):
123123
124124
125125@pytest .mark .parametrize (
126- "node" ,
126+ "node,base_type " ,
127127 [
128- AsdfDictNode ({"a" : 1 , "b" : 2 }),
129- AsdfListNode ([1 , 2 , 3 ]),
130- AsdfOrderedDictNode ({"a" : 1 , "b" : 2 }),
128+ ( AsdfDictNode ({"a" : 1 , "b" : 2 }), dict ),
129+ ( AsdfListNode ([1 , 2 , 3 ]), list ),
130+ ( AsdfOrderedDictNode ({"a" : 1 , "b" : 2 }), collections . OrderedDict ),
131131 ],
132132)
133133@pytest .mark .parametrize ("copy_operation" , [copy .copy , copy .deepcopy ])
134- def test_copy (node , copy_operation ):
134+ def test_copy (node , base_type , copy_operation ):
135135 copied_node = copy_operation (node )
136- assert isinstance (copied_node , type (node ))
136+ if copy_operation is copy .copy :
137+ assert type (copied_node ) is type (node )
138+ else :
139+ assert type (copied_node ) is base_type
137140 assert copied_node == node
138141
139142
@@ -408,3 +411,26 @@ def test_lazy_generator_converter(tmp_path, lazy_generator_class):
408411
409412 with asdf .open (fn , lazy_tree = True ) as af :
410413 assert isinstance (af ["obj" ].data , dict )
414+
415+
416+ def test_lazy_copy (tmp_path ):
417+ """
418+ Test that copying an AsdfFile instance with a lazy
419+ tree doesn't result in the copy retaining references
420+ to the instance.
421+ """
422+ fn = tmp_path / "test.asdf"
423+ obj = asdf .tags .core .IntegerType (1 )
424+ tree = {"a" : {"b" : obj }}
425+ # make a recursive structure
426+ tree ["a" ]["c" ] = tree ["a" ]
427+
428+ asdf .AsdfFile (tree ).write_to (fn )
429+
430+ with asdf .open (fn , lazy_tree = True ) as af :
431+ af2 = af .copy ()
432+
433+ del af
434+ gc .collect (2 )
435+ assert af2 ["a" ]["b" ] == obj
436+ assert af2 ["a" ]["c" ]["b" ] is af2 ["a" ]["b" ]
0 commit comments