Skip to content

Commit 027e688

Browse files
committed
modernize tests
1 parent af69301 commit 027e688

File tree

5 files changed

+207
-227
lines changed

5 files changed

+207
-227
lines changed

cwltest/tests/test_argparse.py

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,13 @@
1-
import unittest
21
from cwltest import arg_parser
32

43

5-
class TestArgparse(unittest.TestCase):
6-
def setUp(self):
7-
self.parser = arg_parser()
8-
9-
def test_arg(self):
10-
parsed = self.parser.parse_args(
11-
["--test", "test_name", "-n", "52", "--tool", "cwltool", "-j", "4"]
12-
)
13-
self.assertEqual(parsed.test, "test_name")
14-
self.assertEqual(parsed.n, "52")
15-
self.assertEqual(parsed.tool, "cwltool")
16-
self.assertEqual(parsed.j, 4)
17-
18-
19-
if __name__ == "__main__":
20-
unittest.main()
4+
def test_arg():
5+
"""Basic test of the argparse."""
6+
parser = arg_parser()
7+
parsed = parser.parse_args(
8+
["--test", "test_name", "-n", "52", "--tool", "cwltool", "-j", "4"]
9+
)
10+
assert parsed.test == "test_name"
11+
assert parsed.n == "52"
12+
assert parsed.tool == "cwltool"
13+
assert parsed.j == 4

cwltest/tests/test_categories.py

Lines changed: 77 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,97 +1,92 @@
1-
import unittest
21
import re
32
import os
43
from os import linesep as n
54
from os import sep as p
5+
from pathlib import Path
66

77
from .util import run_with_mock_cwl_runner, get_data
88
import defusedxml.ElementTree as ET
99
import schema_salad.ref_resolver
1010

1111

12-
class TestCategories(unittest.TestCase):
13-
maxDiff = None
12+
def test_unsupported_with_required_tests():
13+
args = [
14+
"--test",
15+
schema_salad.ref_resolver.file_uri(
16+
get_data("tests/test-data/required-unsupported.yml")
17+
),
18+
]
19+
try:
20+
cwd = os.getcwd()
21+
os.chdir(get_data("tests/test-data/"))
22+
error_code, stdout, stderr = run_with_mock_cwl_runner(args)
23+
finally:
24+
os.chdir(cwd)
1425

15-
def test_unsupported_with_required_tests(self):
16-
args = [
17-
"--test",
18-
schema_salad.ref_resolver.file_uri(
19-
get_data("tests/test-data/required-unsupported.yml")
20-
),
21-
]
22-
try:
23-
cwd = os.getcwd()
24-
os.chdir(get_data("tests/test-data/"))
25-
error_code, stdout, stderr = run_with_mock_cwl_runner(args)
26-
finally:
27-
os.chdir(cwd)
26+
assert error_code == 1
27+
print(stderr)
28+
stderr = re.sub(r" '?--outdir=[^ ]*", "", stderr)
29+
if os.name == "nt":
30+
q = "'"
31+
else:
32+
q = ""
33+
assert (
34+
"Test [1/2] Required test that is unsupported (without tags){n}"
35+
"{n}"
36+
"Test 1 failed: mock-cwl-runner --quiet return-unsupported.cwl {q}v1.0{p}cat-job.json{q}{n}"
37+
"Required test that is unsupported (without tags){n}"
38+
"Does not support required feature{n}"
39+
"{n}"
40+
"Test [2/2] Required test that is unsupported (with tags){n}"
41+
"{n}"
42+
"Test 2 failed: mock-cwl-runner --quiet return-unsupported.cwl {q}v1.0{p}cat-job.json{q}{n}"
43+
"Required test that is unsupported (with tags){n}"
44+
"Does not support required feature{n}"
45+
"{n}"
46+
"0 tests passed, 2 failures, 0 unsupported features{n}".format(n=n, p=p, q=q)
47+
) == stderr
2848

29-
self.assertEqual(error_code, 1)
30-
print(stderr)
31-
stderr = re.sub(r" '?--outdir=[^ ]*", "", stderr)
32-
if os.name == "nt":
33-
q = "'"
34-
else:
35-
q = ""
36-
self.assertEqual(
37-
"Test [1/2] Required test that is unsupported (without tags){n}"
38-
"{n}"
39-
"Test 1 failed: mock-cwl-runner --quiet return-unsupported.cwl {q}v1.0{p}cat-job.json{q}{n}"
40-
"Required test that is unsupported (without tags){n}"
41-
"Does not support required feature{n}"
42-
"{n}"
43-
"Test [2/2] Required test that is unsupported (with tags){n}"
44-
"{n}"
45-
"Test 2 failed: mock-cwl-runner --quiet return-unsupported.cwl {q}v1.0{p}cat-job.json{q}{n}"
46-
"Required test that is unsupported (with tags){n}"
47-
"Does not support required feature{n}"
48-
"{n}"
49-
"0 tests passed, 2 failures, 0 unsupported features{n}".format(
50-
n=n, p=p, q=q
51-
),
52-
stderr,
53-
)
5449

