From b7e043e4428c39a4c7acdfd0abc730897f1870e0 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Sun, 28 Jul 2024 10:02:09 +0300 Subject: [PATCH] gh-122311: Add more details in tests for pickle --- Lib/test/pickletester.py | 241 ++++++++++++++++++++++++++++++--------- 1 file changed, 190 insertions(+), 51 deletions(-) diff --git a/Lib/test/pickletester.py b/Lib/test/pickletester.py index 174f4ff6d021b2..b702758e53bf3d 100644 --- a/Lib/test/pickletester.py +++ b/Lib/test/pickletester.py @@ -1229,24 +1229,40 @@ def test_find_class(self): self.assertIs(unpickler.find_class('os.path', 'join'), os.path.join) self.assertIs(unpickler4.find_class('builtins', 'str.upper'), str.upper) - with self.assertRaises(AttributeError): + with self.assertRaisesRegex(AttributeError, + "module 'builtins' has no attribute 'str.upper'|" + "Can't get attribute 'str.upper' on .spam'|" + "Can't get attribute 'log..spam' on .spam') - with self.assertRaises(AttributeError): + with self.assertRaisesRegex(AttributeError, + "Can't get local attribute 'log..spam' on .spam' on .spam') - with self.assertRaises(AttributeError): + with self.assertRaisesRegex(AttributeError, + "module 'math' has no attribute ''|" + "Can't get attribute '' on = 5') def test_non_continuous_buffer(self): if self.pickler is pickle._Pickler: @@ -4541,8 +4677,11 @@ class MyClass: # NotImplemented self.assertIs(math_log, math.log) - with self.assertRaises(pickle.PicklingError): + with self.assertRaises(pickle.PicklingError) as cm: p.dump(g) + self.assertRegex(str(cm.exception), + r'(__reduce__|)' + r' must return (a )?string or tuple') with self.assertRaisesRegex( ValueError, 'The reducer just failed'):