summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_bytes.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2022-04-06 17:00:14 (GMT)
committerGitHub <noreply@github.com>2022-04-06 17:00:14 (GMT)
commit884eba3c76916889fd6bff3b37b8552bfb4f9566 (patch)
tree51fd55d6170cdff327ac11d70f1e5ff1aa7e735a /Lib/test/test_bytes.py
parentf82f9ce3239b9a7e6ffa278658dd9858f64a3c14 (diff)
downloadcpython-884eba3c76916889fd6bff3b37b8552bfb4f9566.zip
cpython-884eba3c76916889fd6bff3b37b8552bfb4f9566.tar.gz
cpython-884eba3c76916889fd6bff3b37b8552bfb4f9566.tar.bz2
bpo-26579: Add object.__getstate__(). (GH-2821)
Copying and pickling instances of subclasses of builtin types bytearray, set, frozenset, collections.OrderedDict, collections.deque, weakref.WeakSet, and datetime.tzinfo now copies and pickles instance attributes implemented as slots.
Diffstat (limited to 'Lib/test/test_bytes.py')
-rw-r--r--Lib/test/test_bytes.py20
1 files changed, 14 insertions, 6 deletions
diff --git a/Lib/test/test_bytes.py b/Lib/test/test_bytes.py
index fd8e1d4..b457ff6 100644
--- a/Lib/test/test_bytes.py
+++ b/Lib/test/test_bytes.py
@@ -1940,28 +1940,30 @@ class SubclassTest:
def test_pickle(self):
a = self.type2test(b"abcd")
a.x = 10
- a.y = self.type2test(b"efgh")
+ a.z = self.type2test(b"efgh")
for proto in range(pickle.HIGHEST_PROTOCOL + 1):
b = pickle.loads(pickle.dumps(a, proto))
self.assertNotEqual(id(a), id(b))
self.assertEqual(a, b)
self.assertEqual(a.x, b.x)
- self.assertEqual(a.y, b.y)
+ self.assertEqual(a.z, b.z)
self.assertEqual(type(a), type(b))
- self.assertEqual(type(a.y), type(b.y))
+ self.assertEqual(type(a.z), type(b.z))
+ self.assertFalse(hasattr(b, 'y'))
def test_copy(self):
a = self.type2test(b"abcd")
a.x = 10
- a.y = self.type2test(b"efgh")
+ a.z = self.type2test(b"efgh")
for copy_method in (copy.copy, copy.deepcopy):
b = copy_method(a)
self.assertNotEqual(id(a), id(b))
self.assertEqual(a, b)
self.assertEqual(a.x, b.x)
- self.assertEqual(a.y, b.y)
+ self.assertEqual(a.z, b.z)
self.assertEqual(type(a), type(b))
- self.assertEqual(type(a.y), type(b.y))
+ self.assertEqual(type(a.z), type(b.z))
+ self.assertFalse(hasattr(b, 'y'))
def test_fromhex(self):
b = self.type2test.fromhex('1a2B30')
@@ -1994,6 +1996,9 @@ class SubclassTest:
class ByteArraySubclass(bytearray):
pass
+class ByteArraySubclassWithSlots(bytearray):
+ __slots__ = ('x', 'y', '__dict__')
+
class BytesSubclass(bytes):
pass
@@ -2014,6 +2019,9 @@ class ByteArraySubclassTest(SubclassTest, unittest.TestCase):
x = subclass(newarg=4, source=b"abcd")
self.assertEqual(x, b"abcd")
+class ByteArraySubclassWithSlotsTest(SubclassTest, unittest.TestCase):
+ basetype = bytearray
+ type2test = ByteArraySubclassWithSlots
class BytesSubclassTest(SubclassTest, unittest.TestCase):
basetype = bytes