test_pickle.py 401 B

123456789101112131415161718192021222324252627
  1. import os
  2. import tempfile
  3. import pickle
  4. from mpmath import *
  5. def pickler(obj):
  6. fn = tempfile.mktemp()
  7. f = open(fn, 'wb')
  8. pickle.dump(obj, f)
  9. f.close()
  10. f = open(fn, 'rb')
  11. obj2 = pickle.load(f)
  12. f.close()
  13. os.remove(fn)
  14. return obj2
  15. def test_pickle():
  16. obj = mpf('0.5')
  17. assert obj == pickler(obj)
  18. obj = mpc('0.5','0.2')
  19. assert obj == pickler(obj)