Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
fslpy
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Analyze
Contributor analytics
CI/CD 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
FSL
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):
elif
op
.
isdir
(
f
):
shutil
.
rmtree
(
f
)
def
make_random_image
(
filename
,
dims
=
(
10
,
10
,
10
),
affine
=
None
):
"""
Creates a NIFTI image with random data, returns the hash of said data.
def
make_random_image
(
filename
,
dims
=
(
10
,
10
,
10
)):
"""
Creates a NIFTI1 image with random data, saves and
returns it.
"""
if
affine
is
None
:
affine
=
np
.
eye
(
4
)
data
=
np
.
random
.
random
(
dims
)
img
=
nib
.
Nifti1Image
(
data
,
affine
)
data
=
np
.
array
(
np
.
random
.
random
(
dims
)
*
100
,
dtype
=
np
.
float32
)
img
=
nib
.
Nifti1Image
(
data
,
np
.
eye
(
4
))
nib
.
save
(
img
,
filename
)
return
hash
(
data
.
tobytes
())
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
return
img
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
from
.
import
make_random_image
from
.
import
make_dummy_file
from
.
import
check_image_hash
from
.
import
looks_like_image
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
):
exts
=
{
...
...
@@ -91,7 +102,7 @@ def checkFilesToExpect(files, outdir, outputType, datahashes):
else
:
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
):
...
...
@@ -308,7 +319,7 @@ def test_imcp_script_shouldPass(move=False):
print
(
'
files_to_expect:
'
,
files_to_expect
)
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
()
...
...
@@ -413,7 +424,7 @@ def test_imcp_script_shouldFail(move=False):
imcp_args
=
imcp_args
.
split
()
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
(
outdir
,
imcp_args
[
-
1
])
...
...
@@ -609,7 +620,7 @@ def test_imcp_shouldPass(move=False):
hashes
=
{}
for
fn
in
files_to_create
:
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
:
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