diff options
author | Olivier Grisel <olivier.grisel@ensta.org> | 2013-11-26 16:12:06 +0100 |
---|---|---|
committer | Olivier Grisel <olivier.grisel@ensta.org> | 2013-11-26 19:21:08 +0100 |
commit | 7a497ffdecceec2d8574674a2b8b04f7927f75d4 (patch) | |
tree | 847583e7f87558cec6a91090c9fd154103f92e7b /numpy/lib/tests/test_io.py | |
parent | 207474ffcf835baa4d8511eff1f021f1b2bf6532 (diff) | |
download | numpy-7a497ffdecceec2d8574674a2b8b04f7927f75d4.tar.gz |
TST: Increase test coverage of numpy.save/load roundtrips
Diffstat (limited to 'numpy/lib/tests/test_io.py')
-rw-r--r-- | numpy/lib/tests/test_io.py | 42 |
1 files changed, 36 insertions, 6 deletions
diff --git a/numpy/lib/tests/test_io.py b/numpy/lib/tests/test_io.py index 66310a509..e3ccb391c 100644 --- a/numpy/lib/tests/test_io.py +++ b/numpy/lib/tests/test_io.py @@ -104,18 +104,40 @@ class RoundtripTest(object): self.arr = arr self.arr_reloaded = arr_reloaded + def check_roundtrips(self, a): + self.roundtrip(a) + self.roundtrip(a, file_on_disk=True) + self.roundtrip(np.asfortranarray(a)) + self.roundtrip(np.asfortranarray(a), file_on_disk=True) + if a.shape[0] > 1: + # neither C nor Fortran contiguous for 2D arrays or more + self.roundtrip(np.asfortranarray(a)[1:]) + self.roundtrip(np.asfortranarray(a)[1:], file_on_disk=True) + def test_array(self): + a = np.array([], float) + self.check_roundtrips(a) + a = np.array([[1, 2], [3, 4]], float) - self.roundtrip(a) + self.check_roundtrips(a) a = np.array([[1, 2], [3, 4]], int) - self.roundtrip(a) + self.check_roundtrips(a) a = np.array([[1 + 5j, 2 + 6j], [3 + 7j, 4 + 8j]], dtype=np.csingle) - self.roundtrip(a) + self.check_roundtrips(a) a = np.array([[1 + 5j, 2 + 6j], [3 + 7j, 4 + 8j]], dtype=np.cdouble) - self.roundtrip(a) + self.check_roundtrips(a) + + def test_array_object(self): + if sys.version_info[:2] >= (2, 7): + a = np.array([], object) + self.check_roundtrips(a) + + a = np.array([[1, 2], [3, 4]], object) + self.check_roundtrips(a) + # Fails with UnpicklingError: could not find MARK on Python 2.6 def test_1D(self): a = np.array([1, 2, 3, 4], int) @@ -126,22 +148,30 @@ class RoundtripTest(object): a = np.array([[1, 2.5], [4, 7.3]]) self.roundtrip(a, file_on_disk=True, load_kwds={'mmap_mode': 'r'}) + a = np.asfortranarray([[1, 2.5], [4, 7.3]]) + self.roundtrip(a, file_on_disk=True, load_kwds={'mmap_mode': 'r'}) + def test_record(self): a = np.array([(1, 2), (3, 4)], dtype=[('x', 'i4'), ('y', 'i4')]) - self.roundtrip(a) + self.check_roundtrips(a) class TestSaveLoad(RoundtripTest, TestCase): def roundtrip(self, *args, **kwargs): RoundtripTest.roundtrip(self, np.save, *args, **kwargs) assert_equal(self.arr[0], self.arr_reloaded) + assert_equal(self.arr[0].dtype, self.arr_reloaded.dtype) + assert_equal(self.arr[0].flags.fnc, self.arr_reloaded.flags.fnc) class TestSavezLoad(RoundtripTest, TestCase): def roundtrip(self, *args, **kwargs): RoundtripTest.roundtrip(self, np.savez, *args, **kwargs) for n, arr in enumerate(self.arr): - assert_equal(arr, self.arr_reloaded['arr_%d' % n]) + reloaded = self.arr_reloaded['arr_%d' % n] + assert_equal(arr, reloaded) + assert_equal(arr.dtype, reloaded.dtype) + assert_equal(arr.flags.fnc, reloaded.flags.fnc) @np.testing.dec.skipif(not IS_64BIT, "Works only with 64bit systems") @np.testing.dec.slow |