55-
def test_unsupported_with_optional_tests(self):
56-
args = [
57-
"--test",
58-
schema_salad.ref_resolver.file_uri(
59-
get_data("tests/test-data/optional-unsupported.yml")
60-
),
61-
]
62-
error_code, stdout, stderr = run_with_mock_cwl_runner(args)
63-
self.assertEqual(error_code, 0)
64-
self.assertEqual(
65-
"Test [1/1] Optional test that is unsupported{n}{n}"
66-
"0 tests passed, 1 unsupported "
67-
"features{n}".format(n=n),
68-
stderr,
69-
)
50+
def test_unsupported_with_optional_tests():
51+
args = [
52+
"--test",
53+
schema_salad.ref_resolver.file_uri(
54+
get_data("tests/test-data/optional-unsupported.yml")
55+
),
56+
]
57+
error_code, stdout, stderr = run_with_mock_cwl_runner(args)
58+
assert error_code == 0
59+
assert (
60+
"Test [1/1] Optional test that is unsupported{n}{n}"
61+
"0 tests passed, 1 unsupported "
62+
"features{n}".format(n=n)
63+
) == stderr
64+
65+
66+
def test_error_with_optional_tests():
67+
args = [
68+
"--test",
69+
schema_salad.ref_resolver.file_uri(
70+
get_data("tests/test-data/optional-error.yml")
71+
),
72+
]
73+
error_code, stdout, stderr = run_with_mock_cwl_runner(args)
74+
assert error_code == 1
75+
assert "1 failures" in stderr
7076

71-
def test_error_with_optional_tests(self):
72-
args = [
73-
"--test",
74-
schema_salad.ref_resolver.file_uri(
75-
get_data("tests/test-data/optional-error.yml")
76-
),
77-
]
78-
error_code, stdout, stderr = run_with_mock_cwl_runner(args)
79-
self.assertEqual(error_code, 1)
80-
self.assertIn("1 failures", stderr)
8177

82-
def test_category_in_junit_xml(self):
83-
junit_xml_report = get_data("tests/test-data/junit-report.xml")
84-
args = [
85-
"--test",
86-
schema_salad.ref_resolver.file_uri(
87-
get_data("tests/test-data/optional-error.yml")
88-
),
89-
"--junit-xml",
90-
junit_xml_report,
91-
]
92-
run_with_mock_cwl_runner(args)
93-
tree = ET.parse(junit_xml_report)
94-
root = tree.getroot()
95-
category = root.find("testsuite").find("testcase").attrib["class"]
96-
self.assertEqual(category, "js, init_work_dir")
97-
os.remove(junit_xml_report)
78+
def test_category_in_junit_xml(tmp_path: Path):
79+
junit_xml_report = tmp_path / "junit-report.xml"
80+
args = [
81+
"--test",
82+
schema_salad.ref_resolver.file_uri(
83+
get_data("tests/test-data/optional-error.yml")
84+
),
85+
"--junit-xml",
86+
str(junit_xml_report),
87+
]
88+
run_with_mock_cwl_runner(args)
89+
tree = ET.parse(junit_xml_report)
90+
root = tree.getroot()
91+
category = root.find("testsuite").find("testcase").attrib["class"]
92+
assert category == "js, init_work_dir"

cwltest/tests/test_compare.py

Lines changed: 53 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,63 @@
1-
import unittest
21
from .util import get_data
32
from cwltest import CompareFail
43
from cwltest.utils import compare_file, compare
54

5+
import pytest
66

7-
class TestCompareFile(unittest.TestCase):
8-
def test_compare_file(self):
9-
expected = {
10-
"location": "cores.txt",
11-
"size": 2,
12-
"class": "File",
13-
"checksum": "sha1$7448d8798a4380162d4b56f9b452e2f6f9e24e7a",
14-
}
157

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-
try:
25-
compare_file(expected, actual)
26-
except CompareFail:
27-
self.fail("File comparison failed unexpectedly")
8+
def test_compare_file():
9+
expected = {
10+
"location": "cores.txt",
11+
"size": 2,
12+
"class": "File",
13+
"checksum": "sha1$7448d8798a4380162d4b56f9b452e2f6f9e24e7a",
14+
}
2815

29-
def test_compare_contents_success(self):
30-
expected = {
31-
"location": "cores.txt",
32-
"size": 2,
33-
"class": "File",
34-
"contents": "2\n",
35-
}
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+
compare_file(expected, actual)
3625

