Skip to content

Commit 05dcdbd

Browse files
author
Anton Khodak
committed
Add tests for short names & use junit_xml file attribute
* instead of non-existent `short_name` attribute
1 parent 1931956 commit 05dcdbd

File tree

7 files changed

+63
-167
lines changed

7 files changed

+63
-167
lines changed

cwltest/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
from six.moves import zip
2323
from typing import Any, Dict, List
2424

25-
import cwltest.cwl_junit_xml as cwl_junit_xml
25+
import junit_xml
2626
from cwltest.utils import compare, CompareFail, TestResult, REQUIRED, get_test_number_by_key
2727

2828
_logger = logging.getLogger("cwltest")
@@ -198,7 +198,7 @@ def main(): # type: () -> int
198198
unsupported = 0
199199
passed = 0
200200
suite_name, _ = os.path.splitext(os.path.basename(args.test))
201-
report = cwl_junit_xml.CWLTestSuite(suite_name, [])
201+
report = junit_xml.TestSuite(suite_name, [])
202202

203203
if args.only_tools:
204204
alltests = tests
@@ -267,7 +267,7 @@ def main(): # type: () -> int
267267

268268
if args.junit_xml:
269269
with open(args.junit_xml, 'w') as fp:
270-
cwl_junit_xml.CWLTestSuite.to_file(fp, [report])
270+
junit_xml.TestSuite.to_file(fp, [report])
271271

272272
if failures == 0 and unsupported == 0:
273273
_logger.info("All tests passed")

cwltest/cwl_junit_xml.py

Lines changed: 0 additions & 157 deletions
This file was deleted.

cwltest/utils.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
from six.moves import range
44
from typing import Any, Dict, Set, Text, List, Optional
55

6-
from cwltest import cwl_junit_xml
7-
6+
import junit_xml
87
REQUIRED = "required"
98

109

@@ -22,15 +21,15 @@ def __init__(self, return_code, standard_output, error_output, duration, classna
2221
self.classname = classname
2322

2423
def create_test_case(self, test):
25-
# type: (Dict[Text, Any]) -> cwl_junit_xml.TestCase
24+
# type: (Dict[Text, Any]) -> junit_xml.TestCase
2625
doc = test.get(u'doc', 'N/A').strip()
2726
if test.get("tags"):
2827
category = ", ".join(test['tags'])
2928
else:
3029
category = REQUIRED
3130
short_name = test.get(u'short_name')
32-
case = cwl_junit_xml.TestCase(
33-
doc, elapsed_sec=self.duration, short_name=short_name,
31+
case = junit_xml.TestCase(
32+
doc, elapsed_sec=self.duration, file=short_name,
3433
category=category, stdout=self.standard_output, stderr=self.error_output,
3534
)
3635
if self.return_code > 0:

tests/test-data/short-names.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
- job: v1.0/cat-job.json
2+
output: {}
3+
tool: return-0.cwl
4+
doc: Test with a short name
5+
short_name: opt-error
6+
tags: [ js, init_work_dir ]
7+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
- job: v1.0/cat1-job.json
2+
output: {}
3+
tool: return-0.cwl
4+
doc: Test without a short name
5+
- job: v1.0/cat2-job.json
6+
output: {}
7+
tool: return-0.cwl
8+
doc: Test with a short name
9+
short_name: opt-error

tests/test_categories.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,15 @@ def test_unsupported_with_required_tests(self):
1212
args = ["--test", get_data("tests/test-data/required-unsupported.yml")]
1313
error_code, stdout, stderr = run_with_mock_cwl_runner(args)
1414
self.assertEquals(error_code, 1)
15-
self.assertEquals("Test [1/2] \n\nTest [2/2] \n\n"
15+
self.assertEquals("Test [1/2] Required test that is unsupported (without tags)\n\n"
16+
"Test [2/2] Required test that is unsupported (with tags)\n\n"
1617
"0 tests passed, 2 failures, 0 unsupported features\n", stderr)
1718

1819
def test_unsupported_with_optional_tests(self):
1920
args = ["--test", get_data("tests/test-data/optional-unsupported.yml")]
2021
error_code, stdout, stderr = run_with_mock_cwl_runner(args)
2122
self.assertEquals(error_code, 0)
22-
self.assertEquals("Test [1/1] \n\n"
23+
self.assertEquals("Test [1/1] Optional test that is unsupported\n\n"
2324
"0 tests passed, 1 unsupported features\n", stderr)
2425

2526
def test_error_with_optional_tests(self):

tests/test_short_names.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import unittest
2+
3+
import os
4+
5+
from .util import run_with_mock_cwl_runner, get_data
6+
import xml.etree.ElementTree as ET
7+
8+
9+
class TestShortNames(unittest.TestCase):
10+
11+
def test_stderr_output(self):
12+
args = ["--test", get_data("tests/test-data/short-names.yml")]
13+
error_code, stdout, stderr = run_with_mock_cwl_runner(args)
14+
self.assertIn("Test [1/1] opt-error: Test with a short name\n", stderr)
15+
16+
def test_run_by_short_name(self):
17+
short_name = "opt-error"
18+
args = ["--test", get_data("tests/test-data/with-and-without-short-names.yml"), "-s", short_name]
19+
error_code, stdout, stderr = run_with_mock_cwl_runner(args)
20+
self.assertIn("Test [2/2] opt-error: Test with a short name", stderr)
21+
self.assertNotIn("Test [1/2]", stderr)
22+
23+
def test_list_tests(self):
24+
args = ["--test", get_data("tests/test-data/with-and-without-short-names.yml"), "-l"]
25+
error_code, stdout, stderr = run_with_mock_cwl_runner(args)
26+
self.assertEquals("[1] Test without a short name\n"
27+
"[2] opt-error: Test with a short name\n", stdout)
28+
29+
def test_short_name_in_junit_xml(self):
30+
junit_xml_report = get_data("tests/test-data/junit-report.xml")
31+
args = ["--test", get_data("tests/test-data/short-names.yml"), "--junit-xml", junit_xml_report]
32+
run_with_mock_cwl_runner(args)
33+
tree = ET.parse(junit_xml_report)
34+
root = tree.getroot()
35+
category = root.find("testsuite").find("testcase").attrib['file']
36+
self.assertEquals(category, "opt-error")
37+
os.remove(junit_xml_report)

0 commit comments

Comments
 (0)