summaryrefslogtreecommitdiff
path: root/Lib/test/test_copy.py
diff options
context:
space:
mode:
authorZachary Ware <zachary.ware@gmail.com>2015-04-13 16:44:05 -0500
committerZachary Ware <zachary.ware@gmail.com>2015-04-13 16:44:05 -0500
commit8cc6d42d475c53396afaf972f03bee07ee4739bd (patch)
treeff70de39fc13210d28c609aa90ff93d35a9db359 /Lib/test/test_copy.py
parent187d9878e860b66d78bfd4c8d538130c72cc724a (diff)
parent81833b5e59153c758f894c851ad1ec4e7942c4b5 (diff)
downloadcpython-8cc6d42d475c53396afaf972f03bee07ee4739bd.tar.gz
Closes #23730: merge with 3.4
Diffstat (limited to 'Lib/test/test_copy.py')
-rw-r--r--Lib/test/test_copy.py76
1 files changed, 71 insertions, 5 deletions
diff --git a/Lib/test/test_copy.py b/Lib/test/test_copy.py
index eb8d18cf0b..4c197467e9 100644
--- a/Lib/test/test_copy.py
+++ b/Lib/test/test_copy.py
@@ -7,7 +7,6 @@ import abc
from operator import le, lt, ge, gt, eq, ne
import unittest
-from test import support
order_comparisons = le, lt, ge, gt
equality_comparisons = eq, ne
@@ -146,6 +145,40 @@ class TestCopy(unittest.TestCase):
x = C(42)
self.assertEqual(copy.copy(x), x)
+ def test_copy_inst_getnewargs(self):
+ class C(int):
+ def __new__(cls, foo):
+ self = int.__new__(cls)
+ self.foo = foo
+ return self
+ def __getnewargs__(self):
+ return self.foo,
+ def __eq__(self, other):
+ return self.foo == other.foo
+ x = C(42)
+ y = copy.copy(x)
+ self.assertIsInstance(y, C)
+ self.assertEqual(y, x)
+ self.assertIsNot(y, x)
+ self.assertEqual(y.foo, x.foo)
+
+ def test_copy_inst_getnewargs_ex(self):
+ class C(int):
+ def __new__(cls, *, foo):
+ self = int.__new__(cls)
+ self.foo = foo
+ return self
+ def __getnewargs_ex__(self):
+ return (), {'foo': self.foo}
+ def __eq__(self, other):
+ return self.foo == other.foo
+ x = C(foo=42)
+ y = copy.copy(x)
+ self.assertIsInstance(y, C)
+ self.assertEqual(y, x)
+ self.assertIsNot(y, x)
+ self.assertEqual(y.foo, x.foo)
+
def test_copy_inst_getstate(self):
class C:
def __init__(self, foo):
@@ -405,6 +438,42 @@ class TestCopy(unittest.TestCase):
self.assertIsNot(y, x)
self.assertIsNot(y.foo, x.foo)
+ def test_deepcopy_inst_getnewargs(self):
+ class C(int):
+ def __new__(cls, foo):
+ self = int.__new__(cls)
+ self.foo = foo
+ return self
+ def __getnewargs__(self):
+ return self.foo,
+ def __eq__(self, other):
+ return self.foo == other.foo
+ x = C([42])
+ y = copy.deepcopy(x)
+ self.assertIsInstance(y, C)
+ self.assertEqual(y, x)
+ self.assertIsNot(y, x)
+ self.assertEqual(y.foo, x.foo)
+ self.assertIsNot(y.foo, x.foo)
+
+ def test_deepcopy_inst_getnewargs_ex(self):
+ class C(int):
+ def __new__(cls, *, foo):
+ self = int.__new__(cls)
+ self.foo = foo
+ return self
+ def __getnewargs_ex__(self):
+ return (), {'foo': self.foo}
+ def __eq__(self, other):
+ return self.foo == other.foo
+ x = C(foo=[42])
+ y = copy.deepcopy(x)
+ self.assertIsInstance(y, C)
+ self.assertEqual(y, x)
+ self.assertIsNot(y, x)
+ self.assertEqual(y.foo, x.foo)
+ self.assertIsNot(y.foo, x.foo)
+
def test_deepcopy_inst_getstate(self):
class C:
def __init__(self, foo):
@@ -752,8 +821,5 @@ class TestCopy(unittest.TestCase):
def global_foo(x, y): return x+y
-def test_main():
- support.run_unittest(TestCopy)
-
if __name__ == "__main__":
- test_main()
+ unittest.main()