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
ab598b91
Commit
ab598b91
authored
1 year ago
by
Paul McCarthy
Browse files
Options
Downloads
Patches
Plain Diff
TEST: Test cluster wrapper
parent
2dd93b22
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
fsl/tests/test_wrappers/__init__.py
+1
-0
1 addition, 0 deletions
fsl/tests/test_wrappers/__init__.py
fsl/tests/test_wrappers/test_cluster.py
+69
-0
69 additions, 0 deletions
fsl/tests/test_wrappers/test_cluster.py
with
70 additions
and
0 deletions
fsl/tests/test_wrappers/__init__.py
+
1
−
0
View file @
ab598b91
...
...
@@ -46,3 +46,4 @@ def testenv(*fslexes):
fslexes
=
[
op
.
join
(
fsldir
,
'
bin
'
,
e
)
for
e
in
fslexes
]
if
len
(
fslexes
)
==
1
:
yield
fslexes
[
0
]
else
:
yield
fslexes
testenv
.
__test__
=
False
This diff is collapsed.
Click to expand it.
fsl/tests/test_wrappers/test_cluster.py
0 → 100644
+
69
−
0
View file @
ab598b91
#!/usr/bin/env python
#
# test_cluster.py -
#
# Author: Paul McCarthy <pauldmccarthy@gmail.com>
#
import
contextlib
import
os
import
os.path
as
op
import
sys
import
numpy
as
np
from
fsl.wrappers.cluster
import
cluster
,
_cluster
from
.
import
testenv
from
..
import
mockFSLDIR
@contextlib.contextmanager
def
reseed
(
seed
):
state
=
np
.
random
.
get_state
()
np
.
random
.
seed
(
seed
)
try
:
yield
finally
:
np
.
random
.
set_state
(
state
)
def
test_cluster_wrapper
():
with
testenv
(
'
fsl-cluster
'
)
as
cluster_exe
:
result
=
_cluster
(
'
input
'
,
10
,
mm
=
True
)
expected
=
[
cluster_exe
,
'
-i
'
,
'
input
'
,
'
-t
'
,
'
10
'
,
'
--mm
'
]
expected
=
'
'
.
join
(
expected
)
assert
result
.
stdout
[
0
]
==
expected
mock_titles
=
'
ABCDEFGHIJ
'
mock_cluster
=
f
"""
#!
{
sys
.
executable
}
import numpy as np
np.random.seed(12345)
data = np.random.randint(1, 10, (10, 10))
print(
'
\t
'
.join(
'
{
mock_titles
}
'
))
for row in data:
print(
'
\t
'
.join([str(val) for val in row]))
"""
.
strip
()
def
test_cluster
():
with
mockFSLDIR
()
as
fsldir
:
cluster_exe
=
op
.
join
(
fsldir
,
'
bin
'
,
'
fsl-cluster
'
)
with
open
(
cluster_exe
,
'
wt
'
)
as
f
:
f
.
write
(
mock_cluster
)
os
.
chmod
(
cluster_exe
,
0o755
)
data
,
titles
,
result1
=
cluster
(
'
input
'
,
3.5
)
result2
=
cluster
(
'
input
'
,
3.5
,
load
=
False
)
with
reseed
(
12345
):
expected
=
np
.
random
.
randint
(
1
,
10
,
(
10
,
10
))
assert
np
.
all
(
np
.
isclose
(
data
,
expected
))
assert
''
.
join
(
titles
)
==
mock_titles
assert
result1
.
stdout
==
result2
.
stdout
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