File: test_python.py

package info (click to toggle)
kcov 43%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 1,600 kB
  • sloc: cpp: 12,617; ansic: 2,379; python: 2,001; sh: 333; makefile: 133; javascript: 65; xml: 7; asm: 4
file content (192 lines) | stat: -rw-r--r-- 5,955 bytes parent folder | download | duplicates (3)
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
import shutil
import unittest

import libkcov
from libkcov import cobertura

skip_python2 = shutil.which("python2") is None


class python_exit_status(libkcov.TestCase):
    def runTest(self):
        noKcovRv, o = self.doCmd(self.sources + "/tests/python/main 5")
        rv, o = self.do(
            self.kcov + " " + self.outbase + "/kcov " + self.sources + "/tests/python/main 5"
        )

        assert rv == noKcovRv


class python_can_set_illegal_parser(libkcov.TestCase):
    def runTest(self):
        rv, o = self.do(
            self.kcov
            + " --python-parser=python7 "
            + self.outbase
            + "/kcov "
            + self.sources
            + "/tests/python/main 5"
        )

        assert b"Cannot find Python parser 'python7'" in o


class python_can_set_legal_parser(libkcov.TestCase):
    def runTest(self):
        rv, o = self.do(
            self.kcov
            + " --python-parser=python3 "
            + self.outbase
            + "/kcov "
            + self.sources
            + "/tests/python/main 5"
        )

        assert b"Cannot find Python parser 'python3'" not in o


class python2_can_set_legal_parser(libkcov.TestCase):
    @unittest.skipIf(skip_python2, "python2 not available")
    def runTest(self):
        rv, o = self.do(
            self.kcov
            + " --python-parser=python2 "
            + self.outbase
            + "/kcov "
            + self.sources
            + "/tests/python/main 5"
        )

        assert b"Cannot find Python parser 'python2'" not in o


class python_issue_368_can_handle_symlink_target(libkcov.TestCase):
    def runTest(self):
        rv, o = self.do(
            self.kcov
            + " --python-parser=python3 "
            + self.outbase
            + "/kcov "
            + self.sources
            + "/tests/python/link_main 5 --foo"
        )

        assert b"unrecognized option '--foo'" not in o


class python_unittest(libkcov.TestCase):
    def runTest(self):
        rv, o = self.do(
            self.kcov
            + " "
            + self.outbase
            + "/kcov "
            + self.sources
            + "/tests/python/unittest/testdriver"
        )

        dom = cobertura.parseFile(self.outbase + "/kcov/testdriver/cobertura.xml")
        assert cobertura.hitsPerLine(dom, "testdriver", 14) == 1


class PythonBase(libkcov.TestCase):
    def doTest(self, extra):
        rv, o = self.do(
            self.kcov
            + " "
            + extra
            + " "
            + self.outbase
            + "/kcov "
            + self.sources
            + "/tests/python/main 5"
        )

        dom = cobertura.parseFile(self.outbase + "/kcov/main/cobertura.xml")
        assert cobertura.hitsPerLine(dom, "main", 10) == 2
        assert cobertura.hitsPerLine(dom, "main", 17) == 0
        assert cobertura.hitsPerLine(dom, "main", 22) is None
        assert cobertura.hitsPerLine(dom, "second.py", 2) == 1
        assert cobertura.hitsPerLine(dom, "second.py", 4) is None
        assert cobertura.hitsPerLine(dom, "second.py", 11) is None
        assert cobertura.hitsPerLine(dom, "second.py", 31) == 0
        assert cobertura.hitsPerLine(dom, "second.py", 38) == 1
        assert cobertura.hitsPerLine(dom, "second.py", 39) == 0
        assert cobertura.hitsPerLine(dom, "second.py", 40) is None
        assert cobertura.hitsPerLine(dom, "second.py", 41) == 1
        assert cobertura.hitsPerLine(dom, "second.py", 56) is None
        assert cobertura.hitsPerLine(dom, "second.py", 60) is None
        assert cobertura.hitsPerLine(dom, "second.py", 65) is None
        assert cobertura.hitsPerLine(dom, "second.py", 77) is None


class python_coverage(PythonBase):
    def runTest(self):
        self.doTest("")


class python_accumulate_data(libkcov.TestCase):
    def runTest(self):
        rv, o = self.do(
            self.kcov + " " + self.outbase + "/kcov " + self.sources + "/tests/python/main 5"
        )

        dom = cobertura.parseFile(self.outbase + "/kcov/main/cobertura.xml")
        assert cobertura.hitsPerLine(dom, "main", 16) == 0
        assert cobertura.hitsPerLine(dom, "main", 19) == 1
        rv, o = self.do(
            self.kcov + " " + self.outbase + "/kcov " + self.sources + "/tests/python/main"
        )

        dom = cobertura.parseFile(self.outbase + "/kcov/main/cobertura.xml")
        assert cobertura.hitsPerLine(dom, "main", 16) == 1
        assert cobertura.hitsPerLine(dom, "main", 19) == 1


class python3_coverage(PythonBase):
    def runTest(self):
        self.doTest("--python-parser=python3")


class python2_coverage(PythonBase):
    @unittest.skipIf(skip_python2, "python2 not available")
    def runTest(self):
        self.doTest("--python-parser=python2")


class python_tricky_single_line_string_assignment(libkcov.TestCase):
    def runTest(self):
        rv, o = self.do(
            self.kcov + " " + self.outbase + "/kcov " + self.sources + "/tests/python/main 5"
        )

        dom = cobertura.parseFile(self.outbase + "/kcov/main/cobertura.xml")
        assert cobertura.hitsPerLine(dom, "second.py", 34) == 2


class python_select_parser(libkcov.TestCase):
    def disabledTest(self):
        rv, o = self.do(
            self.kcov
            + " --python-parser="
            + self.sources
            + "/tests/tools/dummy-python.sh "
            + self.outbase
            + "/kcov "
            + self.sources
            + "/tests/python/main 5"
        )

        assert rv == 99


class python_tricky_single_dict_assignment(libkcov.TestCase):
    @unittest.expectedFailure
    def runTest(self):
        rv, o = self.do(
            self.kcov + " " + self.outbase + "/kcov " + self.sources + "/tests/python/main 5"
        )

        dom = cobertura.parseFile(self.outbase + "/kcov/main/cobertura.xml")
        assert cobertura.hitsPerLine(dom, "second.py", 57) == 1
        assert cobertura.hitsPerLine(dom, "second.py", 61) == 1