summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2021-10-24 13:29:37 (GMT)
committerGitHub <noreply@github.com>2021-10-24 13:29:37 (GMT)
commit36971fd1f490664fb62b1fab869c5637669f0967 (patch)
tree19eac95ff03ce32d4ae38b3ea446994bf708b388
parentcadf06eab75c887dfc753ca80ef35cd2a7871135 (diff)
downloadcpython-36971fd1f490664fb62b1fab869c5637669f0967.zip
cpython-36971fd1f490664fb62b1fab869c5637669f0967.tar.gz
cpython-36971fd1f490664fb62b1fab869c5637669f0967.tar.bz2
bpo-45566: `test_frozen_pickle` checks all `pickle` protocols (GH-29150)
Refs https://github.com/python/cpython/pull/29147 Automerge-Triggered-By: GH:ericvsmith (cherry picked from commit 07236d562e59c6650227be18fa6ffc66b18d4741) Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
-rw-r--r--Lib/test/test_dataclasses.py21
-rw-r--r--Misc/NEWS.d/next/Tests/2021-10-22-12-05-21.bpo-45566.2gQ3ZB.rst1
2 files changed, 18 insertions, 4 deletions
diff --git a/Lib/test/test_dataclasses.py b/Lib/test/test_dataclasses.py
index bdcb4a2..bbbb8e6 100644
--- a/Lib/test/test_dataclasses.py
+++ b/Lib/test/test_dataclasses.py
@@ -2859,13 +2859,26 @@ class TestSlots(unittest.TestCase):
foo: str
bar: int
+ @dataclass(frozen=True)
+ class FrozenWithoutSlotsClass:
+ foo: str
+ bar: int
+
def test_frozen_pickle(self):
# bpo-43999
- assert self.FrozenSlotsClass.__slots__ == ("foo", "bar")
- p = pickle.dumps(self.FrozenSlotsClass("a", 1))
- assert pickle.loads(p) == self.FrozenSlotsClass("a", 1)
-
+ self.assertEqual(self.FrozenSlotsClass.__slots__, ("foo", "bar"))
+ for proto in range(pickle.HIGHEST_PROTOCOL + 1):
+ with self.subTest(proto=proto):
+ obj = self.FrozenSlotsClass("a", 1)
+ p = pickle.loads(pickle.dumps(obj, protocol=proto))
+ self.assertIsNot(obj, p)
+ self.assertEqual(obj, p)
+
+ obj = self.FrozenWithoutSlotsClass("a", 1)
+ p = pickle.loads(pickle.dumps(obj, protocol=proto))
+ self.assertIsNot(obj, p)
+ self.assertEqual(obj, p)
class TestDescriptors(unittest.TestCase):
def test_set_name(self):
diff --git a/Misc/NEWS.d/next/Tests/2021-10-22-12-05-21.bpo-45566.2gQ3ZB.rst b/Misc/NEWS.d/next/Tests/2021-10-22-12-05-21.bpo-45566.2gQ3ZB.rst
new file mode 100644
index 0000000..a2ecf72
--- /dev/null
+++ b/Misc/NEWS.d/next/Tests/2021-10-22-12-05-21.bpo-45566.2gQ3ZB.rst
@@ -0,0 +1 @@
+Fix ``test_frozen_pickle`` in ``test_dataclasses`` to check all ``pickle`` versions.