2014-12-16 12:00:56 -04:00
|
|
|
import struct
|
Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617,60619-60621,60623-60625,60627-60629,60631,60633,60635,60647,60650,60652,60654,60656,60658-60659,60664-60666,60668-60670,60672,60676,60678,60680-60683,60685-60686,60688,60690,60692-60694,60697-60700,60705-60706,60708,60711,60714,60720,60724-60734 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r60731 | raymond.hettinger | 2008-02-11 19:51:08 +0100 (Mon, 11 Feb 2008) | 1 line
No need to register classes that already inherit from ABCs.
........
r60733 | lars.gustaebel | 2008-02-11 20:17:10 +0100 (Mon, 11 Feb 2008) | 2 lines
Make sure that xstar headers are read correctly.
........
r60734 | raymond.hettinger | 2008-02-11 21:05:53 +0100 (Mon, 11 Feb 2008) | 1 line
Add tests for pickletools.optimize().
........
2008-02-11 18:57:17 -04:00
|
|
|
import pickle
|
2003-01-27 14:51:48 -04:00
|
|
|
import pickletools
|
2008-05-20 18:35:26 -03:00
|
|
|
from test import support
|
Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617,60619-60621,60623-60625,60627-60629,60631,60633,60635,60647,60650,60652,60654,60656,60658-60659,60664-60666,60668-60670,60672,60676,60678,60680-60683,60685-60686,60688,60690,60692-60694,60697-60700,60705-60706,60708,60711,60714,60720,60724-60734 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r60731 | raymond.hettinger | 2008-02-11 19:51:08 +0100 (Mon, 11 Feb 2008) | 1 line
No need to register classes that already inherit from ABCs.
........
r60733 | lars.gustaebel | 2008-02-11 20:17:10 +0100 (Mon, 11 Feb 2008) | 2 lines
Make sure that xstar headers are read correctly.
........
r60734 | raymond.hettinger | 2008-02-11 21:05:53 +0100 (Mon, 11 Feb 2008) | 1 line
Add tests for pickletools.optimize().
........
2008-02-11 18:57:17 -04:00
|
|
|
from test.pickletester import AbstractPickleTests
|
|
|
|
from test.pickletester import AbstractPickleModuleTests
|
|
|
|
|
|
|
|
class OptimizedPickleTests(AbstractPickleTests, AbstractPickleModuleTests):
|
|
|
|
|
2008-03-17 19:56:06 -03:00
|
|
|
def dumps(self, arg, proto=None):
|
Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617,60619-60621,60623-60625,60627-60629,60631,60633,60635,60647,60650,60652,60654,60656,60658-60659,60664-60666,60668-60670,60672,60676,60678,60680-60683,60685-60686,60688,60690,60692-60694,60697-60700,60705-60706,60708,60711,60714,60720,60724-60734 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r60731 | raymond.hettinger | 2008-02-11 19:51:08 +0100 (Mon, 11 Feb 2008) | 1 line
No need to register classes that already inherit from ABCs.
........
r60733 | lars.gustaebel | 2008-02-11 20:17:10 +0100 (Mon, 11 Feb 2008) | 2 lines
Make sure that xstar headers are read correctly.
........
r60734 | raymond.hettinger | 2008-02-11 21:05:53 +0100 (Mon, 11 Feb 2008) | 1 line
Add tests for pickletools.optimize().
........
2008-02-11 18:57:17 -04:00
|
|
|
return pickletools.optimize(pickle.dumps(arg, proto))
|
|
|
|
|
2011-02-24 15:40:09 -04:00
|
|
|
def loads(self, buf, **kwds):
|
|
|
|
return pickle.loads(buf, **kwds)
|
Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617,60619-60621,60623-60625,60627-60629,60631,60633,60635,60647,60650,60652,60654,60656,60658-60659,60664-60666,60668-60670,60672,60676,60678,60680-60683,60685-60686,60688,60690,60692-60694,60697-60700,60705-60706,60708,60711,60714,60720,60724-60734 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r60731 | raymond.hettinger | 2008-02-11 19:51:08 +0100 (Mon, 11 Feb 2008) | 1 line
No need to register classes that already inherit from ABCs.
........
r60733 | lars.gustaebel | 2008-02-11 20:17:10 +0100 (Mon, 11 Feb 2008) | 2 lines
Make sure that xstar headers are read correctly.
........
r60734 | raymond.hettinger | 2008-02-11 21:05:53 +0100 (Mon, 11 Feb 2008) | 1 line
Add tests for pickletools.optimize().
........
2008-02-11 18:57:17 -04:00
|
|
|
|
2009-06-04 17:32:06 -03:00
|
|
|
# Test relies on precise output of dumps()
|
|
|
|
test_pickle_to_2x = None
|
|
|
|
|
2014-12-16 12:00:56 -04:00
|
|
|
def test_optimize_long_binget(self):
|
|
|
|
data = [str(i) for i in range(257)]
|
|
|
|
data.append(data[-1])
|
|
|
|
for proto in range(pickle.HIGHEST_PROTOCOL + 1):
|
|
|
|
pickled = pickle.dumps(data, proto)
|
|
|
|
unpickled = pickle.loads(pickled)
|
|
|
|
self.assertEqual(unpickled, data)
|
|
|
|
self.assertIs(unpickled[-1], unpickled[-2])
|
|
|
|
|
|
|
|
pickled2 = pickletools.optimize(pickled)
|
|
|
|
unpickled2 = pickle.loads(pickled2)
|
|
|
|
self.assertEqual(unpickled2, data)
|
|
|
|
self.assertIs(unpickled2[-1], unpickled2[-2])
|
|
|
|
self.assertNotIn(pickle.LONG_BINGET, pickled2)
|
|
|
|
self.assertNotIn(pickle.LONG_BINPUT, pickled2)
|
|
|
|
|
|
|
|
def test_optimize_binput_and_memoize(self):
|
|
|
|
pickled = (b'\x80\x04\x95\x15\x00\x00\x00\x00\x00\x00\x00'
|
|
|
|
b']\x94(\x8c\x04spamq\x01\x8c\x03ham\x94h\x02e.')
|
|
|
|
# 0: \x80 PROTO 4
|
|
|
|
# 2: \x95 FRAME 21
|
|
|
|
# 11: ] EMPTY_LIST
|
|
|
|
# 12: \x94 MEMOIZE
|
|
|
|
# 13: ( MARK
|
|
|
|
# 14: \x8c SHORT_BINUNICODE 'spam'
|
|
|
|
# 20: q BINPUT 1
|
|
|
|
# 22: \x8c SHORT_BINUNICODE 'ham'
|
|
|
|
# 27: \x94 MEMOIZE
|
|
|
|
# 28: h BINGET 2
|
|
|
|
# 30: e APPENDS (MARK at 13)
|
|
|
|
# 31: . STOP
|
|
|
|
self.assertIn(pickle.BINPUT, pickled)
|
|
|
|
unpickled = pickle.loads(pickled)
|
|
|
|
self.assertEqual(unpickled, ['spam', 'ham', 'ham'])
|
|
|
|
self.assertIs(unpickled[1], unpickled[2])
|
|
|
|
|
|
|
|
pickled2 = pickletools.optimize(pickled)
|
|
|
|
unpickled2 = pickle.loads(pickled2)
|
|
|
|
self.assertEqual(unpickled2, ['spam', 'ham', 'ham'])
|
|
|
|
self.assertIs(unpickled2[1], unpickled2[2])
|
|
|
|
self.assertNotIn(pickle.BINPUT, pickled2)
|
|
|
|
|
Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617,60619-60621,60623-60625,60627-60629,60631,60633,60635,60647,60650,60652,60654,60656,60658-60659,60664-60666,60668-60670,60672,60676,60678,60680-60683,60685-60686,60688,60690,60692-60694,60697-60700,60705-60706,60708,60711,60714,60720,60724-60734 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r60731 | raymond.hettinger | 2008-02-11 19:51:08 +0100 (Mon, 11 Feb 2008) | 1 line
No need to register classes that already inherit from ABCs.
........
r60733 | lars.gustaebel | 2008-02-11 20:17:10 +0100 (Mon, 11 Feb 2008) | 2 lines
Make sure that xstar headers are read correctly.
........
r60734 | raymond.hettinger | 2008-02-11 21:05:53 +0100 (Mon, 11 Feb 2008) | 1 line
Add tests for pickletools.optimize().
........
2008-02-11 18:57:17 -04:00
|
|
|
|
|
|
|
def test_main():
|
2008-05-20 18:35:26 -03:00
|
|
|
support.run_unittest(OptimizedPickleTests)
|
|
|
|
support.run_doctest(pickletools)
|
Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617,60619-60621,60623-60625,60627-60629,60631,60633,60635,60647,60650,60652,60654,60656,60658-60659,60664-60666,60668-60670,60672,60676,60678,60680-60683,60685-60686,60688,60690,60692-60694,60697-60700,60705-60706,60708,60711,60714,60720,60724-60734 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r60731 | raymond.hettinger | 2008-02-11 19:51:08 +0100 (Mon, 11 Feb 2008) | 1 line
No need to register classes that already inherit from ABCs.
........
r60733 | lars.gustaebel | 2008-02-11 20:17:10 +0100 (Mon, 11 Feb 2008) | 2 lines
Make sure that xstar headers are read correctly.
........
r60734 | raymond.hettinger | 2008-02-11 21:05:53 +0100 (Mon, 11 Feb 2008) | 1 line
Add tests for pickletools.optimize().
........
2008-02-11 18:57:17 -04:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
test_main()
|