-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create test for repickling and switch to highest protocol
- Loading branch information
1 parent
2e69f33
commit 27ca806
Showing
6 changed files
with
166 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
""" | ||
Test whether pickling hdf5 datasets works in single_process mode | ||
""" | ||
|
||
import unittest | ||
import tempfile | ||
import pickle | ||
import os | ||
import h5py | ||
import h5pickle | ||
|
||
class PicklingTest(unittest.TestCase): | ||
file = tempfile.mkstemp(suffix='.h5')[1] | ||
def setUp(self): | ||
with h5py.File(self.file, 'w') as f: | ||
f['a'] = 1 | ||
|
||
def test_readonly_skip_cache(self): | ||
f = h5pickle.File(self.file, 'r', skip_cache=True) | ||
self.assertEqual(f['a'][()], 1, 'can read from file') | ||
|
||
g = pickle.loads(pickle.dumps(f['a'])) | ||
|
||
self.assertEqual(g[()], 1, 'reading from dataset should give correct result') | ||
|
||
f.close() | ||
g.file.close() | ||
|
||
if __name__ == '__main__': | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
""" | ||
Test whether pickling hdf5 datasets works in single_process mode | ||
""" | ||
|
||
import unittest | ||
import tempfile | ||
import pickle | ||
import os | ||
import h5py | ||
import h5pickle | ||
|
||
class PicklingTest(unittest.TestCase): | ||
file = tempfile.mkstemp(suffix='.h5')[1] | ||
def setUp(self): | ||
with h5py.File(self.file, 'w') as f: | ||
f['a'] = 1 | ||
|
||
@unittest.expectedFailure | ||
def test_0(self): | ||
f = h5pickle.File(self.file, 'r', skip_cache=True) | ||
protocol = 0 | ||
|
||
h = pickle.loads(pickle.dumps(f, protocol=protocol)) | ||
self.assertEqual(f['a'][()], 1, 'reading from file dataset should give correct result') | ||
|
||
g = pickle.loads(pickle.dumps(f['a'], protocol=protocol)) | ||
self.assertEqual(g[()], 1, 'reading from dataset should give correct result') | ||
|
||
f.close() | ||
h.close() | ||
g.file.close() | ||
|
||
@unittest.expectedFailure | ||
def test_1(self): | ||
f = h5pickle.File(self.file, 'r', skip_cache=True) | ||
protocol = 1 | ||
|
||
h = pickle.loads(pickle.dumps(f, protocol=protocol)) | ||
self.assertEqual(f['a'][()], 1, 'reading from file dataset should give correct result') | ||
|
||
g = pickle.loads(pickle.dumps(f['a'], protocol=protocol)) | ||
self.assertEqual(g[()], 1, 'reading from dataset should give correct result') | ||
|
||
f.close() | ||
h.close() | ||
g.file.close() | ||
|
||
def test_2(self): | ||
f = h5pickle.File(self.file, 'r', skip_cache=True) | ||
protocol = 2 | ||
|
||
h = pickle.loads(pickle.dumps(f, protocol=protocol)) | ||
self.assertEqual(f['a'][()], 1, 'reading from file dataset should give correct result') | ||
|
||
g = pickle.loads(pickle.dumps(f['a'], protocol=protocol)) | ||
self.assertEqual(g[()], 1, 'reading from dataset should give correct result') | ||
|
||
f.close() | ||
h.close() | ||
g.file.close() | ||
|
||
def test_3(self): | ||
f = h5pickle.File(self.file, 'r', skip_cache=True) | ||
protocol = 3 | ||
|
||
h = pickle.loads(pickle.dumps(f, protocol=protocol)) | ||
self.assertEqual(f['a'][()], 1, 'reading from file dataset should give correct result') | ||
|
||
g = pickle.loads(pickle.dumps(f['a'], protocol=protocol)) | ||
self.assertEqual(g[()], 1, 'reading from dataset should give correct result') | ||
|
||
f.close() | ||
h.close() | ||
g.file.close() | ||
|
||
def tearDown(self): | ||
os.remove(self.file) | ||
|
||
if __name__ == '__main__': | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
""" | ||
Test whether re-pickling hdf5 works | ||
""" | ||
|
||
import unittest | ||
import tempfile | ||
import pickle | ||
import os | ||
import h5py | ||
import h5pickle | ||
|
||
class RePicklingTest(unittest.TestCase): | ||
file = tempfile.mkstemp(suffix='.h5')[1] | ||
def setUp(self): | ||
with h5py.File(self.file, 'w') as f: | ||
f['a'] = 1 | ||
|
||
def test_repickling(self): | ||
f = h5pickle.File(self.file, 'r', skip_cache=True) | ||
dataset = f['a'] | ||
dataset_pickled = pickle.dumps(dataset, protocol=pickle.HIGHEST_PROTOCOL) | ||
dataset_unpickled = pickle.loads(dataset_pickled) | ||
dataset_repickled = pickle.dumps(dataset_unpickled, protocol=pickle.HIGHEST_PROTOCOL) | ||
|
||
def tearDown(self): | ||
os.remove(self.file) | ||
|
||
if __name__ == '__main__': | ||
unittest.main() |