Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
FSL
fslpy
Commits
b47fdbde
Commit
b47fdbde
authored
Oct 27, 2021
by
Paul McCarthy
🚵
Browse files
TEST: Unit tests for json metadata with ctrl chars
parent
ecdfe130
Changes
2
Hide whitespace changes
Inline
Side-by-side
tests/test_bids.py
View file @
b47fdbde
...
...
@@ -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'
)
...
...
tests/test_image.py
View file @
b47fdbde
...
...
@@ -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'
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment