| Line | |
|---|
| 1 | # test_pickle dumps and loads pickles via pickle.py.
|
|---|
| 2 | # test_cpickle does the same, but via the cPickle module.
|
|---|
| 3 | # This test covers the other two cases, making pickles with one module and
|
|---|
| 4 | # loading them via the other.
|
|---|
| 5 |
|
|---|
| 6 | import pickle
|
|---|
| 7 | import cPickle
|
|---|
| 8 | import unittest
|
|---|
| 9 |
|
|---|
| 10 | from test import test_support
|
|---|
| 11 | from test.pickletester import AbstractPickleTests
|
|---|
| 12 |
|
|---|
| 13 | class DumpCPickle_LoadPickle(AbstractPickleTests):
|
|---|
| 14 |
|
|---|
| 15 | error = KeyError
|
|---|
| 16 |
|
|---|
| 17 | def dumps(self, arg, proto=0, fast=0):
|
|---|
| 18 | # Ignore fast
|
|---|
| 19 | return cPickle.dumps(arg, proto)
|
|---|
| 20 |
|
|---|
| 21 | def loads(self, buf):
|
|---|
| 22 | # Ignore fast
|
|---|
| 23 | return pickle.loads(buf)
|
|---|
| 24 |
|
|---|
| 25 | class DumpPickle_LoadCPickle(AbstractPickleTests):
|
|---|
| 26 |
|
|---|
| 27 | error = cPickle.BadPickleGet
|
|---|
| 28 |
|
|---|
| 29 | def dumps(self, arg, proto=0, fast=0):
|
|---|
| 30 | # Ignore fast
|
|---|
| 31 | return pickle.dumps(arg, proto)
|
|---|
| 32 |
|
|---|
| 33 | def loads(self, buf):
|
|---|
| 34 | # Ignore fast
|
|---|
| 35 | return cPickle.loads(buf)
|
|---|
| 36 |
|
|---|
| 37 | def test_main():
|
|---|
| 38 | test_support.run_unittest(
|
|---|
| 39 | DumpCPickle_LoadPickle,
|
|---|
| 40 | DumpPickle_LoadCPickle
|
|---|
| 41 | )
|
|---|
| 42 |
|
|---|
| 43 | if __name__ == "__main__":
|
|---|
| 44 | test_main()
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.