Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions nipype/tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from nipype import utils


def test_pickle(tmp_path):
testobj = 'iamateststr'
pickle_fname = str(tmp_path / 'testpickle.pklz')
utils.filemanip.savepkl(pickle_fname, testobj)
outobj = utils.filemanip.loadpkl(pickle_fname)
assert outobj == testobj


def test_pickle_versioning(tmp_path):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about parameterizing this into a single test?

@pytest.mark.parametrize("save_ver", (True, False))
@pytest.mark.parametrize("load_ver", (True, False))
def test_pickle(tmp_path, save_ver, load_ver):
    testobj = 'iamateststr'
    pickle_fname = str(tmp_path / 'testpickle.pklz')
    utils.filemanip.savepkl(pickle_fname, testobj, versioning=save_ver)
    outobj = utils.filemanip.loadpkl(pickle_fname, versioning=load_ver)
    assert outobj == testobj

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea.

testobj = 'iamateststr'
pickle_fname = str(tmp_path / 'testpickle.pklz')
utils.filemanip.savepkl(pickle_fname, testobj, versioning=True)
outobj = utils.filemanip.loadpkl(pickle_fname)
assert outobj == testobj
2 changes: 0 additions & 2 deletions nipype/utils/filemanip.py
Original file line number Diff line number Diff line change
Expand Up @@ -689,8 +689,6 @@ def loadpkl(infile, versioning=False):
pkl_metadata_line = pkl_file.readline()
pkl_metadata = json.loads(pkl_metadata_line)
except (UnicodeDecodeError, json.JSONDecodeError):
pass
finally:
# Could not get version info
pkl_file.seek(0)

Expand Down