File: test_tojunit.py

package info (click to toggle)
junit2html 31.0.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 576 kB
  • sloc: xml: 3,208; python: 1,023; makefile: 6; sh: 5
file content (89 lines) | stat: -rw-r--r-- 2,491 bytes parent folder | download
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
"""
Tests for emitting junit xml
"""

from junit2htmlreport import parser, merge


def test_case_tojunit_failed():
    """
    Test coverting a failed case to xml
    :return:
    """
    testclass = parser.Class()
    testclass.name = "myclass"
    testcase = parser.Case()
    testcase.name = "mytest"
    testcase.testclass = testclass
    testcase.failure = "bad"
    testcase.failure_msg = "failed message"

    result = testcase.tojunit()
    children = list(result)
    assert len(children) == 1
    assert children[0].tag == "failure"
    assert children[0].text == "bad"
    assert children[0].get("message") == "failed message"


def test_case_tojunit():
    """
    Test converting a test case to a junit xml element
    :return:
    """
    testclass = parser.Class()
    testclass.name = "myclass"
    testcase = parser.Case()
    testcase.name = "mytest"
    testcase.testclass = testclass
    testcase.duration = 3.0
    testcase.stdout = "hello\nworld"
    testcase.stderr = "byee"
    testcase.skipped = "ignored"
    testcase.skipped_msg = "skipped message"

    result = testcase.tojunit()
    assert result.tag == "testcase"
    assert result.get("time") == "3.0"
    assert result.get("classname") == "myclass"
    assert result.get("name") == "mytest"
    children = list(result)
    assert len(children) == 3
    assert children[0].tag == "system-err"
    assert children[0].text == "byee"
    assert children[1].tag == "system-out"
    assert children[1].text == "hello\nworld"
    assert children[2].tag == "skipped"
    assert children[2].get("message") == "skipped message"
    assert children[2].text == "ignored"


def test_merge():
    """
    Test merging suites
    :return:
    """
    # make two suites, with two classes with each three cases
    suites = []
    for y in range(2):
        suite = parser.Suite()
        suites.append(suite)

        for x in range(2):
            testclass = parser.Class()
            testclass.name = "class.name{}_{}".format(y, x)
            suite.classes[testclass.name] = testclass
            for z in range(3):
                testcase = parser.Case()
                testcase.name = "testcase{}_{}_{}".format(y, x, z)
                testcase.testclass = testclass
                testclass.cases.append(testcase)
    merger = merge.Merger()
    for suite in suites:
        merger.add_suite(suite)

    result = merger.tojunit()
    assert result is not None

    output = merger.toxmlstring()
    assert output