Skip to content

Commit 15473bf

Browse files
authored
Merge pull request #941 from psafont/empty-input
Test against errors on empty input from stdin
2 parents 592a7e6 + 55246e9 commit 15473bf

File tree

4 files changed

+41
-26
lines changed

4 files changed

+41
-26
lines changed

tests/test_empty_input.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
try:
2+
from cStringIO import StringIO
3+
except ImportError:
4+
from io import StringIO
5+
6+
from cwltool.main import main
7+
from .util import get_data, temp_dir, windows_needs_docker
8+
9+
@windows_needs_docker
10+
def test_empty_input():
11+
empty_json = '{}'
12+
empty_input = StringIO(empty_json)
13+
14+
with temp_dir() as tmpdir:
15+
params = ['--outdir', tmpdir, get_data('tests/wf/no-parameters-echo.cwl'), '-']
16+
17+
try:
18+
assert main(params, stdin=empty_input) == 0
19+
except SystemExit as err:
20+
assert err.code == 0

tests/test_toolargparse.py

Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@
7070
),
7171
('boolean', script_b, lambda x: [x, '--help']
7272
),
73+
('help with c', script_c, lambda x: [x, '--help']),
74+
('foo with c', script_c,
75+
lambda x: [x, '--foo.one', get_data('tests/echo.cwl'), '--foo.two', 'test']
76+
)
7377
]
7478

7579
@needs_docker
@@ -78,34 +82,12 @@ def test_argparse(name, script_contents, params):
7882
try:
7983
script = NamedTemporaryFile(mode='w', delete=False)
8084
script.write(script_contents)
81-
script.flush()
8285
script.close()
8386

84-
try:
85-
assert main(params(script.name)) == 0, name
86-
except SystemExit as err:
87-
assert err.code == 0, name
88-
finally:
89-
if os.path.exists(script.name):
90-
os.remove(script.name)
91-
92-
script_c_params = [
93-
(lambda x: [x, '--help']),
94-
(lambda x: [x, '--foo.one', get_data('tests/echo.cwl'), '--foo.two', 'test'])
95-
]
96-
97-
@pytest.mark.parametrize('params', script_c_params)
98-
def test_argparse_record(params):
99-
try:
100-
script = NamedTemporaryFile(mode='w', delete=False)
101-
script.write(script_c)
102-
script.flush()
103-
script.close()
87+
assert main(params(script.name)) == 0, name
10488

105-
try:
106-
assert main(params(script.name)) == 0
107-
except SystemExit as err:
108-
assert err.code == 0
89+
except SystemExit as err:
90+
assert err.code == 0, name
10991
finally:
11092
if os.path.exists(script.name):
111-
os.remove(script.name)
93+
os.unlink(script.name)

tests/util.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import shutil
88
import contextlib
99
import tempfile
10+
import shutil
1011
from typing import Text
1112

1213
from pkg_resources import (Requirement, ResolutionError, # type: ignore

tests/wf/no-parameters-echo.cwl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/usr/bin/env cwl-runner
2+
cwlVersion: v1.0
3+
class: CommandLineTool
4+
doc: "This is a tool that can be launched without parameters"
5+
baseCommand: [echo]
6+
inputs:
7+
in:
8+
type: string
9+
default: "foo"
10+
outputs:
11+
e_out:
12+
type: stdout

0 commit comments

Comments
 (0)