diff options
| author | Serhiy Storchaka <storchaka@gmail.com> | 2015-09-29 12:36:28 (GMT) |
|---|---|---|
| committer | Serhiy Storchaka <storchaka@gmail.com> | 2015-09-29 12:36:28 (GMT) |
| commit | 4d2cf5587cd02e9642b0abea8450ab1ee5e5fde8 (patch) | |
| tree | 83fd8c036369bb54c68d17b3183084c30d04dd61 /Lib/test/pickletester.py | |
| parent | 958a9c752022fd89173563f5e9678ca4d74ece00 (diff) | |
| download | cpython-4d2cf5587cd02e9642b0abea8450ab1ee5e5fde8.zip cpython-4d2cf5587cd02e9642b0abea8450ab1ee5e5fde8.tar.gz cpython-4d2cf5587cd02e9642b0abea8450ab1ee5e5fde8.tar.bz2 | |
Moved unpickling tests with prepickled data to separate class.
Diffstat (limited to 'Lib/test/pickletester.py')
| -rw-r--r-- | Lib/test/pickletester.py | 83 |
1 files changed, 45 insertions, 38 deletions
diff --git a/Lib/test/pickletester.py b/Lib/test/pickletester.py index 1599893..7c1f403 100644 --- a/Lib/test/pickletester.py +++ b/Lib/test/pickletester.py @@ -420,11 +420,54 @@ def create_data(): x.append(5) return x -class AbstractPickleTests(unittest.TestCase): - # Subclass must define self.dumps, self.loads, self.error. + +class AbstractUnpickleTests(unittest.TestCase): + # Subclass must define self.loads, self.error. _testdata = create_data() + def test_load_from_canned_string(self): + expected = self._testdata + for canned in DATA0, DATA1, DATA2: + got = self.loads(canned) + self.assertEqual(expected, got) + + def test_garyp(self): + self.assertRaises(self.error, self.loads, 'garyp') + + def test_maxint64(self): + maxint64 = (1L << 63) - 1 + data = 'I' + str(maxint64) + '\n.' + got = self.loads(data) + self.assertEqual(got, maxint64) + + # Try too with a bogus literal. + data = 'I' + str(maxint64) + 'JUNK\n.' + self.assertRaises(ValueError, self.loads, data) + + def test_insecure_strings(self): + insecure = ["abc", "2 + 2", # not quoted + #"'abc' + 'def'", # not a single quoted string + "'abc", # quote is not closed + "'abc\"", # open quote and close quote don't match + "'abc' ?", # junk after close quote + "'\\'", # trailing backslash + "'", # issue #17710 + "' ", # issue #17710 + # some tests of the quoting rules + #"'abc\"\''", + #"'\\\\a\'\'\'\\\'\\\\\''", + ] + for s in insecure: + buf = "S" + s + "\012p0\012." + self.assertRaises(ValueError, self.loads, buf) + + +class AbstractPickleTests(unittest.TestCase): + # Subclass must define self.dumps, self.loads. + + _testdata = AbstractUnpickleTests._testdata + def setUp(self): pass @@ -455,12 +498,6 @@ class AbstractPickleTests(unittest.TestCase): got = self.loads(s) self.assertEqual(expected, got) - def test_load_from_canned_string(self): - expected = self._testdata - for canned in DATA0, DATA1, DATA2: - got = self.loads(canned) - self.assertEqual(expected, got) - # There are gratuitous differences between pickles produced by # pickle and cPickle, largely because cPickle starts PUT indices at # 1 and pickle starts them at 0. See XXX comment in cPickle's put2() -- @@ -528,26 +565,6 @@ class AbstractPickleTests(unittest.TestCase): self.assertEqual(x[0].attr.keys(), [1]) self.assertTrue(x[0].attr[1] is x) - def test_garyp(self): - self.assertRaises(self.error, self.loads, 'garyp') - - def test_insecure_strings(self): - insecure = ["abc", "2 + 2", # not quoted - #"'abc' + 'def'", # not a single quoted string - "'abc", # quote is not closed - "'abc\"", # open quote and close quote don't match - "'abc' ?", # junk after close quote - "'\\'", # trailing backslash - "'", # issue #17710 - "' ", # issue #17710 - # some tests of the quoting rules - #"'abc\"\''", - #"'\\\\a\'\'\'\\\'\\\\\''", - ] - for s in insecure: - buf = "S" + s + "\012p0\012." - self.assertRaises(ValueError, self.loads, buf) - if have_unicode: def test_unicode(self): endcases = [u'', u'<\\u>', u'<\\\u1234>', u'<\n>', @@ -576,16 +593,6 @@ class AbstractPickleTests(unittest.TestCase): self.assertEqual(expected, n2) n = n >> 1 - def test_maxint64(self): - maxint64 = (1L << 63) - 1 - data = 'I' + str(maxint64) + '\n.' - got = self.loads(data) - self.assertEqual(got, maxint64) - - # Try too with a bogus literal. - data = 'I' + str(maxint64) + 'JUNK\n.' - self.assertRaises(ValueError, self.loads, data) - def test_long(self): for proto in protocols: # 256 bytes is where LONG4 begins. |
