ยปCore Development>Code coverage>Lib/unittest/test/support.py

Python code coverage for Lib/unittest/test/support.py

#countcontent
1n/aimport unittest
2n/a
3n/a
4n/aclass TestEquality(object):
5n/a """Used as a mixin for TestCase"""
6n/a
7n/a # Check for a valid __eq__ implementation
8n/a def test_eq(self):
9n/a for obj_1, obj_2 in self.eq_pairs:
10n/a self.assertEqual(obj_1, obj_2)
11n/a self.assertEqual(obj_2, obj_1)
12n/a
13n/a # Check for a valid __ne__ implementation
14n/a def test_ne(self):
15n/a for obj_1, obj_2 in self.ne_pairs:
16n/a self.assertNotEqual(obj_1, obj_2)
17n/a self.assertNotEqual(obj_2, obj_1)
18n/a
19n/aclass TestHashing(object):
20n/a """Used as a mixin for TestCase"""
21n/a
22n/a # Check for a valid __hash__ implementation
23n/a def test_hash(self):
24n/a for obj_1, obj_2 in self.eq_pairs:
25n/a try:
26n/a if not hash(obj_1) == hash(obj_2):
27n/a self.fail("%r and %r do not hash equal" % (obj_1, obj_2))
28n/a except Exception as e:
29n/a self.fail("Problem hashing %r and %r: %s" % (obj_1, obj_2, e))
30n/a
31n/a for obj_1, obj_2 in self.ne_pairs:
32n/a try:
33n/a if hash(obj_1) == hash(obj_2):
34n/a self.fail("%s and %s hash equal, but shouldn't" %
35n/a (obj_1, obj_2))
36n/a except Exception as e:
37n/a self.fail("Problem hashing %s and %s: %s" % (obj_1, obj_2, e))
38n/a
39n/a
40n/aclass _BaseLoggingResult(unittest.TestResult):
41n/a def __init__(self, log):
42n/a self._events = log
43n/a super().__init__()
44n/a
45n/a def startTest(self, test):
46n/a self._events.append('startTest')
47n/a super().startTest(test)
48n/a
49n/a def startTestRun(self):
50n/a self._events.append('startTestRun')
51n/a super().startTestRun()
52n/a
53n/a def stopTest(self, test):
54n/a self._events.append('stopTest')
55n/a super().stopTest(test)
56n/a
57n/a def stopTestRun(self):
58n/a self._events.append('stopTestRun')
59n/a super().stopTestRun()
60n/a
61n/a def addFailure(self, *args):
62n/a self._events.append('addFailure')
63n/a super().addFailure(*args)
64n/a
65n/a def addSuccess(self, *args):
66n/a self._events.append('addSuccess')
67n/a super().addSuccess(*args)
68n/a
69n/a def addError(self, *args):
70n/a self._events.append('addError')
71n/a super().addError(*args)
72n/a
73n/a def addSkip(self, *args):
74n/a self._events.append('addSkip')
75n/a super().addSkip(*args)
76n/a
77n/a def addExpectedFailure(self, *args):
78n/a self._events.append('addExpectedFailure')
79n/a super().addExpectedFailure(*args)
80n/a
81n/a def addUnexpectedSuccess(self, *args):
82n/a self._events.append('addUnexpectedSuccess')
83n/a super().addUnexpectedSuccess(*args)
84n/a
85n/a
86n/aclass LegacyLoggingResult(_BaseLoggingResult):
87n/a """
88n/a A legacy TestResult implementation, without an addSubTest method,
89n/a which records its method calls.
90n/a """
91n/a
92n/a @property
93n/a def addSubTest(self):
94n/a raise AttributeError
95n/a
96n/a
97n/aclass LoggingResult(_BaseLoggingResult):
98n/a """
99n/a A TestResult implementation which records its method calls.
100n/a """
101n/a
102n/a def addSubTest(self, test, subtest, err):
103n/a if err is None:
104n/a self._events.append('addSubTestSuccess')
105n/a else:
106n/a self._events.append('addSubTestFailure')
107n/a super().addSubTest(test, subtest, err)
108n/a
109n/a
110n/aclass ResultWithNoStartTestRunStopTestRun(object):
111n/a """An object honouring TestResult before startTestRun/stopTestRun."""
112n/a
113n/a def __init__(self):
114n/a self.failures = []
115n/a self.errors = []
116n/a self.testsRun = 0
117n/a self.skipped = []
118n/a self.expectedFailures = []
119n/a self.unexpectedSuccesses = []
120n/a self.shouldStop = False
121n/a
122n/a def startTest(self, test):
123n/a pass
124n/a
125n/a def stopTest(self, test):
126n/a pass
127n/a
128n/a def addError(self, test):
129n/a pass
130n/a
131n/a def addFailure(self, test):
132n/a pass
133n/a
134n/a def addSuccess(self, test):
135n/a pass
136n/a
137n/a def wasSuccessful(self):
138n/a return True