37-
actual = {
38-
"basename": "cores.txt",
39-
"checksum": "sha1$7448d8798a4380162d4b56f9b452e2f6f9e24e7a",
40-
"class": "File",
41-
"location": "file:///var/folders/8x/2df05_7j20j6r8y81w4qf43r0000gn/T/tmpG0EkrS/cores.txt",
42-
"path": get_data("tests/test-data/cores.txt"),
43-
"size": 2,
44-
}
45-
compare(expected, actual)
4626

47-
def test_compare_contents_failure(self):
48-
expected = {
49-
"location": "cores.txt",
50-
"size": 2,
51-
"class": "File",
52-
"contents": "2",
53-
}
27+
def test_compare_contents_success():
28+
expected = {
29+
"location": "cores.txt",
30+
"size": 2,
31+
"class": "File",
32+
"contents": "2\n",
33+
}
5434

55-
actual = {
56-
"basename": "cores.txt",
57-
"checksum": "sha1$7448d8798a4380162d4b56f9b452e2f6f9e24e7a",
58-
"class": "File",
59-
"location": "file:///var/folders/8x/2df05_7j20j6r8y81w4qf43r0000gn/T/tmpG0EkrS/cores.txt",
60-
"path": get_data("tests/test-data/cores.txt"),
61-
"size": 2,
62-
}
63-
with self.assertRaises(CompareFail):
64-
compare_file(expected, actual)
35+
actual = {
36+
"basename": "cores.txt",
37+
"checksum": "sha1$7448d8798a4380162d4b56f9b452e2f6f9e24e7a",
38+
"class": "File",
39+
"location": "file:///var/folders/8x/2df05_7j20j6r8y81w4qf43r0000gn/T/tmpG0EkrS/cores.txt",
40+
"path": get_data("tests/test-data/cores.txt"),
41+
"size": 2,
42+
}
43+
compare(expected, actual)
44+
45+
46+
def test_compare_contents_failure():
47+
expected = {
48+
"location": "cores.txt",
49+
"size": 2,
50+
"class": "File",
51+
"contents": "2",
52+
}
53+
54+
actual = {
55+
"basename": "cores.txt",
56+
"checksum": "sha1$7448d8798a4380162d4b56f9b452e2f6f9e24e7a",
57+
"class": "File",
58+
"location": "file:///var/folders/8x/2df05_7j20j6r8y81w4qf43r0000gn/T/tmpG0EkrS/cores.txt",
59+
"path": get_data("tests/test-data/cores.txt"),
60+
"size": 2,
61+
}
62+
with pytest.raises(CompareFail):
63+
compare_file(expected, actual)

cwltest/tests/test_prepare.py

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,26 @@
1+
"""Test prepare_test_command()"""
12
import os
2-
import unittest
33
from cwltest import prepare_test_command
44

55

6-
class TestPrepareCommand(unittest.TestCase):
7-
"""Test prepare_test_command()"""
8-
9-
def test_unix_relative_path(self):
10-
"""Confirm unix style to windows style path corrections."""
11-
command = prepare_test_command(
12-
tool="cwl-runner",
13-
args=[],
14-
testargs=None,
15-
test={
16-
"doc": "General test of command line generation",
17-
"output": {"args": ["echo"]},
18-
"tool": "v1.0/bwa-mem-tool.cwl",
19-
"job": "v1.0/bwa-mem-job.json",
20-
"tags": ["required"],
21-
},
22-
cwd=os.getcwd(),
23-
)
24-
if os.name == "nt":
25-
self.assertEqual(command[3], "v1.0\\bwa-mem-tool.cwl")
26-
self.assertEqual(command[4], "v1.0\\bwa-mem-job.json")
27-
else:
28-
self.assertEqual(command[3], "v1.0/bwa-mem-tool.cwl")
29-
self.assertEqual(command[4], "v1.0/bwa-mem-job.json")
6+
def test_unix_relative_path():
7+
"""Confirm unix style to windows style path corrections."""
8+
command = prepare_test_command(
9+
tool="cwl-runner",
10+
args=[],
11+
testargs=None,
12+
test={
13+
"doc": "General test of command line generation",
14+
"output": {"args": ["echo"]},
15+
"tool": "v1.0/bwa-mem-tool.cwl",
16+
"job": "v1.0/bwa-mem-job.json",
17+
"tags": ["required"],
18+
},
19+
cwd=os.getcwd(),
20+
)
21+
if os.name == "nt":
22+
assert command[3] == "v1.0\\bwa-mem-tool.cwl"
23+
assert command[4] == "v1.0\\bwa-mem-job.json"
24+
else:
25+
assert command[3] == "v1.0/bwa-mem-tool.cwl"
26+
assert command[4] == "v1.0/bwa-mem-job.json"

0 commit comments

Comments
 (0)