diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2014-12-15 12:03:42 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2014-12-15 12:03:42 (GMT) |
commit | bad1257c96943dcb39584a41e1a178542479df97 (patch) | |
tree | dbb4594291c7df3660da701eb062bec35446bcba /Lib/test/test_configparser.py | |
parent | 79b81738ef052e9406adb8e98f0d292928053c01 (diff) | |
download | cpython-bad1257c96943dcb39584a41e1a178542479df97.zip cpython-bad1257c96943dcb39584a41e1a178542479df97.tar.gz cpython-bad1257c96943dcb39584a41e1a178542479df97.tar.bz2 |
Issue #22777: Test pickling with all protocols.
Diffstat (limited to 'Lib/test/test_configparser.py')
-rw-r--r-- | Lib/test/test_configparser.py | 182 |
1 files changed, 97 insertions, 85 deletions
diff --git a/Lib/test/test_configparser.py b/Lib/test/test_configparser.py index 78bd315..09c229a 100644 --- a/Lib/test/test_configparser.py +++ b/Lib/test/test_configparser.py @@ -1591,104 +1591,113 @@ class ExceptionPicklingTestCase(unittest.TestCase): def test_error(self): import pickle e1 = configparser.Error('value') - pickled = pickle.dumps(e1) - e2 = pickle.loads(pickled) - self.assertEqual(e1.message, e2.message) - self.assertEqual(repr(e1), repr(e2)) + for proto in range(pickle.HIGHEST_PROTOCOL + 1): + pickled = pickle.dumps(e1, proto) + e2 = pickle.loads(pickled) + self.assertEqual(e1.message, e2.message) + self.assertEqual(repr(e1), repr(e2)) def test_nosectionerror(self): import pickle e1 = configparser.NoSectionError('section') - pickled = pickle.dumps(e1) - e2 = pickle.loads(pickled) - self.assertEqual(e1.message, e2.message) - self.assertEqual(e1.args, e2.args) - self.assertEqual(e1.section, e2.section) - self.assertEqual(repr(e1), repr(e2)) + for proto in range(pickle.HIGHEST_PROTOCOL + 1): + pickled = pickle.dumps(e1, proto) + e2 = pickle.loads(pickled) + self.assertEqual(e1.message, e2.message) + self.assertEqual(e1.args, e2.args) + self.assertEqual(e1.section, e2.section) + self.assertEqual(repr(e1), repr(e2)) def test_nooptionerror(self): import pickle e1 = configparser.NoOptionError('option', 'section') - pickled = pickle.dumps(e1) - e2 = pickle.loads(pickled) - self.assertEqual(e1.message, e2.message) - self.assertEqual(e1.args, e2.args) - self.assertEqual(e1.section, e2.section) - self.assertEqual(e1.option, e2.option) - self.assertEqual(repr(e1), repr(e2)) + for proto in range(pickle.HIGHEST_PROTOCOL + 1): + pickled = pickle.dumps(e1, proto) + e2 = pickle.loads(pickled) + self.assertEqual(e1.message, e2.message) + self.assertEqual(e1.args, e2.args) + self.assertEqual(e1.section, e2.section) + self.assertEqual(e1.option, e2.option) + self.assertEqual(repr(e1), repr(e2)) def test_duplicatesectionerror(self): import pickle e1 = configparser.DuplicateSectionError('section', 'source', 123) - pickled = pickle.dumps(e1) - e2 = pickle.loads(pickled) - self.assertEqual(e1.message, e2.message) - self.assertEqual(e1.args, e2.args) - self.assertEqual(e1.section, e2.section) - self.assertEqual(e1.source, e2.source) - self.assertEqual(e1.lineno, e2.lineno) - self.assertEqual(repr(e1), repr(e2)) + for proto in range(pickle.HIGHEST_PROTOCOL + 1): + pickled = pickle.dumps(e1, proto) + e2 = pickle.loads(pickled) + self.assertEqual(e1.message, e2.message) + self.assertEqual(e1.args, e2.args) + self.assertEqual(e1.section, e2.section) + self.assertEqual(e1.source, e2.source) + self.assertEqual(e1.lineno, e2.lineno) + self.assertEqual(repr(e1), repr(e2)) def test_duplicateoptionerror(self): import pickle e1 = configparser.DuplicateOptionError('section', 'option', 'source', 123) - pickled = pickle.dumps(e1) - e2 = pickle.loads(pickled) - self.assertEqual(e1.message, e2.message) - self.assertEqual(e1.args, e2.args) - self.assertEqual(e1.section, e2.section) - self.assertEqual(e1.option, e2.option) - self.assertEqual(e1.source, e2.source) - self.assertEqual(e1.lineno, e2.lineno) - self.assertEqual(repr(e1), repr(e2)) + for proto in range(pickle.HIGHEST_PROTOCOL + 1): + pickled = pickle.dumps(e1, proto) + e2 = pickle.loads(pickled) + self.assertEqual(e1.message, e2.message) + self.assertEqual(e1.args, e2.args) + self.assertEqual(e1.section, e2.section) + self.assertEqual(e1.option, e2.option) + self.assertEqual(e1.source, e2.source) + self.assertEqual(e1.lineno, e2.lineno) + self.assertEqual(repr(e1), repr(e2)) def test_interpolationerror(self): import pickle e1 = configparser.InterpolationError('option', 'section', 'msg') - pickled = pickle.dumps(e1) - e2 = pickle.loads(pickled) - self.assertEqual(e1.message, e2.message) - self.assertEqual(e1.args, e2.args) - self.assertEqual(e1.section, e2.section) - self.assertEqual(e1.option, e2.option) - self.assertEqual(repr(e1), repr(e2)) + for proto in range(pickle.HIGHEST_PROTOCOL + 1): + pickled = pickle.dumps(e1, proto) + e2 = pickle.loads(pickled) + self.assertEqual(e1.message, e2.message) + self.assertEqual(e1.args, e2.args) + self.assertEqual(e1.section, e2.section) + self.assertEqual(e1.option, e2.option) + self.assertEqual(repr(e1), repr(e2)) def test_interpolationmissingoptionerror(self): import pickle e1 = configparser.InterpolationMissingOptionError('option', 'section', 'rawval', 'reference') - pickled = pickle.dumps(e1) - e2 = pickle.loads(pickled) - self.assertEqual(e1.message, e2.message) - self.assertEqual(e1.args, e2.args) - self.assertEqual(e1.section, e2.section) - self.assertEqual(e1.option, e2.option) - self.assertEqual(e1.reference, e2.reference) - self.assertEqual(repr(e1), repr(e2)) + for proto in range(pickle.HIGHEST_PROTOCOL + 1): + pickled = pickle.dumps(e1, proto) + e2 = pickle.loads(pickled) + self.assertEqual(e1.message, e2.message) + self.assertEqual(e1.args, e2.args) + self.assertEqual(e1.section, e2.section) + self.assertEqual(e1.option, e2.option) + self.assertEqual(e1.reference, e2.reference) + self.assertEqual(repr(e1), repr(e2)) def test_interpolationsyntaxerror(self): import pickle e1 = configparser.InterpolationSyntaxError('option', 'section', 'msg') - pickled = pickle.dumps(e1) - e2 = pickle.loads(pickled) - self.assertEqual(e1.message, e2.message) - self.assertEqual(e1.args, e2.args) - self.assertEqual(e1.section, e2.section) - self.assertEqual(e1.option, e2.option) - self.assertEqual(repr(e1), repr(e2)) + for proto in range(pickle.HIGHEST_PROTOCOL + 1): + pickled = pickle.dumps(e1, proto) + e2 = pickle.loads(pickled) + self.assertEqual(e1.message, e2.message) + self.assertEqual(e1.args, e2.args) + self.assertEqual(e1.section, e2.section) + self.assertEqual(e1.option, e2.option) + self.assertEqual(repr(e1), repr(e2)) def test_interpolationdeptherror(self): import pickle e1 = configparser.InterpolationDepthError('option', 'section', 'rawval') - pickled = pickle.dumps(e1) - e2 = pickle.loads(pickled) - self.assertEqual(e1.message, e2.message) - self.assertEqual(e1.args, e2.args) - self.assertEqual(e1.section, e2.section) - self.assertEqual(e1.option, e2.option) - self.assertEqual(repr(e1), repr(e2)) + for proto in range(pickle.HIGHEST_PROTOCOL + 1): + pickled = pickle.dumps(e1, proto) + e2 = pickle.loads(pickled) + self.assertEqual(e1.message, e2.message) + self.assertEqual(e1.args, e2.args) + self.assertEqual(e1.section, e2.section) + self.assertEqual(e1.option, e2.option) + self.assertEqual(repr(e1), repr(e2)) def test_parsingerror(self): import pickle @@ -1696,36 +1705,39 @@ class ExceptionPicklingTestCase(unittest.TestCase): e1.append(1, 'line1') e1.append(2, 'line2') e1.append(3, 'line3') - pickled = pickle.dumps(e1) - e2 = pickle.loads(pickled) - self.assertEqual(e1.message, e2.message) - self.assertEqual(e1.args, e2.args) - self.assertEqual(e1.source, e2.source) - self.assertEqual(e1.errors, e2.errors) - self.assertEqual(repr(e1), repr(e2)) + for proto in range(pickle.HIGHEST_PROTOCOL + 1): + pickled = pickle.dumps(e1, proto) + e2 = pickle.loads(pickled) + self.assertEqual(e1.message, e2.message) + self.assertEqual(e1.args, e2.args) + self.assertEqual(e1.source, e2.source) + self.assertEqual(e1.errors, e2.errors) + self.assertEqual(repr(e1), repr(e2)) e1 = configparser.ParsingError(filename='filename') e1.append(1, 'line1') e1.append(2, 'line2') e1.append(3, 'line3') - pickled = pickle.dumps(e1) - e2 = pickle.loads(pickled) - self.assertEqual(e1.message, e2.message) - self.assertEqual(e1.args, e2.args) - self.assertEqual(e1.source, e2.source) - self.assertEqual(e1.errors, e2.errors) - self.assertEqual(repr(e1), repr(e2)) + for proto in range(pickle.HIGHEST_PROTOCOL + 1): + pickled = pickle.dumps(e1, proto) + e2 = pickle.loads(pickled) + self.assertEqual(e1.message, e2.message) + self.assertEqual(e1.args, e2.args) + self.assertEqual(e1.source, e2.source) + self.assertEqual(e1.errors, e2.errors) + self.assertEqual(repr(e1), repr(e2)) def test_missingsectionheadererror(self): import pickle e1 = configparser.MissingSectionHeaderError('filename', 123, 'line') - pickled = pickle.dumps(e1) - e2 = pickle.loads(pickled) - self.assertEqual(e1.message, e2.message) - self.assertEqual(e1.args, e2.args) - self.assertEqual(e1.line, e2.line) - self.assertEqual(e1.source, e2.source) - self.assertEqual(e1.lineno, e2.lineno) - self.assertEqual(repr(e1), repr(e2)) + for proto in range(pickle.HIGHEST_PROTOCOL + 1): + pickled = pickle.dumps(e1, proto) + e2 = pickle.loads(pickled) + self.assertEqual(e1.message, e2.message) + self.assertEqual(e1.args, e2.args) + self.assertEqual(e1.line, e2.line) + self.assertEqual(e1.source, e2.source) + self.assertEqual(e1.lineno, e2.lineno) + self.assertEqual(repr(e1), repr(e2)) class InlineCommentStrippingTestCase(unittest.TestCase): |