Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4dc9c84

Browse files
committed
#11572: improvements to copy module tests along with removal of old test suite
1 parent 29f6297 commit 4dc9c84

2 files changed

Lines changed: 95 additions & 138 deletions

File tree

Lib/copy.py

Lines changed: 0 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -323,68 +323,3 @@ def _reconstruct(x, info, deep, memo=None):
323323
# Helper for instance creation without calling __init__
324324
class _EmptyClass:
325325
pass
326-
327-
def _test():
328-
l = [None, 1, 2, 3.14, 'xyzzy', (1, 2), [3.14, 'abc'],
329-
{'abc': 'ABC'}, (), [], {}]
330-
l1 = copy(l)
331-
print(l1==l)
332-
l1 = map(copy, l)
333-
print(l1==l)
334-
l1 = deepcopy(l)
335-
print(l1==l)
336-
class C:
337-
def __init__(self, arg=None):
338-
self.a = 1
339-
self.arg = arg
340-
if __name__ == '__main__':
341-
import sys
342-
file = sys.argv[0]
343-
else:
344-
file = __file__
345-
self.fp = open(file)
346-
self.fp.close()
347-
def __getstate__(self):
348-
return {'a': self.a, 'arg': self.arg}
349-
def __setstate__(self, state):
350-
for key, value in state.items():
351-
setattr(self, key, value)
352-
def __deepcopy__(self, memo=None):
353-
new = self.__class__(deepcopy(self.arg, memo))
354-
new.a = self.a
355-
return new
356-
c = C('argument sketch')
357-
l.append(c)
358-
l2 = copy(l)
359-
print(l == l2)
360-
print(l)
361-
print(l2)
362-
l2 = deepcopy(l)
363-
print(l == l2)
364-
print(l)
365-
print(l2)
366-
l.append({l[1]: l, 'xyz': l[2]})
367-
l3 = copy(l)
368-
import reprlib
369-
print(map(reprlib.repr, l))
370-
print(map(reprlib.repr, l1))
371-
print(map(reprlib.repr, l2))
372-
print(map(reprlib.repr, l3))
373-
l3 = deepcopy(l)
374-
print(map(reprlib.repr, l))
375-
print(map(reprlib.repr, l1))
376-
print(map(reprlib.repr, l2))
377-
print(map(reprlib.repr, l3))
378-
class odict(dict):
379-
def __init__(self, d = {}):
380-
self.a = 99
381-
dict.__init__(self, d)
382-
def __setitem__(self, k, i):
383-
dict.__setitem__(self, k, i)
384-
self.a
385-
o = odict({"A" : "B"})
386-
x = deepcopy(o)
387-
print(o, x)
388-
389-
if __name__ == '__main__':
390-
_test()

0 commit comments

Comments
 (0)