Skip to content

Commit d610d1f

Browse files
committed
maintenance: remove unittest from test_toolargparse
1 parent 522c69b commit d610d1f

File tree

1 file changed

+50
-51
lines changed

1 file changed

+50
-51
lines changed

tests/test_toolargparse.py

Lines changed: 50 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
1-
from __future__ import absolute_import
2-
3-
import unittest
1+
import os
42
from tempfile import NamedTemporaryFile
53

4+
import pytest
65
from cwltool.main import main
76

87
from .util import get_data, needs_docker
98

109

11-
class ToolArgparse(unittest.TestCase):
12-
script = '''
10+
script_a = '''
1311
#!/usr/bin/env cwl-runner
1412
cwlVersion: v1.0
1513
class: CommandLineTool
@@ -29,7 +27,7 @@ class ToolArgparse(unittest.TestCase):
2927
baseCommand: [cat]
3028
'''
3129

32-
script2 = '''
30+
script_b = '''
3331
#!/usr/bin/env cwl-runner
3432
cwlVersion: v1.0
3533
class: CommandLineTool
@@ -47,7 +45,7 @@ class ToolArgparse(unittest.TestCase):
4745
stdout: foo
4846
'''
4947

50-
script3 = '''
48+
script_c = '''
5149
#!/usr/bin/env cwl-runner
5250
5351
cwlVersion: v1.0
@@ -66,47 +64,48 @@ class ToolArgparse(unittest.TestCase):
6664
outputs: []
6765
'''
6866

69-
@needs_docker
70-
def test_help(self):
71-
with NamedTemporaryFile(mode='w', delete=False) as f:
72-
f.write(self.script)
73-
f.flush()
74-
f.close()
75-
self.assertEquals(main(["--debug", f.name, '--input',
76-
get_data('tests/echo.cwl')]), 0)
77-
78-
@needs_docker
79-
def test_bool(self):
80-
with NamedTemporaryFile(mode='w', delete=False) as f:
81-
f.write(self.script2)
82-
f.flush()
83-
f.close()
84-
try:
85-
self.assertEquals(main([f.name, '--help']), 0)
86-
except SystemExit as e:
87-
self.assertEquals(e.code, 0)
88-
89-
def test_record_help(self):
90-
with NamedTemporaryFile(mode='w', delete=False) as f:
91-
f.write(self.script3)
92-
f.flush()
93-
f.close()
94-
try:
95-
self.assertEquals(main([f.name, '--help']), 0)
96-
except SystemExit as e:
97-
self.assertEquals(e.code, 0)
98-
99-
def test_record(self):
100-
with NamedTemporaryFile(mode='w', delete=False) as f:
101-
f.write(self.script3)
102-
f.flush()
103-
f.close()
104-
try:
105-
self.assertEquals(main([f.name, '--foo.one',
106-
get_data('tests/echo.cwl'), '--foo.two', 'test']), 0)
107-
except SystemExit as e:
108-
self.assertEquals(e.code, 0)
109-
110-
111-
if __name__ == '__main__':
112-
unittest.main()
67+
scripts_argparse_params = [
68+
('help', script_a,
69+
lambda x: ["--debug", x, '--input', get_data('tests/echo.cwl')]
70+
),
71+
('boolean', script_b, lambda x: [x, '--help']
72+
),
73+
]
74+
75+
@needs_docker
76+
@pytest.mark.parametrize('name,script_contents,params', scripts_argparse_params)
77+
def test_argparse(name, script_contents, params):
78+
try:
79+
script = NamedTemporaryFile(mode='w', delete=False)
80+
script.write(script_contents)
81+
script.flush()
82+
script.close()
83+
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()
104+
105+
try:
106+
assert main(params(script.name)) == 0
107+
except SystemExit as err:
108+
assert err.code == 0
109+
finally:
110+
if os.path.exists(script.name):
111+
os.remove(script.name)

0 commit comments

Comments
 (0)