|
1 |
| -import unittest |
2 | 1 | import re
|
3 | 2 | import os
|
4 | 3 | from os import linesep as n
|
5 | 4 | from os import sep as p
|
| 5 | +from pathlib import Path |
6 | 6 |
|
7 | 7 | from .util import run_with_mock_cwl_runner, get_data
|
8 | 8 | import defusedxml.ElementTree as ET
|
9 | 9 | import schema_salad.ref_resolver
|
10 | 10 |
|
11 | 11 |
|
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) |
14 | 25 |
|
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 |
28 | 48 |
|
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 |
| - ) |
54 | 49 |
|
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 |
70 | 76 |
|
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) |
81 | 77 |
|
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" |
0 commit comments