0001 import pickle 0002 import unittest 0003 from cStringIO import StringIO 0004 0005 from test import test_support 0006 0007 from test.pickletester import AbstractPickleTests 0008 from test.pickletester import AbstractPickleModuleTests 0009 from test.pickletester import AbstractPersistentPicklerTests 0010 0011 class PickleTests(AbstractPickleTests, AbstractPickleModuleTests): 0012 0013 def dumps(self, arg, proto=0, fast=0): 0014 # Ignore fast 0015 return pickle.dumps(arg, proto) 0016 0017 def loads(self, buf): 0018 # Ignore fast 0019 return pickle.loads(buf) 0020 0021 module = pickle 0022 error = KeyError 0023 0024 class PicklerTests(AbstractPickleTests): 0025 0026 error = KeyError 0027 0028 def dumps(self, arg, proto=0, fast=0): 0029 f = StringIO() 0030 p = pickle.Pickler(f, proto) 0031 if fast: 0032 p.fast = fast 0033 p.dump(arg) 0034 f.seek(0) 0035 return f.read() 0036 0037 def loads(self, buf): 0038 f = StringIO(buf) 0039 u = pickle.Unpickler(f) 0040 return u.load() 0041 0042 class PersPicklerTests(AbstractPersistentPicklerTests): 0043 0044 def dumps(self, arg, proto=0, fast=0): 0045 class PersPickler(pickle.Pickler): 0046 def persistent_id(subself, obj): 0047 return self.persistent_id(obj) 0048 f = StringIO() 0049 p = PersPickler(f, proto) 0050 if fast: 0051 p.fast = fast 0052 p.dump(arg) 0053 f.seek(0) 0054 return f.read() 0055 0056 def loads(self, buf): 0057 class PersUnpickler(pickle.Unpickler): 0058 def persistent_load(subself, obj): 0059 return self.persistent_load(obj) 0060 f = StringIO(buf) 0061 u = PersUnpickler(f) 0062 return u.load() 0063 0064 def test_main(): 0065 test_support.run_unittest( 0066 PickleTests, 0067 PicklerTests, 0068 PersPicklerTests 0069 ) 0070 test_support.run_doctest(pickle) 0071 0072 if __name__ == "__main__": 0073 test_main() 0074
Generated by PyXR 0.9.4