11import unittest
22from weakref import WeakSet
3+ import copy
34import string
45from collections import UserString as ustr
56from collections .abc import Set , MutableSet
@@ -15,6 +16,12 @@ class RefCycle:
1516 def __init__ (self ):
1617 self .cycle = self
1718
19+ class WeakSetSubclass (WeakSet ):
20+ pass
21+
22+ class WeakSetWithSlots (WeakSet ):
23+ __slots__ = ('x' , 'y' )
24+
1825
1926class TestWeakSet (unittest .TestCase ):
2027
@@ -455,6 +462,32 @@ def test_abc(self):
455462 self .assertIsInstance (self .s , Set )
456463 self .assertIsInstance (self .s , MutableSet )
457464
465+ # TODO: RUSTPYTHON
466+ @unittest .expectedFailure
467+ def test_copying (self ):
468+ for cls in WeakSet , WeakSetWithSlots :
469+ s = cls (self .items )
470+ s .x = ['x' ]
471+ s .z = ['z' ]
472+
473+ dup = copy .copy (s )
474+ self .assertIsInstance (dup , cls )
475+ self .assertEqual (dup , s )
476+ self .assertIsNot (dup , s )
477+ self .assertIs (dup .x , s .x )
478+ self .assertIs (dup .z , s .z )
479+ self .assertFalse (hasattr (dup , 'y' ))
480+
481+ dup = copy .deepcopy (s )
482+ self .assertIsInstance (dup , cls )
483+ self .assertEqual (dup , s )
484+ self .assertIsNot (dup , s )
485+ self .assertEqual (dup .x , s .x )
486+ self .assertIsNot (dup .x , s .x )
487+ self .assertEqual (dup .z , s .z )
488+ self .assertIsNot (dup .z , s .z )
489+ self .assertFalse (hasattr (dup , 'y' ))
490+
458491
459492if __name__ == "__main__" :
460493 unittest .main ()
0 commit comments