home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2011 June / maximum-cd-2011-06.iso / DiscContents / LibO_3.3.1_Win_x86_install_multi.exe / libreoffice1.cab / test_xpickle.py < prev    next >
Encoding:
Python Source  |  2011-02-15  |  1.0 KB  |  44 lines

  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.  
  9. from test import test_support
  10. from test.pickletester import AbstractPickleTests
  11.  
  12. class DumpCPickle_LoadPickle(AbstractPickleTests):
  13.  
  14.     error = KeyError
  15.  
  16.     def dumps(self, arg, proto=0, fast=0):
  17.         # Ignore fast
  18.         return cPickle.dumps(arg, proto)
  19.  
  20.     def loads(self, buf):
  21.         # Ignore fast
  22.         return pickle.loads(buf)
  23.  
  24. class DumpPickle_LoadCPickle(AbstractPickleTests):
  25.  
  26.     error = cPickle.BadPickleGet
  27.  
  28.     def dumps(self, arg, proto=0, fast=0):
  29.         # Ignore fast
  30.         return pickle.dumps(arg, proto)
  31.  
  32.     def loads(self, buf):
  33.         # Ignore fast
  34.         return cPickle.loads(buf)
  35.  
  36. def test_main():
  37.     test_support.run_unittest(
  38.         DumpCPickle_LoadPickle,
  39.         DumpPickle_LoadCPickle
  40.     )
  41.  
  42. if __name__ == "__main__":
  43.     test_main()
  44.