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
58b22bfb
Commit
58b22bfb
authored
6 years ago
by
Paul McCarthy
Browse files
Options
Downloads
Patches
Plain Diff
TEST: Test run(tee=True)
parent
8bd3ea7b
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
+3
-0
3 additions, 0 deletions
tests/__init__.py
tests/test_run.py
+67
-17
67 additions, 17 deletions
tests/test_run.py
with
70 additions
and
17 deletions
tests/__init__.py
+
3
−
0
View file @
58b22bfb
...
@@ -67,6 +67,9 @@ class CaptureStdout(object):
...
@@ -67,6 +67,9 @@ class CaptureStdout(object):
def
reset
(
self
):
def
reset
(
self
):
self
.
__mock_stdout
=
StringIO
(
''
)
self
.
__mock_stdout
=
StringIO
(
''
)
self
.
__mock_stderr
=
StringIO
(
''
)
self
.
__mock_stderr
=
StringIO
(
''
)
self
.
__mock_stdout
.
mode
=
'
w
'
self
.
__mock_stderr
.
mode
=
'
w
'
return
self
def
__enter__
(
self
):
def
__enter__
(
self
):
self
.
__real_stdout
=
sys
.
stdout
self
.
__real_stdout
=
sys
.
stdout
...
...
This diff is collapsed.
Click to expand it.
tests/test_run.py
+
67
−
17
View file @
58b22bfb
...
@@ -23,7 +23,7 @@ from fsl.utils.platform import platform as fslplatform
...
@@ -23,7 +23,7 @@ from fsl.utils.platform import platform as fslplatform
import
fsl.utils.run
as
run
import
fsl.utils.run
as
run
import
fsl.utils.fslsub
as
fslsub
import
fsl.utils.fslsub
as
fslsub
from
.
import
make_random_image
,
mockFSLDIR
from
.
import
make_random_image
,
mockFSLDIR
,
CaptureStdout
def
test_run
():
def
test_run
():
...
@@ -43,31 +43,30 @@ def test_run():
...
@@ -43,31 +43,30 @@ def test_run():
f
.
write
(
test_script
.
format
(
0
))
f
.
write
(
test_script
.
format
(
0
))
os
.
chmod
(
'
script.sh
'
,
0o755
)
os
.
chmod
(
'
script.sh
'
,
0o755
)
expstdout
=
"
standard output - arguments: 1 2 3
"
expstdout
=
"
standard output - arguments: 1 2 3
\n
"
expstderr
=
"
standard error
"
expstderr
=
"
standard error
\n
"
# test:
# test:
# - single string
# - single string
# - packed sequence
# - packed sequence
# - unpacked sequence
# - unpacked sequence
assert
run
.
run
(
'
./script.sh 1 2 3
'
)
.
strip
()
==
expstdout
assert
run
.
run
(
'
./script.sh 1 2 3
'
)
==
expstdout
assert
run
.
run
((
'
./script.sh
'
,
'
1
'
,
'
2
'
,
'
3
'
))
==
expstdout
assert
run
.
run
((
'
./script.sh
'
,
'
1
'
,
'
2
'
,
'
3
'
))
==
expstdout
assert
run
.
run
(
*
(
'
./script.sh
'
,
'
1
'
,
'
2
'
,
'
3
'
))
==
expstdout
assert
run
.
run
(
*
(
'
./script.sh
'
,
'
1
'
,
'
2
'
,
'
3
'
))
==
expstdout
# test stdout/stderr
# test stdout/stderr
stdout
,
stderr
=
run
.
run
(
'
./script.sh 1 2 3
'
,
err
=
True
)
stdout
,
stderr
=
run
.
run
(
'
./script.sh 1 2 3
'
,
err
=
True
)
assert
stdout
.
strip
()
==
expstdout
assert
stdout
==
expstdout
assert
stderr
.
strip
()
==
expstderr
assert
stderr
==
expstderr
# test return code
# test return code
res
=
run
.
run
(
'
./script.sh 1 2 3
'
,
ret
=
True
)
res
=
run
.
run
(
'
./script.sh 1 2 3
'
,
ret
=
True
)
print
(
res
)
stdout
,
ret
=
res
stdout
,
ret
=
res
assert
stdout
.
strip
()
==
expstdout
assert
stdout
==
expstdout
assert
ret
==
0
assert
ret
==
0
stdout
,
stderr
,
ret
=
run
.
run
(
'
./script.sh 1 2 3
'
,
err
=
True
,
ret
=
True
)
stdout
,
stderr
,
ret
=
run
.
run
(
'
./script.sh 1 2 3
'
,
err
=
True
,
ret
=
True
)
assert
stdout
.
strip
()
==
expstdout
assert
stdout
==
expstdout
assert
stderr
.
strip
()
==
expstderr
assert
stderr
==
expstderr
assert
ret
==
0
assert
ret
==
0
# return code != 0
# return code != 0
...
@@ -79,10 +78,61 @@ def test_run():
...
@@ -79,10 +78,61 @@ def test_run():
run
.
run
(
'
./script.sh 1 2 3
'
)
run
.
run
(
'
./script.sh 1 2 3
'
)
stdout
,
ret
=
run
.
run
(
'
./script.sh 1 2 3
'
,
ret
=
True
)
stdout
,
ret
=
run
.
run
(
'
./script.sh 1 2 3
'
,
ret
=
True
)
assert
stdout
.
strip
()
==
expstdout
assert
stdout
==
expstdout
assert
ret
==
255
assert
ret
==
255
def
test_run_tee
():
test_script
=
textwrap
.
dedent
(
"""
#!/bin/bash
echo
"
standard output - arguments: $@
"
echo
"
standard error
"
>&2
exit 0
"""
).
strip
()
with
tempdir
.
tempdir
():
with
open
(
'
script.sh
'
,
'
wt
'
)
as
f
:
f
.
write
(
test_script
)
os
.
chmod
(
'
script.sh
'
,
0o755
)
expstdout
=
"
standard output - arguments: 1 2 3
\n
"
expstderr
=
"
standard error
\n
"
capture
=
CaptureStdout
()
with
capture
:
stdout
=
run
.
run
(
'
./script.sh 1 2 3
'
,
tee
=
True
)
assert
stdout
==
expstdout
assert
capture
.
stdout
==
expstdout
with
capture
.
reset
():
stdout
,
stderr
=
run
.
run
(
'
./script.sh 1 2 3
'
,
err
=
True
,
tee
=
True
)
assert
stdout
==
expstdout
assert
stderr
==
expstderr
assert
capture
.
stdout
==
expstdout
assert
capture
.
stderr
==
expstderr
with
capture
.
reset
():
stdout
,
stderr
,
ret
=
run
.
run
(
'
./script.sh 1 2 3
'
,
err
=
True
,
ret
=
True
,
tee
=
True
)
assert
ret
==
0
assert
stdout
==
expstdout
assert
stderr
==
expstderr
assert
capture
.
stdout
==
expstdout
assert
capture
.
stderr
==
expstderr
with
capture
.
reset
():
stdout
,
ret
=
run
.
run
(
'
./script.sh 1 2 3
'
,
ret
=
True
,
tee
=
True
)
assert
ret
==
0
assert
stdout
==
expstdout
assert
capture
.
stdout
==
expstdout
def
test_dryrun
():
def
test_dryrun
():
test_script
=
textwrap
.
dedent
(
"""
test_script
=
textwrap
.
dedent
(
"""
...
@@ -189,8 +239,8 @@ def test_run_submit():
...
@@ -189,8 +239,8 @@ def test_run_submit():
stdout
,
stderr
=
fslsub
.
output
(
jid
)
stdout
,
stderr
=
fslsub
.
output
(
jid
)
assert
stdout
.
strip
()
==
'
test_script running
'
assert
stdout
==
'
test_script running
\n
'
assert
stderr
.
strip
()
==
''
assert
stderr
==
''
kwargs
=
{
'
name
'
:
'
abcde
'
,
'
ram
'
:
'
4GB
'
}
kwargs
=
{
'
name
'
:
'
abcde
'
,
'
ram
'
:
'
4GB
'
}
...
@@ -201,7 +251,7 @@ def test_run_submit():
...
@@ -201,7 +251,7 @@ def test_run_submit():
stdout
,
stderr
=
fslsub
.
output
(
jid
)
stdout
,
stderr
=
fslsub
.
output
(
jid
)
experr
=
'
\n
'
.
join
([
'
{}: {}
'
.
format
(
k
,
kwargs
[
k
])
experr
=
'
\n
'
.
join
([
'
{}: {}
'
.
format
(
k
,
kwargs
[
k
])
for
k
in
sorted
(
kwargs
.
keys
())])
for
k
in
sorted
(
kwargs
.
keys
())])
+
'
\n
'
assert
stdout
.
strip
()
==
'
test_script running
'
assert
stdout
==
'
test_script running
\n
'
assert
stderr
.
strip
()
==
experr
assert
stderr
==
experr
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