Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
fslpy
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Michiel Cottaar
fslpy
Commits
9a99c71d
Commit
9a99c71d
authored
8 years ago
by
Paul McCarthy
Browse files
Options
Downloads
Patches
Plain Diff
test_image module rewritten so it generates its own data, instead of relying
on an existing data set.
parent
5d063e35
No related branches found
No related tags found
No related merge requests found
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
tests/__init__.py
+6
-16
6 additions, 16 deletions
tests/__init__.py
tests/test_image.py
+436
-172
436 additions, 172 deletions
tests/test_image.py
tests/test_immv_imcp.py
+16
-5
16 additions, 5 deletions
tests/test_immv_imcp.py
with
458 additions
and
193 deletions
tests/__init__.py
+
6
−
16
View file @
9a99c71d
...
@@ -60,24 +60,14 @@ def cleardir(dir):
...
@@ -60,24 +60,14 @@ def cleardir(dir):
elif
op
.
isdir
(
f
):
shutil
.
rmtree
(
f
)
elif
op
.
isdir
(
f
):
shutil
.
rmtree
(
f
)
def
make_random_image
(
filename
,
dims
=
(
10
,
10
,
10
),
affine
=
None
):
def
make_random_image
(
filename
,
dims
=
(
10
,
10
,
10
)):
"""
Creates a NIFTI image with random data, returns the hash of said data.
"""
Creates a NIFTI1 image with random data, saves and
returns it.
"""
"""
if
affine
is
None
:
data
=
np
.
array
(
np
.
random
.
random
(
dims
)
*
100
,
dtype
=
np
.
float32
)
affine
=
np
.
eye
(
4
)
img
=
nib
.
Nifti1Image
(
data
,
np
.
eye
(
4
))
data
=
np
.
random
.
random
(
dims
)
img
=
nib
.
Nifti1Image
(
data
,
affine
)
nib
.
save
(
img
,
filename
)
nib
.
save
(
img
,
filename
)
return
hash
(
data
.
tobytes
())
return
img
def
check_image_hash
(
filename
,
datahash
):
"""
Checks that the given NIFTI image matches the given hash.
"""
img
=
nib
.
load
(
filename
)
assert
hash
(
img
.
get_data
().
tobytes
())
==
datahash
This diff is collapsed.
Click to expand it.
tests/test_image.py
+
436
−
172
View file @
9a99c71d
This diff is collapsed.
Click to expand it.
tests/test_immv_imcp.py
+
16
−
5
View file @
9a99c71d
...
@@ -31,11 +31,22 @@ import fsl.data.image as fslimage
...
@@ -31,11 +31,22 @@ import fsl.data.image as fslimage
from
.
import
make_random_image
from
.
import
make_random_image
from
.
import
make_dummy_file
from
.
import
make_dummy_file
from
.
import
check_image_hash
from
.
import
looks_like_image
from
.
import
looks_like_image
from
.
import
cleardir
from
.
import
cleardir
def
makeImage
(
filename
):
return
hash
(
make_random_image
(
filename
).
get_data
().
tobytes
())
def
checkImageHash
(
filename
,
datahash
):
"""
Checks that the given NIFTI image matches the given hash.
"""
img
=
nib
.
load
(
filename
)
assert
hash
(
img
.
get_data
().
tobytes
())
==
datahash
def
checkFilesToExpect
(
files
,
outdir
,
outputType
,
datahashes
):
def
checkFilesToExpect
(
files
,
outdir
,
outputType
,
datahashes
):
exts
=
{
exts
=
{
...
@@ -91,7 +102,7 @@ def checkFilesToExpect(files, outdir, outputType, datahashes):
...
@@ -91,7 +102,7 @@ def checkFilesToExpect(files, outdir, outputType, datahashes):
else
:
else
:
h
=
datahashes
[
op
.
basename
(
f
)]
h
=
datahashes
[
op
.
basename
(
f
)]
check
_i
mage
_h
ash
(
f
,
h
)
check
I
mage
H
ash
(
f
,
h
)
def
test_imcp_script_shouldPass
(
move
=
False
):
def
test_imcp_script_shouldPass
(
move
=
False
):
...
@@ -308,7 +319,7 @@ def test_imcp_script_shouldPass(move=False):
...
@@ -308,7 +319,7 @@ def test_imcp_script_shouldPass(move=False):
print
(
'
files_to_expect:
'
,
files_to_expect
)
print
(
'
files_to_expect:
'
,
files_to_expect
)
for
i
,
fname
in
enumerate
(
files_to_create
.
split
()):
for
i
,
fname
in
enumerate
(
files_to_create
.
split
()):
imageHashes
.
append
(
make
_random_i
mage
(
op
.
join
(
indir
,
fname
)))
imageHashes
.
append
(
make
I
mage
(
op
.
join
(
indir
,
fname
)))
imcp_args
=
imcp_args
.
split
()
imcp_args
=
imcp_args
.
split
()
...
@@ -413,7 +424,7 @@ def test_imcp_script_shouldFail(move=False):
...
@@ -413,7 +424,7 @@ def test_imcp_script_shouldFail(move=False):
imcp_args
=
imcp_args
.
split
()
imcp_args
=
imcp_args
.
split
()
for
fname
in
files_to_create
:
for
fname
in
files_to_create
:
make
_random_i
mage
(
op
.
join
(
indir
,
fname
))
make
I
mage
(
op
.
join
(
indir
,
fname
))
imcp_args
[:
-
1
]
=
[
op
.
join
(
indir
,
a
)
for
a
in
imcp_args
[:
-
1
]]
imcp_args
[:
-
1
]
=
[
op
.
join
(
indir
,
a
)
for
a
in
imcp_args
[:
-
1
]]
imcp_args
[
-
1
]
=
op
.
join
(
outdir
,
imcp_args
[
-
1
])
imcp_args
[
-
1
]
=
op
.
join
(
outdir
,
imcp_args
[
-
1
])
...
@@ -609,7 +620,7 @@ def test_imcp_shouldPass(move=False):
...
@@ -609,7 +620,7 @@ def test_imcp_shouldPass(move=False):
hashes
=
{}
hashes
=
{}
for
fn
in
files_to_create
:
for
fn
in
files_to_create
:
if
looks_like_image
(
fn
):
if
looks_like_image
(
fn
):
hashes
[
fn
]
=
make
_random_i
mage
(
op
.
join
(
indir
,
fn
))
hashes
[
fn
]
=
make
I
mage
(
op
.
join
(
indir
,
fn
))
else
:
else
:
hashes
[
fn
]
=
make_dummy_file
(
op
.
join
(
indir
,
fn
))
hashes
[
fn
]
=
make_dummy_file
(
op
.
join
(
indir
,
fn
))
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment