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
f1855a2b
Commit
f1855a2b
authored
6 years ago
by
Paul McCarthy
Browse files
Options
Downloads
Patches
Plain Diff
New unit test for run(submit=True). Not going to test fslsub right now, as it
will probably change.
parent
1bd1ab69
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
tests/__init__.py
+11
-2
11 additions, 2 deletions
tests/__init__.py
tests/test_run.py
+45
-3
45 additions, 3 deletions
tests/test_run.py
with
56 additions
and
5 deletions
tests/__init__.py
+
11
−
2
View file @
f1855a2b
...
...
@@ -21,6 +21,10 @@ import nibabel as nib
from
six
import
StringIO
try
:
from
unittest
import
mock
except
ImportError
:
import
mock
import
fsl.data.image
as
fslimage
from
fsl.utils.tempdir
import
tempdir
from
fsl.utils.platform
import
platform
as
fslplatform
...
...
@@ -37,9 +41,14 @@ def mockFSLDIR():
try
:
with
tempdir
()
as
td
:
fsldir
=
op
.
join
(
td
,
'
fsl
'
)
os
.
makedirs
(
fsldir
)
bindir
=
op
.
join
(
fsldir
,
'
bin
'
)
os
.
makedirs
(
bindir
)
fslplatform
.
fsldir
=
fsldir
yield
fsldir
path
=
op
.
pathsep
.
join
((
bindir
,
os
.
environ
[
'
PATH
'
]))
with
mock
.
patch
.
dict
(
os
.
environ
,
{
'
PATH
'
:
path
}):
yield
fsldir
finally
:
fslplatform
.
fsldir
=
oldval
...
...
This diff is collapsed.
Click to expand it.
tests/test_run.py
+
45
−
3
View file @
f1855a2b
...
...
@@ -20,8 +20,9 @@ import pytest
import
fsl.utils.tempdir
as
tempdir
from
fsl.utils.platform
import
platform
as
fslplatform
import
fsl.utils.run
as
run
import
fsl.utils.fslsub
as
fslsub
from
.
import
make_random_image
from
.
import
make_random_image
,
mockFSLDIR
def
test_run
():
...
...
@@ -58,7 +59,9 @@ def test_run():
assert
stderr
.
strip
()
==
expstderr
# test return code
stdout
,
ret
=
run
.
run
(
'
./script.sh 1 2 3
'
,
ret
=
True
)
res
=
run
.
run
(
'
./script.sh 1 2 3
'
,
ret
=
True
)
print
(
res
)
stdout
,
ret
=
res
assert
stdout
.
strip
()
==
expstdout
assert
ret
==
0
stdout
,
stderr
,
ret
=
run
.
run
(
'
./script.sh 1 2 3
'
,
err
=
True
,
ret
=
True
)
...
...
@@ -123,7 +126,6 @@ def test_runfsl():
with
pytest
.
raises
(
run
.
FSLNotPresent
):
run
.
runfsl
(
'
fslhd image
'
)
# FSLDIR/bin exists - should be good
fsldir
=
op
.
abspath
(
'
./fsl
'
)
fslhd
=
op
.
join
(
fsldir
,
'
bin
'
,
'
fslhd
'
)
...
...
@@ -138,3 +140,43 @@ def test_runfsl():
assert
run
.
runfsl
(
'
fslhd image
'
).
strip
()
==
'
image
'
finally
:
fslplatform
.
fsldir
=
old_fsldir
mock_fsl_sub
=
textwrap
.
dedent
(
"""
#!/usr/bin/env bash
jid=12345
cmd=$1
name=`basename $cmd`
$cmd >
"
$name
"
.o
"
$jid
"
touch
"
$name
"
.e
"
$jid
"
echo $jid
exit 0
"""
).
strip
()
def
test_run_submit
():
def
mkexec
(
path
,
contents
):
with
open
(
path
,
'
wt
'
)
as
f
:
f
.
write
(
contents
)
os
.
chmod
(
path
,
0o755
)
test_script
=
textwrap
.
dedent
(
"""
#!/usr/bin/env bash
echo test_script running
exit 0
"""
).
strip
()
with
tempdir
.
tempdir
(),
mockFSLDIR
():
mkexec
(
op
.
expandvars
(
'
$FSLDIR/bin/fsltest
'
),
test_script
)
mkexec
(
op
.
expandvars
(
'
$FSLDIR/bin/fsl_sub
'
),
mock_fsl_sub
)
jid
=
run
.
run
(
'
fsltest
'
,
submit
=
True
)[
0
]
assert
jid
==
'
12345
'
stdout
,
stderr
=
fslsub
.
output
(
jid
,
'
fsltest
'
)
assert
stdout
.
strip
()
==
'
test_script running
'
assert
stderr
.
strip
()
==
''
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