Skip to content

Commit 4da150b

Browse files
author
Anton Khodak
authored
Merge pull request #36 from kapilkd13/testsuite
Adding basic Testsuite to cwltest
2 parents d3f7cce + 05ef85b commit 4da150b

File tree

6 files changed

+86
-27
lines changed

6 files changed

+86
-27
lines changed

cwltest/__init__.py

Lines changed: 37 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
from concurrent.futures import ThreadPoolExecutor
2222
from six.moves import range
2323
from six.moves import zip
24-
from typing import Any, Dict, List
24+
from typing import Any, Dict, List, Text
2525

2626
from cwltest.utils import compare, CompareFail, TestResult
2727

@@ -40,6 +40,34 @@
4040
templock = threading.Lock()
4141

4242

43+
def prepare_test_command(args, i, tests):
44+
# type: (argparse.Namespace, int, List[Dict[str, str]]) -> List[str]
45+
t = tests[i]
46+
test_command = [args.tool]
47+
test_command.extend(args.args)
48+
49+
# Add additional arguments given in test case
50+
if args.testargs is not None:
51+
for testarg in args.testargs:
52+
(test_case_name, prefix) = testarg.split('==')
53+
if test_case_name in t:
54+
test_command.extend([prefix, t[test_case_name]])
55+
56+
# Add prefixes if running on MacOSX so that boot2docker writes to /Users
57+
with templock:
58+
if 'darwin' in sys.platform and args.tool == 'cwltool':
59+
outdir = tempfile.mkdtemp(prefix=os.path.abspath(os.path.curdir))
60+
test_command.extend(["--tmp-outdir-prefix={}".format(outdir), "--tmpdir-prefix={}".format(outdir)])
61+
else:
62+
outdir = tempfile.mkdtemp()
63+
test_command.extend(["--outdir={}".format(outdir),
64+
"--quiet",
65+
t["tool"]])
66+
if t.get("job"):
67+
test_command.append(t["job"])
68+
return test_command
69+
70+
4371
def run_test(args, i, tests, timeout):
4472
# type: (argparse.Namespace, int, List[Dict[str, str]], int) -> TestResult
4573

@@ -56,28 +84,7 @@ def run_test(args, i, tests, timeout):
5684
else:
5785
suffix = "\n"
5886
try:
59-
test_command = [args.tool]
60-
test_command.extend(args.args)
61-
62-
# Add additional arguments given in test case
63-
if args.testargs is not None:
64-
for testarg in args.testargs:
65-
(test_case_name, prefix) = testarg.split('==')
66-
if test_case_name in t:
67-
test_command.extend([prefix, t[test_case_name]])
68-
69-
# Add prefixes if running on MacOSX so that boot2docker writes to /Users
70-
with templock:
71-
if 'darwin' in sys.platform and args.tool == 'cwltool':
72-
outdir = tempfile.mkdtemp(prefix=os.path.abspath(os.path.curdir))
73-
test_command.extend(["--tmp-outdir-prefix={}".format(outdir), "--tmpdir-prefix={}".format(outdir)])
74-
else:
75-
outdir = tempfile.mkdtemp()
76-
test_command.extend(["--outdir={}".format(outdir),
77-
"--quiet",
78-
t["tool"]])
79-
if t.get("job"):
80-
test_command.append(t["job"])
87+
test_command = prepare_test_command(args, i, tests)
8188

8289
sys.stderr.write("%sTest [%i/%i] %s\n" % (prefix, i + 1, len(tests), suffix))
8390
sys.stderr.flush()
@@ -142,8 +149,7 @@ def run_test(args, i, tests, timeout):
142149
return TestResult((1 if fail_message else 0), outstr, outerr, duration, args.classname, fail_message)
143150

144151

145-
def main(): # type: () -> int
146-
152+
def arg_parser(): # type: () -> argparse.ArgumentParser
147153
parser = argparse.ArgumentParser(description='Compliance tests for cwltool')
148154
parser.add_argument("--test", type=str, help="YAML file describing test cases", required=True)
149155
parser.add_argument("--basedir", type=str, help="Basedir to use for tests", default=".")
@@ -164,8 +170,12 @@ def main(): # type: () -> int
164170
parser.add_argument("--timeout", type=int, default=DEFAULT_TIMEOUT, help="Time of execution in seconds after "
165171
"which the test will be skipped."
166172
"Defaults to 900 sec (15 minutes)")
173+
return parser
174+
175+
176+
def main(): # type: () -> int
167177

168-
args = parser.parse_args()
178+
args = arg_parser().parse_args(sys.argv[1:])
169179
if '--' in args.args:
170180
args.args.remove('--')
171181

@@ -174,7 +184,7 @@ def main(): # type: () -> int
174184
args.testargs = [testarg for testarg in args.testargs if testarg.count('==') == 1]
175185

176186
if not args.test:
177-
parser.print_help()
187+
arg_parser().print_help()
178188
return 1
179189

180190
with open(args.test) as f:

mypy.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1+
[mypy]
2+
13
[mypy-ruamel.*]
24
ignore_errors = True

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
license='Apache 2.0',
4040
packages=["cwltest"],
4141
install_requires=install_requires,
42+
test_suite='tests',
4243
tests_require=[],
4344
entry_points={
4445
'console_scripts': ["cwltest=cwltest:main"]

tests/__init__.py

Whitespace-only changes.

tests/test_argparse.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import unittest
2+
from cwltest import arg_parser
3+
4+
class TestArgparse(unittest.TestCase):
5+
def setUp(self):
6+
self.parser = arg_parser()
7+
8+
def test_arg(self):
9+
parsed = self.parser.parse_args(['--test', 'test_name','-n','52','--tool','cwltool','-j','4'])
10+
self.assertEqual(parsed.test, 'test_name')
11+
self.assertEqual(parsed.n, '52')
12+
self.assertEqual(parsed.tool, 'cwltool')
13+
self.assertEqual(parsed.j, 4)
14+
15+
16+
if __name__ == '__main__':
17+
unittest.main()
18+

tests/test_compare.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import unittest
2+
from cwltest import CompareFail
3+
from cwltest.utils import compare_file
4+
5+
6+
class TestCompareFile(unittest.TestCase):
7+
8+
def test_general(self):
9+
expected = {
10+
"location": "cores.txt",
11+
"size": 2,
12+
"class": "File",
13+
"checksum": "sha1$7448d8798a4380162d4b56f9b452e2f6f9e24e7a"
14+
}
15+
16+
actual = {
17+
"basename": "cores.txt",
18+
"checksum": "sha1$7448d8798a4380162d4b56f9b452e2f6f9e24e7a",
19+
"class": "File",
20+
"location": "file:///var/folders/8x/2df05_7j20j6r8y81w4qf43r0000gn/T/tmpG0EkrS/cores.txt",
21+
"path": "/var/folders/8x/2df05_7j20j6r8y81w4qf43r0000gn/T/tmpG0EkrS/cores.txt",
22+
"size": 2
23+
}
24+
25+
try:
26+
compare_file(expected, actual)
27+
except CompareFail:
28+
self.fail("File comparison failed unexpectedly")

0 commit comments

Comments
 (0)