-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathtest_junittools.py
51 lines (44 loc) · 1.86 KB
/
test_junittools.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# pylint: disable=missing-docstring,redefined-outer-name,no-self-use,protected-access
import os
from io import StringIO
import pytest
from dump2polarion.exceptions import Dump2PolarionException
from dump2polarion.results import junittools
from tests import conf
class TestJunitImport:
def test_import_orig_data(self):
junit_file = os.path.join(conf.DATA_PATH, "junit-report.xml")
data = junittools.import_junit(junit_file)
assert hasattr(data, "results")
assert len(data.results) == 7
passed_num = failed_num = skipped_num = 0
for result in data.results:
if result["verdict"] == "passed":
passed_num += 1
elif result["verdict"] == "failed":
assert result["comment"]
failed_num += 1
elif result["verdict"] == "skipped":
assert result["comment"]
skipped_num += 1
assert passed_num == 2
assert failed_num == 2
assert skipped_num == 3
assert hasattr(data, "testrun")
assert data.testrun is None
def test_invalid_input(self):
invalid_content = "foo"
input_file = StringIO(invalid_content)
with pytest.raises(Dump2PolarionException) as excinfo:
junittools.import_junit(input_file)
input_file.close()
assert "Failed to parse XML file" in str(excinfo.value)
def test_import_with_params(self):
junit_file = os.path.join(conf.DATA_PATH, "junit-report-params.xml")
data = junittools.import_junit(junit_file)
assert hasattr(data, "results")
assert len(data.results) == 2
assert list(data.results[0]["params"].keys()) == ["pkg"]
assert list(data.results[1]["params"].keys()) == ["api_ver", "package"]
assert data.results[0]["id"] == "foobar"
assert data.results[1]["id"] == "barbaz"