test_numpy_pickle_compat.py 624 B

123456789101112131415161718
  1. """Test the old numpy pickler, compatibility version."""
  2. import random
  3. # numpy_pickle is not a drop-in replacement of pickle, as it takes
  4. # filenames instead of open files as arguments.
  5. from joblib import numpy_pickle_compat
  6. def test_z_file(tmpdir):
  7. # Test saving and loading data with Zfiles.
  8. filename = tmpdir.join('test.pkl').strpath
  9. data = numpy_pickle_compat.asbytes('Foo, \n Bar, baz, \n\nfoobar')
  10. with open(filename, 'wb') as f:
  11. numpy_pickle_compat.write_zfile(f, data)
  12. with open(filename, 'rb') as f:
  13. data_read = numpy_pickle_compat.read_zfile(f)
  14. assert data == data_read