-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtappy.py
73 lines (52 loc) · 2.59 KB
/
tappy.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
"""
TAP producer for Python unittest framework
---
Copyright (c) 2011 Chris Packham
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License version 2 as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
import unittest
import sys
class TapTestResult(unittest.TestResult):
"""A test result class that produces TAP compliant output."""
def __init__(self, stream, descriptions, verbosity):
super(TapTestResult, self).__init__()
self.stream = stream
def startTest(self, test):
super(TapTestResult, self).startTest(test)
def addSuccess(self, test):
super(TapTestResult, self).addSuccess(test)
self.stream.write("ok %d - %s\n" % (self.testsRun, str(test)))
def addFailure(self, test):
super(TapTestResult, self).addFailure(test)
self.stream.write("not ok - %d %s\n" % (self.testsRun, str(test)))
def addError(self, test):
super(TapTestResult, self).addError(test)
self.stream.write("not ok %d - %s # ERROR\n" % (self.testsRun, str(test)))
def addExpectedFailure(self, test, err):
super(TapTestResult, self).addExpectedFailure(test, err)
self.stream.write("not ok %d - %s # TODO known breakage\n" % (self.testsRun, str(test)))
def addUnexpectedSuccess(self, test):
super(TapTestResult, self).addUnexpectedSuccess(test)
self.stream.write("ok %d - %s # TODO known breakage\n" % (self.testsRun, str(test)))
def addSkip(self, test, reason):
super(TapTestResult, self).addSkip(test, reason)
self.stream.write("ok %d - %s # skip %s\n" % (self.testsRun, str(test), reason))
class TapTestRunner(unittest.TextTestRunner):
"""A test runner class that produces TAP compliant output."""
resultclass = TapTestResult
def __init__(self, stream=sys.stderr, descriptions=True, verbosity=1):
super(TapTestRunner, self).__init__(stream, descriptions, verbosity)
def _makeResult(self):
return self.resultclass(self.stream, self.descriptions, self.verbosity)
def run(self, test):
self.stream.write("TAP version 13\n")
self.stream.write("1..%d\n" % test.countTestCases())
return super(TapTestRunner, self).run(test)