Skip to content

Commit 5099255

Browse files
authored
Revert "Trying revert for regression"
1 parent 068b301 commit 5099255

43 files changed

Lines changed: 13783 additions & 67 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Lib/test/test_unittest.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import unittest.test
2+
3+
from test import support
4+
5+
6+
def test_main():
7+
# used by regrtest
8+
support.run_unittest(unittest.test.suite())
9+
support.reap_children()
10+
11+
def load_tests(*_):
12+
# used by unittest
13+
return unittest.test.suite()
14+
15+
if __name__ == "__main__":
16+
test_main()

Lib/unittest/test/__init__.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import os
2+
import sys
3+
import unittest
4+
5+
6+
here = os.path.dirname(__file__)
7+
loader = unittest.defaultTestLoader
8+
9+
def suite():
10+
suite = unittest.TestSuite()
11+
for fn in os.listdir(here):
12+
if fn.startswith("test") and fn.endswith(".py"):
13+
modname = "unittest.test." + fn[:-3]
14+
__import__(modname)
15+
module = sys.modules[modname]
16+
suite.addTest(loader.loadTestsFromModule(module))
17+
suite.addTest(loader.loadTestsFromName('unittest.test.testmock'))
18+
return suite
19+
20+
21+
if __name__ == "__main__":
22+
unittest.main(defaultTest="suite")

Lib/unittest/test/__main__.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import os
2+
import unittest
3+
4+
5+
def load_tests(loader, standard_tests, pattern):
6+
# top level directory cached on loader instance
7+
this_dir = os.path.dirname(__file__)
8+
pattern = pattern or "test_*.py"
9+
# We are inside unittest.test, so the top-level is two notches up
10+
top_level_dir = os.path.dirname(os.path.dirname(this_dir))
11+
package_tests = loader.discover(start_dir=this_dir, pattern=pattern,
12+
top_level_dir=top_level_dir)
13+
standard_tests.addTests(package_tests)
14+
return standard_tests
15+
16+
17+
if __name__ == '__main__':
18+
unittest.main()
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# helper module for test_runner.Test_TextTestRunner.test_warnings
2+
3+
"""
4+
This module has a number of tests that raise different kinds of warnings.
5+
When the tests are run, the warnings are caught and their messages are printed
6+
to stdout. This module also accepts an arg that is then passed to
7+
unittest.main to affect the behavior of warnings.
8+
Test_TextTestRunner.test_warnings executes this script with different
9+
combinations of warnings args and -W flags and check that the output is correct.
10+
See #10535.
11+
"""
12+
13+
import sys
14+
import unittest
15+
import warnings
16+
17+
def warnfun():
18+
warnings.warn('rw', RuntimeWarning)
19+
20+
class TestWarnings(unittest.TestCase):
21+
# unittest warnings will be printed at most once per type (max one message
22+
# for the fail* methods, and one for the assert* methods)
23+
def test_assert(self):
24+
self.assertEquals(2+2, 4)
25+
self.assertEquals(2*2, 4)
26+
self.assertEquals(2**2, 4)
27+
28+
def test_fail(self):
29+
self.failUnless(1)
30+
self.failUnless(True)
31+
32+
def test_other_unittest(self):
33+
self.assertAlmostEqual(2+2, 4)
34+
self.assertNotAlmostEqual(4+4, 2)
35+
36+
# these warnings are normally silenced, but they are printed in unittest
37+
def test_deprecation(self):
38+
warnings.warn('dw', DeprecationWarning)
39+
warnings.warn('dw', DeprecationWarning)
40+
warnings.warn('dw', DeprecationWarning)
41+
42+
def test_import(self):
43+
warnings.warn('iw', ImportWarning)
44+
warnings.warn('iw', ImportWarning)
45+
warnings.warn('iw', ImportWarning)
46+
47+
# user warnings should always be printed
48+
def test_warning(self):
49+
warnings.warn('uw')
50+
warnings.warn('uw')
51+
warnings.warn('uw')
52+
53+
# these warnings come from the same place; they will be printed
54+
# only once by default or three times if the 'always' filter is used
55+
def test_function(self):
56+
57+
warnfun()
58+
warnfun()
59+
warnfun()
60+
61+
62+
63+
if __name__ == '__main__':
64+
with warnings.catch_warnings(record=True) as ws:
65+
# if an arg is provided pass it to unittest.main as 'warnings'
66+
if len(sys.argv) == 2:
67+
unittest.main(exit=False, warnings=sys.argv.pop())
68+
else:
69+
unittest.main(exit=False)
70+
71+
# print all the warning messages collected
72+
for w in ws:
73+
print(w.message)

Lib/unittest/test/dummy.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Empty module for testing the loading of modules

Lib/unittest/test/support.py

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

0 commit comments

Comments
 (0)