Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
4dc9c84e
Kaydet (Commit)
4dc9c84e
authored
Agu 05, 2011
tarafından
Sandro Tosi
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
#11572: improvements to copy module tests along with removal of old test suite
üst
29f62976
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
95 additions
and
138 deletions
+95
-138
copy.py
Lib/copy.py
+0
-65
test_copy.py
Lib/test/test_copy.py
+95
-73
No files found.
Lib/copy.py
Dosyayı görüntüle @
4dc9c84e
...
@@ -323,68 +323,3 @@ del types
...
@@ -323,68 +323,3 @@ del types
# Helper for instance creation without calling __init__
# Helper for instance creation without calling __init__
class
_EmptyClass
:
class
_EmptyClass
:
pass
pass
def
_test
():
l
=
[
None
,
1
,
2
,
3.14
,
'xyzzy'
,
(
1
,
2
),
[
3.14
,
'abc'
],
{
'abc'
:
'ABC'
},
(),
[],
{}]
l1
=
copy
(
l
)
print
(
l1
==
l
)
l1
=
map
(
copy
,
l
)
print
(
l1
==
l
)
l1
=
deepcopy
(
l
)
print
(
l1
==
l
)
class
C
:
def
__init__
(
self
,
arg
=
None
):
self
.
a
=
1
self
.
arg
=
arg
if
__name__
==
'__main__'
:
import
sys
file
=
sys
.
argv
[
0
]
else
:
file
=
__file__
self
.
fp
=
open
(
file
)
self
.
fp
.
close
()
def
__getstate__
(
self
):
return
{
'a'
:
self
.
a
,
'arg'
:
self
.
arg
}
def
__setstate__
(
self
,
state
):
for
key
,
value
in
state
.
items
():
setattr
(
self
,
key
,
value
)
def
__deepcopy__
(
self
,
memo
=
None
):
new
=
self
.
__class__
(
deepcopy
(
self
.
arg
,
memo
))
new
.
a
=
self
.
a
return
new
c
=
C
(
'argument sketch'
)
l
.
append
(
c
)
l2
=
copy
(
l
)
print
(
l
==
l2
)
print
(
l
)
print
(
l2
)
l2
=
deepcopy
(
l
)
print
(
l
==
l2
)
print
(
l
)
print
(
l2
)
l
.
append
({
l
[
1
]:
l
,
'xyz'
:
l
[
2
]})
l3
=
copy
(
l
)
import
reprlib
print
(
map
(
reprlib
.
repr
,
l
))
print
(
map
(
reprlib
.
repr
,
l1
))
print
(
map
(
reprlib
.
repr
,
l2
))
print
(
map
(
reprlib
.
repr
,
l3
))
l3
=
deepcopy
(
l
)
print
(
map
(
reprlib
.
repr
,
l
))
print
(
map
(
reprlib
.
repr
,
l1
))
print
(
map
(
reprlib
.
repr
,
l2
))
print
(
map
(
reprlib
.
repr
,
l3
))
class
odict
(
dict
):
def
__init__
(
self
,
d
=
{}):
self
.
a
=
99
dict
.
__init__
(
self
,
d
)
def
__setitem__
(
self
,
k
,
i
):
dict
.
__setitem__
(
self
,
k
,
i
)
self
.
a
o
=
odict
({
"A"
:
"B"
})
x
=
deepcopy
(
o
)
print
(
o
,
x
)
if
__name__
==
'__main__'
:
_test
()
Lib/test/test_copy.py
Dosyayı görüntüle @
4dc9c84e
...
@@ -17,7 +17,7 @@ class TestCopy(unittest.TestCase):
...
@@ -17,7 +17,7 @@ class TestCopy(unittest.TestCase):
# Attempt full line coverage of copy.py from top to bottom
# Attempt full line coverage of copy.py from top to bottom
def
test_exceptions
(
self
):
def
test_exceptions
(
self
):
self
.
assert
True
(
copy
.
Error
is
copy
.
error
)
self
.
assert
Is
(
copy
.
Error
,
copy
.
error
)
self
.
assertTrue
(
issubclass
(
copy
.
Error
,
Exception
))
self
.
assertTrue
(
issubclass
(
copy
.
Error
,
Exception
))
# The copy() method
# The copy() method
...
@@ -54,20 +54,26 @@ class TestCopy(unittest.TestCase):
...
@@ -54,20 +54,26 @@ class TestCopy(unittest.TestCase):
def
test_copy_reduce_ex
(
self
):
def
test_copy_reduce_ex
(
self
):
class
C
(
object
):
class
C
(
object
):
def
__reduce_ex__
(
self
,
proto
):
def
__reduce_ex__
(
self
,
proto
):
c
.
append
(
1
)
return
""
return
""
def
__reduce__
(
self
):
def
__reduce__
(
self
):
raise
support
.
TestFailed
(
"shouldn't call this"
)
self
.
fail
(
"shouldn't call this"
)
c
=
[]
x
=
C
()
x
=
C
()
y
=
copy
.
copy
(
x
)
y
=
copy
.
copy
(
x
)
self
.
assertTrue
(
y
is
x
)
self
.
assertIs
(
y
,
x
)
self
.
assertEqual
(
c
,
[
1
])
def
test_copy_reduce
(
self
):
def
test_copy_reduce
(
self
):
class
C
(
object
):
class
C
(
object
):
def
__reduce__
(
self
):
def
__reduce__
(
self
):
c
.
append
(
1
)
return
""
return
""
c
=
[]
x
=
C
()
x
=
C
()
y
=
copy
.
copy
(
x
)
y
=
copy
.
copy
(
x
)
self
.
assertTrue
(
y
is
x
)
self
.
assertIs
(
y
,
x
)
self
.
assertEqual
(
c
,
[
1
])
def
test_copy_cant
(
self
):
def
test_copy_cant
(
self
):
class
C
(
object
):
class
C
(
object
):
...
@@ -91,7 +97,7 @@ class TestCopy(unittest.TestCase):
...
@@ -91,7 +97,7 @@ class TestCopy(unittest.TestCase):
"hello"
,
"hello
\u1234
"
,
f
.
__code__
,
"hello"
,
"hello
\u1234
"
,
f
.
__code__
,
NewStyle
,
range
(
10
),
Classic
,
max
]
NewStyle
,
range
(
10
),
Classic
,
max
]
for
x
in
tests
:
for
x
in
tests
:
self
.
assert
True
(
copy
.
copy
(
x
)
is
x
,
repr
(
x
)
)
self
.
assert
Is
(
copy
.
copy
(
x
),
x
)
def
test_copy_list
(
self
):
def
test_copy_list
(
self
):
x
=
[
1
,
2
,
3
]
x
=
[
1
,
2
,
3
]
...
@@ -185,9 +191,9 @@ class TestCopy(unittest.TestCase):
...
@@ -185,9 +191,9 @@ class TestCopy(unittest.TestCase):
x
=
[
x
,
x
]
x
=
[
x
,
x
]
y
=
copy
.
deepcopy
(
x
)
y
=
copy
.
deepcopy
(
x
)
self
.
assertEqual
(
y
,
x
)
self
.
assertEqual
(
y
,
x
)
self
.
assert
True
(
y
is
not
x
)
self
.
assert
IsNot
(
y
,
x
)
self
.
assert
True
(
y
[
0
]
is
not
x
[
0
])
self
.
assert
IsNot
(
y
[
0
],
x
[
0
])
self
.
assert
True
(
y
[
0
]
is
y
[
1
])
self
.
assert
Is
(
y
[
0
],
y
[
1
])
def
test_deepcopy_issubclass
(
self
):
def
test_deepcopy_issubclass
(
self
):
# XXX Note: there's no way to test the TypeError coming out of
# XXX Note: there's no way to test the TypeError coming out of
...
@@ -227,20 +233,26 @@ class TestCopy(unittest.TestCase):
...
@@ -227,20 +233,26 @@ class TestCopy(unittest.TestCase):
def
test_deepcopy_reduce_ex
(
self
):
def
test_deepcopy_reduce_ex
(
self
):
class
C
(
object
):
class
C
(
object
):
def
__reduce_ex__
(
self
,
proto
):
def
__reduce_ex__
(
self
,
proto
):
c
.
append
(
1
)
return
""
return
""
def
__reduce__
(
self
):
def
__reduce__
(
self
):
raise
support
.
TestFailed
(
"shouldn't call this"
)
self
.
fail
(
"shouldn't call this"
)
c
=
[]
x
=
C
()
x
=
C
()
y
=
copy
.
deepcopy
(
x
)
y
=
copy
.
deepcopy
(
x
)
self
.
assertTrue
(
y
is
x
)
self
.
assertIs
(
y
,
x
)
self
.
assertEqual
(
c
,
[
1
])
def
test_deepcopy_reduce
(
self
):
def
test_deepcopy_reduce
(
self
):
class
C
(
object
):
class
C
(
object
):
def
__reduce__
(
self
):
def
__reduce__
(
self
):
c
.
append
(
1
)
return
""
return
""
c
=
[]
x
=
C
()
x
=
C
()
y
=
copy
.
deepcopy
(
x
)
y
=
copy
.
deepcopy
(
x
)
self
.
assertTrue
(
y
is
x
)
self
.
assertIs
(
y
,
x
)
self
.
assertEqual
(
c
,
[
1
])
def
test_deepcopy_cant
(
self
):
def
test_deepcopy_cant
(
self
):
class
C
(
object
):
class
C
(
object
):
...
@@ -264,14 +276,14 @@ class TestCopy(unittest.TestCase):
...
@@ -264,14 +276,14 @@ class TestCopy(unittest.TestCase):
"hello"
,
"hello
\u1234
"
,
f
.
__code__
,
"hello"
,
"hello
\u1234
"
,
f
.
__code__
,
NewStyle
,
range
(
10
),
Classic
,
max
]
NewStyle
,
range
(
10
),
Classic
,
max
]
for
x
in
tests
:
for
x
in
tests
:
self
.
assert
True
(
copy
.
deepcopy
(
x
)
is
x
,
repr
(
x
)
)
self
.
assert
Is
(
copy
.
deepcopy
(
x
),
x
)
def
test_deepcopy_list
(
self
):
def
test_deepcopy_list
(
self
):
x
=
[[
1
,
2
],
3
]
x
=
[[
1
,
2
],
3
]
y
=
copy
.
deepcopy
(
x
)
y
=
copy
.
deepcopy
(
x
)
self
.
assertEqual
(
y
,
x
)
self
.
assertEqual
(
y
,
x
)
self
.
assert
True
(
x
is
not
y
)
self
.
assert
IsNot
(
x
,
y
)
self
.
assert
True
(
x
[
0
]
is
not
y
[
0
])
self
.
assert
IsNot
(
x
[
0
],
y
[
0
])
def
test_deepcopy_reflexive_list
(
self
):
def
test_deepcopy_reflexive_list
(
self
):
x
=
[]
x
=
[]
...
@@ -279,16 +291,26 @@ class TestCopy(unittest.TestCase):
...
@@ -279,16 +291,26 @@ class TestCopy(unittest.TestCase):
y
=
copy
.
deepcopy
(
x
)
y
=
copy
.
deepcopy
(
x
)
for
op
in
comparisons
:
for
op
in
comparisons
:
self
.
assertRaises
(
RuntimeError
,
op
,
y
,
x
)
self
.
assertRaises
(
RuntimeError
,
op
,
y
,
x
)
self
.
assert
True
(
y
is
not
x
)
self
.
assert
IsNot
(
y
,
x
)
self
.
assert
True
(
y
[
0
]
is
y
)
self
.
assert
Is
(
y
[
0
],
y
)
self
.
assertEqual
(
len
(
y
),
1
)
self
.
assertEqual
(
len
(
y
),
1
)
def
test_deepcopy_empty_tuple
(
self
):
x
=
()
y
=
copy
.
deepcopy
(
x
)
self
.
assertIs
(
x
,
y
)
def
test_deepcopy_tuple
(
self
):
def
test_deepcopy_tuple
(
self
):
x
=
([
1
,
2
],
3
)
x
=
([
1
,
2
],
3
)
y
=
copy
.
deepcopy
(
x
)
y
=
copy
.
deepcopy
(
x
)
self
.
assertEqual
(
y
,
x
)
self
.
assertEqual
(
y
,
x
)
self
.
assertTrue
(
x
is
not
y
)
self
.
assertIsNot
(
x
,
y
)
self
.
assertTrue
(
x
[
0
]
is
not
y
[
0
])
self
.
assertIsNot
(
x
[
0
],
y
[
0
])
def
test_deepcopy_tuple_of_immutables
(
self
):
x
=
((
1
,
2
),
3
)
y
=
copy
.
deepcopy
(
x
)
self
.
assertIs
(
x
,
y
)
def
test_deepcopy_reflexive_tuple
(
self
):
def
test_deepcopy_reflexive_tuple
(
self
):
x
=
([],)
x
=
([],)
...
@@ -296,16 +318,16 @@ class TestCopy(unittest.TestCase):
...
@@ -296,16 +318,16 @@ class TestCopy(unittest.TestCase):
y
=
copy
.
deepcopy
(
x
)
y
=
copy
.
deepcopy
(
x
)
for
op
in
comparisons
:
for
op
in
comparisons
:
self
.
assertRaises
(
RuntimeError
,
op
,
y
,
x
)
self
.
assertRaises
(
RuntimeError
,
op
,
y
,
x
)
self
.
assert
True
(
y
is
not
x
)
self
.
assert
IsNot
(
y
,
x
)
self
.
assert
True
(
y
[
0
]
is
not
x
[
0
])
self
.
assert
IsNot
(
y
[
0
],
x
[
0
])
self
.
assert
True
(
y
[
0
][
0
]
is
y
)
self
.
assert
Is
(
y
[
0
][
0
],
y
)
def
test_deepcopy_dict
(
self
):
def
test_deepcopy_dict
(
self
):
x
=
{
"foo"
:
[
1
,
2
],
"bar"
:
3
}
x
=
{
"foo"
:
[
1
,
2
],
"bar"
:
3
}
y
=
copy
.
deepcopy
(
x
)
y
=
copy
.
deepcopy
(
x
)
self
.
assertEqual
(
y
,
x
)
self
.
assertEqual
(
y
,
x
)
self
.
assert
True
(
x
is
not
y
)
self
.
assert
IsNot
(
x
,
y
)
self
.
assert
True
(
x
[
"foo"
]
is
not
y
[
"foo"
])
self
.
assert
IsNot
(
x
[
"foo"
],
y
[
"foo"
])
def
test_deepcopy_reflexive_dict
(
self
):
def
test_deepcopy_reflexive_dict
(
self
):
x
=
{}
x
=
{}
...
@@ -315,8 +337,8 @@ class TestCopy(unittest.TestCase):
...
@@ -315,8 +337,8 @@ class TestCopy(unittest.TestCase):
self
.
assertRaises
(
TypeError
,
op
,
y
,
x
)
self
.
assertRaises
(
TypeError
,
op
,
y
,
x
)
for
op
in
equality_comparisons
:
for
op
in
equality_comparisons
:
self
.
assertRaises
(
RuntimeError
,
op
,
y
,
x
)
self
.
assertRaises
(
RuntimeError
,
op
,
y
,
x
)
self
.
assert
True
(
y
is
not
x
)
self
.
assert
IsNot
(
y
,
x
)
self
.
assert
True
(
y
[
'foo'
]
is
y
)
self
.
assert
Is
(
y
[
'foo'
],
y
)
self
.
assertEqual
(
len
(
y
),
1
)
self
.
assertEqual
(
len
(
y
),
1
)
def
test_deepcopy_keepalive
(
self
):
def
test_deepcopy_keepalive
(
self
):
...
@@ -349,7 +371,7 @@ class TestCopy(unittest.TestCase):
...
@@ -349,7 +371,7 @@ class TestCopy(unittest.TestCase):
x
=
C
([
42
])
x
=
C
([
42
])
y
=
copy
.
deepcopy
(
x
)
y
=
copy
.
deepcopy
(
x
)
self
.
assertEqual
(
y
,
x
)
self
.
assertEqual
(
y
,
x
)
self
.
assert
True
(
y
.
foo
is
not
x
.
foo
)
self
.
assert
IsNot
(
y
.
foo
,
x
.
foo
)
def
test_deepcopy_inst_deepcopy
(
self
):
def
test_deepcopy_inst_deepcopy
(
self
):
class
C
:
class
C
:
...
@@ -362,8 +384,8 @@ class TestCopy(unittest.TestCase):
...
@@ -362,8 +384,8 @@ class TestCopy(unittest.TestCase):
x
=
C
([
42
])
x
=
C
([
42
])
y
=
copy
.
deepcopy
(
x
)
y
=
copy
.
deepcopy
(
x
)
self
.
assertEqual
(
y
,
x
)
self
.
assertEqual
(
y
,
x
)
self
.
assert
True
(
y
is
not
x
)
self
.
assert
IsNot
(
y
,
x
)
self
.
assert
True
(
y
.
foo
is
not
x
.
foo
)
self
.
assert
IsNot
(
y
.
foo
,
x
.
foo
)
def
test_deepcopy_inst_getinitargs
(
self
):
def
test_deepcopy_inst_getinitargs
(
self
):
class
C
:
class
C
:
...
@@ -376,8 +398,8 @@ class TestCopy(unittest.TestCase):
...
@@ -376,8 +398,8 @@ class TestCopy(unittest.TestCase):
x
=
C
([
42
])
x
=
C
([
42
])
y
=
copy
.
deepcopy
(
x
)
y
=
copy
.
deepcopy
(
x
)
self
.
assertEqual
(
y
,
x
)
self
.
assertEqual
(
y
,
x
)
self
.
assert
True
(
y
is
not
x
)
self
.
assert
IsNot
(
y
,
x
)
self
.
assert
True
(
y
.
foo
is
not
x
.
foo
)
self
.
assert
IsNot
(
y
.
foo
,
x
.
foo
)
def
test_deepcopy_inst_getstate
(
self
):
def
test_deepcopy_inst_getstate
(
self
):
class
C
:
class
C
:
...
@@ -390,8 +412,8 @@ class TestCopy(unittest.TestCase):
...
@@ -390,8 +412,8 @@ class TestCopy(unittest.TestCase):
x
=
C
([
42
])
x
=
C
([
42
])
y
=
copy
.
deepcopy
(
x
)
y
=
copy
.
deepcopy
(
x
)
self
.
assertEqual
(
y
,
x
)
self
.
assertEqual
(
y
,
x
)
self
.
assert
True
(
y
is
not
x
)
self
.
assert
IsNot
(
y
,
x
)
self
.
assert
True
(
y
.
foo
is
not
x
.
foo
)
self
.
assert
IsNot
(
y
.
foo
,
x
.
foo
)
def
test_deepcopy_inst_setstate
(
self
):
def
test_deepcopy_inst_setstate
(
self
):
class
C
:
class
C
:
...
@@ -404,8 +426,8 @@ class TestCopy(unittest.TestCase):
...
@@ -404,8 +426,8 @@ class TestCopy(unittest.TestCase):
x
=
C
([
42
])
x
=
C
([
42
])
y
=
copy
.
deepcopy
(
x
)
y
=
copy
.
deepcopy
(
x
)
self
.
assertEqual
(
y
,
x
)
self
.
assertEqual
(
y
,
x
)
self
.
assert
True
(
y
is
not
x
)
self
.
assert
IsNot
(
y
,
x
)
self
.
assert
True
(
y
.
foo
is
not
x
.
foo
)
self
.
assert
IsNot
(
y
.
foo
,
x
.
foo
)
def
test_deepcopy_inst_getstate_setstate
(
self
):
def
test_deepcopy_inst_getstate_setstate
(
self
):
class
C
:
class
C
:
...
@@ -420,8 +442,8 @@ class TestCopy(unittest.TestCase):
...
@@ -420,8 +442,8 @@ class TestCopy(unittest.TestCase):
x
=
C
([
42
])
x
=
C
([
42
])
y
=
copy
.
deepcopy
(
x
)
y
=
copy
.
deepcopy
(
x
)
self
.
assertEqual
(
y
,
x
)
self
.
assertEqual
(
y
,
x
)
self
.
assert
True
(
y
is
not
x
)
self
.
assert
IsNot
(
y
,
x
)
self
.
assert
True
(
y
.
foo
is
not
x
.
foo
)
self
.
assert
IsNot
(
y
.
foo
,
x
.
foo
)
def
test_deepcopy_reflexive_inst
(
self
):
def
test_deepcopy_reflexive_inst
(
self
):
class
C
:
class
C
:
...
@@ -429,8 +451,8 @@ class TestCopy(unittest.TestCase):
...
@@ -429,8 +451,8 @@ class TestCopy(unittest.TestCase):
x
=
C
()
x
=
C
()
x
.
foo
=
x
x
.
foo
=
x
y
=
copy
.
deepcopy
(
x
)
y
=
copy
.
deepcopy
(
x
)
self
.
assert
True
(
y
is
not
x
)
self
.
assert
IsNot
(
y
,
x
)
self
.
assert
True
(
y
.
foo
is
y
)
self
.
assert
Is
(
y
.
foo
,
y
)
# _reconstruct()
# _reconstruct()
...
@@ -440,9 +462,9 @@ class TestCopy(unittest.TestCase):
...
@@ -440,9 +462,9 @@ class TestCopy(unittest.TestCase):
return
""
return
""
x
=
C
()
x
=
C
()
y
=
copy
.
copy
(
x
)
y
=
copy
.
copy
(
x
)
self
.
assert
True
(
y
is
x
)
self
.
assert
Is
(
y
,
x
)
y
=
copy
.
deepcopy
(
x
)
y
=
copy
.
deepcopy
(
x
)
self
.
assert
True
(
y
is
x
)
self
.
assert
Is
(
y
,
x
)
def
test_reconstruct_nostate
(
self
):
def
test_reconstruct_nostate
(
self
):
class
C
(
object
):
class
C
(
object
):
...
@@ -451,9 +473,9 @@ class TestCopy(unittest.TestCase):
...
@@ -451,9 +473,9 @@ class TestCopy(unittest.TestCase):
x
=
C
()
x
=
C
()
x
.
foo
=
42
x
.
foo
=
42
y
=
copy
.
copy
(
x
)
y
=
copy
.
copy
(
x
)
self
.
assert
True
(
y
.
__class__
is
x
.
__class__
)
self
.
assert
Is
(
y
.
__class__
,
x
.
__class__
)
y
=
copy
.
deepcopy
(
x
)
y
=
copy
.
deepcopy
(
x
)
self
.
assert
True
(
y
.
__class__
is
x
.
__class__
)
self
.
assert
Is
(
y
.
__class__
,
x
.
__class__
)
def
test_reconstruct_state
(
self
):
def
test_reconstruct_state
(
self
):
class
C
(
object
):
class
C
(
object
):
...
@@ -467,7 +489,7 @@ class TestCopy(unittest.TestCase):
...
@@ -467,7 +489,7 @@ class TestCopy(unittest.TestCase):
self
.
assertEqual
(
y
,
x
)
self
.
assertEqual
(
y
,
x
)
y
=
copy
.
deepcopy
(
x
)
y
=
copy
.
deepcopy
(
x
)
self
.
assertEqual
(
y
,
x
)
self
.
assertEqual
(
y
,
x
)
self
.
assert
True
(
y
.
foo
is
not
x
.
foo
)
self
.
assert
IsNot
(
y
.
foo
,
x
.
foo
)
def
test_reconstruct_state_setstate
(
self
):
def
test_reconstruct_state_setstate
(
self
):
class
C
(
object
):
class
C
(
object
):
...
@@ -483,7 +505,7 @@ class TestCopy(unittest.TestCase):
...
@@ -483,7 +505,7 @@ class TestCopy(unittest.TestCase):
self
.
assertEqual
(
y
,
x
)
self
.
assertEqual
(
y
,
x
)
y
=
copy
.
deepcopy
(
x
)
y
=
copy
.
deepcopy
(
x
)
self
.
assertEqual
(
y
,
x
)
self
.
assertEqual
(
y
,
x
)
self
.
assert
True
(
y
.
foo
is
not
x
.
foo
)
self
.
assert
IsNot
(
y
.
foo
,
x
.
foo
)
def
test_reconstruct_reflexive
(
self
):
def
test_reconstruct_reflexive
(
self
):
class
C
(
object
):
class
C
(
object
):
...
@@ -491,8 +513,8 @@ class TestCopy(unittest.TestCase):
...
@@ -491,8 +513,8 @@ class TestCopy(unittest.TestCase):
x
=
C
()
x
=
C
()
x
.
foo
=
x
x
.
foo
=
x
y
=
copy
.
deepcopy
(
x
)
y
=
copy
.
deepcopy
(
x
)
self
.
assert
True
(
y
is
not
x
)
self
.
assert
IsNot
(
y
,
x
)
self
.
assert
True
(
y
.
foo
is
y
)
self
.
assert
Is
(
y
.
foo
,
y
)
# Additions for Python 2.3 and pickle protocol 2
# Additions for Python 2.3 and pickle protocol 2
...
@@ -506,12 +528,12 @@ class TestCopy(unittest.TestCase):
...
@@ -506,12 +528,12 @@ class TestCopy(unittest.TestCase):
x
=
C
([[
1
,
2
],
3
])
x
=
C
([[
1
,
2
],
3
])
y
=
copy
.
copy
(
x
)
y
=
copy
.
copy
(
x
)
self
.
assertEqual
(
x
,
y
)
self
.
assertEqual
(
x
,
y
)
self
.
assert
True
(
x
is
not
y
)
self
.
assert
IsNot
(
x
,
y
)
self
.
assert
True
(
x
[
0
]
is
y
[
0
])
self
.
assert
Is
(
x
[
0
],
y
[
0
])
y
=
copy
.
deepcopy
(
x
)
y
=
copy
.
deepcopy
(
x
)
self
.
assertEqual
(
x
,
y
)
self
.
assertEqual
(
x
,
y
)
self
.
assert
True
(
x
is
not
y
)
self
.
assert
IsNot
(
x
,
y
)
self
.
assert
True
(
x
[
0
]
is
not
y
[
0
])
self
.
assert
IsNot
(
x
[
0
],
y
[
0
])
def
test_reduce_5tuple
(
self
):
def
test_reduce_5tuple
(
self
):
class
C
(
dict
):
class
C
(
dict
):
...
@@ -523,12 +545,12 @@ class TestCopy(unittest.TestCase):
...
@@ -523,12 +545,12 @@ class TestCopy(unittest.TestCase):
x
=
C
([(
"foo"
,
[
1
,
2
]),
(
"bar"
,
3
)])
x
=
C
([(
"foo"
,
[
1
,
2
]),
(
"bar"
,
3
)])
y
=
copy
.
copy
(
x
)
y
=
copy
.
copy
(
x
)
self
.
assertEqual
(
x
,
y
)
self
.
assertEqual
(
x
,
y
)
self
.
assert
True
(
x
is
not
y
)
self
.
assert
IsNot
(
x
,
y
)
self
.
assert
True
(
x
[
"foo"
]
is
y
[
"foo"
])
self
.
assert
Is
(
x
[
"foo"
],
y
[
"foo"
])
y
=
copy
.
deepcopy
(
x
)
y
=
copy
.
deepcopy
(
x
)
self
.
assertEqual
(
x
,
y
)
self
.
assertEqual
(
x
,
y
)
self
.
assert
True
(
x
is
not
y
)
self
.
assert
IsNot
(
x
,
y
)
self
.
assert
True
(
x
[
"foo"
]
is
not
y
[
"foo"
])
self
.
assert
IsNot
(
x
[
"foo"
],
y
[
"foo"
])
def
test_copy_slots
(
self
):
def
test_copy_slots
(
self
):
class
C
(
object
):
class
C
(
object
):
...
@@ -536,7 +558,7 @@ class TestCopy(unittest.TestCase):
...
@@ -536,7 +558,7 @@ class TestCopy(unittest.TestCase):
x
=
C
()
x
=
C
()
x
.
foo
=
[
42
]
x
.
foo
=
[
42
]
y
=
copy
.
copy
(
x
)
y
=
copy
.
copy
(
x
)
self
.
assert
True
(
x
.
foo
is
y
.
foo
)
self
.
assert
Is
(
x
.
foo
,
y
.
foo
)
def
test_deepcopy_slots
(
self
):
def
test_deepcopy_slots
(
self
):
class
C
(
object
):
class
C
(
object
):
...
@@ -545,7 +567,7 @@ class TestCopy(unittest.TestCase):
...
@@ -545,7 +567,7 @@ class TestCopy(unittest.TestCase):
x
.
foo
=
[
42
]
x
.
foo
=
[
42
]
y
=
copy
.
deepcopy
(
x
)
y
=
copy
.
deepcopy
(
x
)
self
.
assertEqual
(
x
.
foo
,
y
.
foo
)
self
.
assertEqual
(
x
.
foo
,
y
.
foo
)
self
.
assert
True
(
x
.
foo
is
not
y
.
foo
)
self
.
assert
IsNot
(
x
.
foo
,
y
.
foo
)
def
test_deepcopy_dict_subclass
(
self
):
def
test_deepcopy_dict_subclass
(
self
):
class
C
(
dict
):
class
C
(
dict
):
...
@@ -562,7 +584,7 @@ class TestCopy(unittest.TestCase):
...
@@ -562,7 +584,7 @@ class TestCopy(unittest.TestCase):
y
=
copy
.
deepcopy
(
x
)
y
=
copy
.
deepcopy
(
x
)
self
.
assertEqual
(
x
,
y
)
self
.
assertEqual
(
x
,
y
)
self
.
assertEqual
(
x
.
_keys
,
y
.
_keys
)
self
.
assertEqual
(
x
.
_keys
,
y
.
_keys
)
self
.
assert
True
(
x
is
not
y
)
self
.
assert
IsNot
(
x
,
y
)
x
[
'bar'
]
=
1
x
[
'bar'
]
=
1
self
.
assertNotEqual
(
x
,
y
)
self
.
assertNotEqual
(
x
,
y
)
self
.
assertNotEqual
(
x
.
_keys
,
y
.
_keys
)
self
.
assertNotEqual
(
x
.
_keys
,
y
.
_keys
)
...
@@ -575,8 +597,8 @@ class TestCopy(unittest.TestCase):
...
@@ -575,8 +597,8 @@ class TestCopy(unittest.TestCase):
y
=
copy
.
copy
(
x
)
y
=
copy
.
copy
(
x
)
self
.
assertEqual
(
list
(
x
),
list
(
y
))
self
.
assertEqual
(
list
(
x
),
list
(
y
))
self
.
assertEqual
(
x
.
foo
,
y
.
foo
)
self
.
assertEqual
(
x
.
foo
,
y
.
foo
)
self
.
assert
True
(
x
[
0
]
is
y
[
0
])
self
.
assert
Is
(
x
[
0
],
y
[
0
])
self
.
assert
True
(
x
.
foo
is
y
.
foo
)
self
.
assert
Is
(
x
.
foo
,
y
.
foo
)
def
test_deepcopy_list_subclass
(
self
):
def
test_deepcopy_list_subclass
(
self
):
class
C
(
list
):
class
C
(
list
):
...
@@ -586,8 +608,8 @@ class TestCopy(unittest.TestCase):
...
@@ -586,8 +608,8 @@ class TestCopy(unittest.TestCase):
y
=
copy
.
deepcopy
(
x
)
y
=
copy
.
deepcopy
(
x
)
self
.
assertEqual
(
list
(
x
),
list
(
y
))
self
.
assertEqual
(
list
(
x
),
list
(
y
))
self
.
assertEqual
(
x
.
foo
,
y
.
foo
)
self
.
assertEqual
(
x
.
foo
,
y
.
foo
)
self
.
assert
True
(
x
[
0
]
is
not
y
[
0
])
self
.
assert
IsNot
(
x
[
0
],
y
[
0
])
self
.
assert
True
(
x
.
foo
is
not
y
.
foo
)
self
.
assert
IsNot
(
x
.
foo
,
y
.
foo
)
def
test_copy_tuple_subclass
(
self
):
def
test_copy_tuple_subclass
(
self
):
class
C
(
tuple
):
class
C
(
tuple
):
...
@@ -604,8 +626,8 @@ class TestCopy(unittest.TestCase):
...
@@ -604,8 +626,8 @@ class TestCopy(unittest.TestCase):
self
.
assertEqual
(
tuple
(
x
),
([
1
,
2
],
3
))
self
.
assertEqual
(
tuple
(
x
),
([
1
,
2
],
3
))
y
=
copy
.
deepcopy
(
x
)
y
=
copy
.
deepcopy
(
x
)
self
.
assertEqual
(
tuple
(
y
),
([
1
,
2
],
3
))
self
.
assertEqual
(
tuple
(
y
),
([
1
,
2
],
3
))
self
.
assert
True
(
x
is
not
y
)
self
.
assert
IsNot
(
x
,
y
)
self
.
assert
True
(
x
[
0
]
is
not
y
[
0
])
self
.
assert
IsNot
(
x
[
0
],
y
[
0
])
def
test_getstate_exc
(
self
):
def
test_getstate_exc
(
self
):
class
EvilState
(
object
):
class
EvilState
(
object
):
...
@@ -633,10 +655,10 @@ class TestCopy(unittest.TestCase):
...
@@ -633,10 +655,10 @@ class TestCopy(unittest.TestCase):
obj
=
C
()
obj
=
C
()
x
=
weakref
.
ref
(
obj
)
x
=
weakref
.
ref
(
obj
)
y
=
_copy
(
x
)
y
=
_copy
(
x
)
self
.
assert
True
(
y
is
x
)
self
.
assert
Is
(
y
,
x
)
del
obj
del
obj
y
=
_copy
(
x
)
y
=
_copy
(
x
)
self
.
assert
True
(
y
is
x
)
self
.
assert
Is
(
y
,
x
)
def
test_copy_weakref
(
self
):
def
test_copy_weakref
(
self
):
self
.
_check_weakref
(
copy
.
copy
)
self
.
_check_weakref
(
copy
.
copy
)
...
@@ -652,7 +674,7 @@ class TestCopy(unittest.TestCase):
...
@@ -652,7 +674,7 @@ class TestCopy(unittest.TestCase):
u
[
a
]
=
b
u
[
a
]
=
b
u
[
c
]
=
d
u
[
c
]
=
d
v
=
copy
.
copy
(
u
)
v
=
copy
.
copy
(
u
)
self
.
assert
False
(
v
is
u
)
self
.
assert
IsNot
(
v
,
u
)
self
.
assertEqual
(
v
,
u
)
self
.
assertEqual
(
v
,
u
)
self
.
assertEqual
(
v
[
a
],
b
)
self
.
assertEqual
(
v
[
a
],
b
)
self
.
assertEqual
(
v
[
c
],
d
)
self
.
assertEqual
(
v
[
c
],
d
)
...
@@ -682,8 +704,8 @@ class TestCopy(unittest.TestCase):
...
@@ -682,8 +704,8 @@ class TestCopy(unittest.TestCase):
v
=
copy
.
deepcopy
(
u
)
v
=
copy
.
deepcopy
(
u
)
self
.
assertNotEqual
(
v
,
u
)
self
.
assertNotEqual
(
v
,
u
)
self
.
assertEqual
(
len
(
v
),
2
)
self
.
assertEqual
(
len
(
v
),
2
)
self
.
assert
False
(
v
[
a
]
is
b
)
self
.
assert
IsNot
(
v
[
a
],
b
)
self
.
assert
False
(
v
[
c
]
is
d
)
self
.
assert
IsNot
(
v
[
c
],
d
)
self
.
assertEqual
(
v
[
a
]
.
i
,
b
.
i
)
self
.
assertEqual
(
v
[
a
]
.
i
,
b
.
i
)
self
.
assertEqual
(
v
[
c
]
.
i
,
d
.
i
)
self
.
assertEqual
(
v
[
c
]
.
i
,
d
.
i
)
del
c
del
c
...
@@ -702,12 +724,12 @@ class TestCopy(unittest.TestCase):
...
@@ -702,12 +724,12 @@ class TestCopy(unittest.TestCase):
self
.
assertNotEqual
(
v
,
u
)
self
.
assertNotEqual
(
v
,
u
)
self
.
assertEqual
(
len
(
v
),
2
)
self
.
assertEqual
(
len
(
v
),
2
)
(
x
,
y
),
(
z
,
t
)
=
sorted
(
v
.
items
(),
key
=
lambda
pair
:
pair
[
0
]
.
i
)
(
x
,
y
),
(
z
,
t
)
=
sorted
(
v
.
items
(),
key
=
lambda
pair
:
pair
[
0
]
.
i
)
self
.
assert
False
(
x
is
a
)
self
.
assert
IsNot
(
x
,
a
)
self
.
assertEqual
(
x
.
i
,
a
.
i
)
self
.
assertEqual
(
x
.
i
,
a
.
i
)
self
.
assert
True
(
y
is
b
)
self
.
assert
Is
(
y
,
b
)
self
.
assert
False
(
z
is
c
)
self
.
assert
IsNot
(
z
,
c
)
self
.
assertEqual
(
z
.
i
,
c
.
i
)
self
.
assertEqual
(
z
.
i
,
c
.
i
)
self
.
assert
True
(
t
is
d
)
self
.
assert
Is
(
t
,
d
)
del
x
,
y
,
z
,
t
del
x
,
y
,
z
,
t
del
d
del
d
self
.
assertEqual
(
len
(
v
),
1
)
self
.
assertEqual
(
len
(
v
),
1
)
...
@@ -720,7 +742,7 @@ class TestCopy(unittest.TestCase):
...
@@ -720,7 +742,7 @@ class TestCopy(unittest.TestCase):
f
.
b
=
f
.
m
f
.
b
=
f
.
m
g
=
copy
.
deepcopy
(
f
)
g
=
copy
.
deepcopy
(
f
)
self
.
assertEqual
(
g
.
m
,
g
.
b
)
self
.
assertEqual
(
g
.
m
,
g
.
b
)
self
.
assert
True
(
g
.
b
.
__self__
is
g
)
self
.
assert
Is
(
g
.
b
.
__self__
,
g
)
g
.
b
()
g
.
b
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment