Commit 8aa30d0e authored by Paul McCarthy's avatar Paul McCarthy 🚵
Browse files

TEST: Unit tests for json metadata with ctrl chars

parent afb2f31d
......@@ -110,6 +110,21 @@ def test_loadMetadata():
assert fslbids.loadMetadata(t1) == {**meta4, **meta2, **meta1}
def test_loadMetadata_control_characters():
dd = Path('dataset_description.json')
t1 = Path('sub-01/func/sub-01_task-stim_bold.nii.gz')
json1 = Path('sub-01/func/sub-01_task-stim_bold.json')
meta1 = {"a" : "1", "b" : "2\x19\x20"}
smeta1 = '{"a" : "1", "b" : "2\x19\x20"}'
with tempdir():
dd.touch()
Path(op.dirname(t1)).mkdir(parents=True)
t1.touch()
assert fslbids.loadMetadata(t1) == {}
json1.write_text(smeta1)
assert fslbids.loadMetadata(t1) == meta1
def test_loadMetadata_symlinked():
ddreal = Path('a')
......
......@@ -1484,6 +1484,21 @@ def test_loadMeta_badJSON():
assert list(img.metaKeys()) == []
def test_loadMeta_control_characters():
with tempdir():
make_image('image.nii.gz')
with open('image.json', 'wt') as f:
f.write('{"a" : 1, "b" : "abc\x19\x1b"}')
# bad json should not cause failure
img = fslimage.Image('image.nii.gz', loadMeta=True)
assert list(img.metaKeys()) == ['a', 'b']
assert img.getMeta('a') == 1
assert img.getMeta('b') == 'abc\x19\x1b'
def test_loadMetadata():
with tempdir():
make_image('image.nii.gz')
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment