diff --git a/heudiconv/bids.py b/heudiconv/bids.py index fa5d2600..2043629c 100644 --- a/heudiconv/bids.py +++ b/heudiconv/bids.py @@ -23,6 +23,7 @@ is_readonly, get_datetime, ) +from . import __version__ lgr = logging.getLogger(__name__) @@ -40,6 +41,10 @@ ("Description", "md5 hash of UIDs")])), ]) +#: JSON Key where we will embed our version in the newly produced .json files +HEUDICONV_VERSION_JSON_KEY = 'HeudiconvVersion' + + class BIDSError(Exception): pass @@ -244,6 +249,10 @@ def tuneup_bids_json_files(json_files): # Let's hope no word 'Date' comes within a study name or smth like # that raise ValueError("There must be no dates in .json sidecar") + # Those files should not have our version field already - should have been + # freshly produced + assert HEUDICONV_VERSION_JSON_KEY not in json_ + json_[HEUDICONV_VERSION_JSON_KEY] = str(__version__) save_json(jsonfile, json_) # Load the beast diff --git a/heudiconv/tests/test_heuristics.py b/heudiconv/tests/test_heuristics.py index 1232ac1b..69008779 100644 --- a/heudiconv/tests/test_heuristics.py +++ b/heudiconv/tests/test_heuristics.py @@ -7,9 +7,14 @@ from glob import glob from os.path import join as pjoin, dirname +from pathlib import Path import csv import re +from .. import __version__ +from ..bids import HEUDICONV_VERSION_JSON_KEY +from ..utils import load_json + import pytest from .utils import TESTS_DATA_PATH @@ -140,16 +145,22 @@ def test_scout_conversion(tmpdir): ).split(' ') + ['-o', tmppath] runner(args) - assert not op.exists(pjoin( - tmppath, - 'Halchenko/Yarik/950_bids_test4/sub-phantom1sid1/ses-localizer/anat')) - - assert op.exists(pjoin( - tmppath, - 'Halchenko/Yarik/950_bids_test4/sourcedata/sub-phantom1sid1/' - 'ses-localizer/anat/sub-phantom1sid1_ses-localizer_scout.dicom.tgz' - ) - ) + dspath = Path(tmppath) / 'Halchenko/Yarik/950_bids_test4' + sespath = dspath / 'sub-phantom1sid1/ses-localizer' + + assert not (sespath / 'anat').exists() + assert ( + dspath / + 'sourcedata/sub-phantom1sid1/ses-localizer/' + 'anat/sub-phantom1sid1_ses-localizer_scout.dicom.tgz' + ).exists() + + # Let's do some basic checks on produced files + j = load_json(sespath / 'fmap/sub-phantom1sid1_ses-localizer_acq-3mm_phasediff.json') + # We store HeuDiConv version in each produced .json file + # TODO: test that we are not somehow overwritting that version in existing + # files which we have not produced in a particular run. + assert j[HEUDICONV_VERSION_JSON_KEY] == __version__ @pytest.mark.parametrize(