mirror of
https://github.com/python/cpython.git
synced 2026-01-04 14:32:21 +00:00
Change the PyUnit-based tests to use the test_main() approach. This
allows using the tests with unittest.py as a script. The tests will still run when run as a script themselves.
This commit is contained in:
parent
6f7993765a
commit
2e2be3760c
34 changed files with 229 additions and 39 deletions
|
|
@ -42,4 +42,9 @@ def test_binhex(self):
|
|||
self.assertEqual(self.DATA, finish)
|
||||
|
||||
|
||||
test_support.run_unittest(BinHexTestCase)
|
||||
def test_main():
|
||||
test_support.run_unittest(BinHexTestCase)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_main()
|
||||
|
|
|
|||
|
|
@ -320,4 +320,9 @@ def test_future_div(self):
|
|||
self.assertEqual(eval('1/2'), 0.5)
|
||||
"""
|
||||
|
||||
test_support.run_unittest(RatTestCase)
|
||||
def test_main():
|
||||
test_support.run_unittest(RatTestCase)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_main()
|
||||
|
|
|
|||
|
|
@ -122,4 +122,10 @@ def test_oldargs1_1_kw(self):
|
|||
def test_oldargs1_2_kw(self):
|
||||
self.assertRaises(TypeError, {}.update, x=2, y=2)
|
||||
|
||||
run_unittest(CFunctionCalls)
|
||||
|
||||
def test_main():
|
||||
run_unittest(CFunctionCalls)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_main()
|
||||
|
|
|
|||
|
|
@ -22,4 +22,10 @@ def test_only_one_bom(self):
|
|||
f = reader(s)
|
||||
self.assertEquals(f.read(), u"spamspam")
|
||||
|
||||
test_support.run_unittest(UTF16Test)
|
||||
|
||||
def test_main():
|
||||
test_support.run_unittest(UTF16Test)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_main()
|
||||
|
|
|
|||
|
|
@ -87,4 +87,10 @@ def test_filename(self):
|
|||
self.assertNotEquals(compile_command("a = 1\n", "abc").co_filename,
|
||||
compile("a = 1\n", "def", 'single').co_filename)
|
||||
|
||||
run_unittest(CodeopTests)
|
||||
|
||||
def test_main():
|
||||
run_unittest(CodeopTests)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_main()
|
||||
|
|
|
|||
|
|
@ -42,4 +42,10 @@ def test_getstatus(self):
|
|||
|
||||
self.assert_(re.match(pat, getstatus("/bin/ls"), re.VERBOSE))
|
||||
|
||||
run_unittest(CommandTests)
|
||||
|
||||
def test_main():
|
||||
run_unittest(CommandTests)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_main()
|
||||
|
|
|
|||
|
|
@ -22,4 +22,9 @@ def test_noncallable_constructor(self):
|
|||
type(1), int, "not a callable")
|
||||
|
||||
|
||||
test_support.run_unittest(CopyRegTestCase)
|
||||
def test_main():
|
||||
test_support.run_unittest(CopyRegTestCase)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_main()
|
||||
|
|
|
|||
|
|
@ -65,4 +65,10 @@ def test_annotate(self):
|
|||
dircache.annotate(self.tempdir, lst)
|
||||
self.assertEquals(lst, ['A/', 'test2', 'test_nonexistent'])
|
||||
|
||||
run_unittest(DircacheTests)
|
||||
|
||||
def test_main():
|
||||
run_unittest(DircacheTests)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_main()
|
||||
|
|
|
|||
|
|
@ -53,4 +53,9 @@ def test_splitdrive(self):
|
|||
self.assertEquals(splitdrive("c:"), ('c:', ''))
|
||||
|
||||
|
||||
test_support.run_unittest(DOSPathTestCase)
|
||||
def test_main():
|
||||
test_support.run_unittest(DOSPathTestCase)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_main()
|
||||
|
|
|
|||
|
|
@ -38,4 +38,9 @@ def test_fnmatch(self):
|
|||
check('\\', r'[!\]', 0)
|
||||
|
||||
|
||||
test_support.run_unittest(FnmatchTestCase)
|
||||
def test_main():
|
||||
test_support.run_unittest(FnmatchTestCase)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_main()
|
||||
|
|
|
|||
|
|
@ -66,4 +66,10 @@ def test_failing_values(self):
|
|||
else:
|
||||
self.fail("No exception on non-numeric sci")
|
||||
|
||||
run_unittest(FpformatTest)
|
||||
|
||||
def test_main():
|
||||
run_unittest(FpformatTest)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_main()
|
||||
|
|
|
|||
|
|
@ -106,4 +106,10 @@ def test_glob_directory_names(self):
|
|||
eq(self.glob('?a?', '*F'), map(self.norm, [os.path.join('aaa', 'zzzF'),
|
||||
os.path.join('aab', 'F')]))
|
||||
|
||||
run_unittest(GlobTests)
|
||||
|
||||
def test_main():
|
||||
run_unittest(GlobTests)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_main()
|
||||
|
|
|
|||
|
|
@ -19,4 +19,9 @@ def test_getgrnam(self):
|
|||
entry = grp.getgrnam(self.groups[0][0])
|
||||
|
||||
|
||||
test_support.run_unittest(GroupDatabaseTestCase)
|
||||
def test_main():
|
||||
test_support.run_unittest(GroupDatabaseTestCase)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_main()
|
||||
|
|
|
|||
|
|
@ -28,4 +28,9 @@ def test_coerced_floats(self):
|
|||
self.same_hash(float(0.5), complex(0.5, 0.0))
|
||||
|
||||
|
||||
test_support.run_unittest(HashEqualityTestCase)
|
||||
def test_main():
|
||||
test_support.run_unittest(HashEqualityTestCase)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_main()
|
||||
|
|
|
|||
|
|
@ -694,4 +694,10 @@ def test_unpack_iter(self):
|
|||
(a, b), (c,) = IteratingSequenceClass(2), {42: 24}
|
||||
self.assertEqual((a, b, c), (0, 1, 42))
|
||||
|
||||
run_unittest(TestCase)
|
||||
|
||||
def test_main():
|
||||
run_unittest(TestCase)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_main()
|
||||
|
|
|
|||
|
|
@ -96,4 +96,9 @@ def test_nonempty_maildir_both(self):
|
|||
# XXX We still need more tests!
|
||||
|
||||
|
||||
test_support.run_unittest(MaildirTestCase)
|
||||
def test_main():
|
||||
test_support.run_unittest(MaildirTestCase)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_main()
|
||||
|
|
|
|||
|
|
@ -331,4 +331,10 @@ def test_read(self):
|
|||
msg.fp.close()
|
||||
del msg
|
||||
|
||||
run_unittest(MhlibTests)
|
||||
|
||||
def test_main():
|
||||
run_unittest(MhlibTests)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_main()
|
||||
|
|
|
|||
|
|
@ -39,4 +39,9 @@ def test_file_parsing(self):
|
|||
".pyunit")
|
||||
|
||||
|
||||
test_support.run_unittest(MimeTypesTestCase)
|
||||
def test_main():
|
||||
test_support.run_unittest(MimeTypesTestCase)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_main()
|
||||
|
|
|
|||
|
|
@ -210,4 +210,9 @@ def test_bitwise_xor(self):
|
|||
self.failUnless(operator.xor(0xb, 0xc) == 0x7)
|
||||
|
||||
|
||||
test_support.run_unittest(OperatorTestCase)
|
||||
def test_main():
|
||||
test_support.run_unittest(OperatorTestCase)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_main()
|
||||
|
|
|
|||
|
|
@ -62,5 +62,9 @@ def test_tmpnam(self):
|
|||
self.check_tempfile(os.tmpnam())
|
||||
|
||||
|
||||
def test_main():
|
||||
run_unittest(TemporaryFileTests)
|
||||
|
||||
run_unittest(TemporaryFileTests)
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_main()
|
||||
|
|
|
|||
|
|
@ -353,5 +353,13 @@ def test_illegal_operator(self):
|
|||
self.check_bad_tree(tree, "a $= b")
|
||||
|
||||
|
||||
test_support.run_unittest(RoundtripLegalSyntaxTestCase)
|
||||
test_support.run_unittest(IllegalSyntaxTestCase)
|
||||
def test_main():
|
||||
loader = unittest.TestLoader()
|
||||
suite = unittest.TestSuite()
|
||||
suite.addTest(loader.loadTestsFromTestCase(RoundtripLegalSyntaxTestCase))
|
||||
suite.addTest(loader.loadTestsFromTestCase(IllegalSyntaxTestCase))
|
||||
test_support.run_suite(suite)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_main()
|
||||
|
|
|
|||
|
|
@ -75,4 +75,10 @@ def test_package_import__semantics(self):
|
|||
reload(module)
|
||||
self.assertEqual(getattr(module, var), 1)
|
||||
|
||||
run_unittest(TestImport)
|
||||
|
||||
def test_main():
|
||||
run_unittest(TestImport)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_main()
|
||||
|
|
|
|||
|
|
@ -76,4 +76,10 @@ def test_same_as_repr(self):
|
|||
verify(native == got, "expected %s got %s from pprint.%s" %
|
||||
(native, got, function))
|
||||
|
||||
test_support.run_unittest(QueryTestCase)
|
||||
|
||||
def test_main():
|
||||
test_support.run_unittest(QueryTestCase)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_main()
|
||||
|
|
|
|||
|
|
@ -153,4 +153,10 @@ def test_others(self):
|
|||
# pdb plays too many dynamic games
|
||||
# cm('pdb', pdb)
|
||||
|
||||
run_unittest(PyclbrTest)
|
||||
|
||||
def test_main():
|
||||
run_unittest(PyclbrTest)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_main()
|
||||
|
|
|
|||
|
|
@ -136,4 +136,9 @@ def test_embedded_ws(self):
|
|||
self.assert_(decodestring(e) == p)
|
||||
|
||||
|
||||
test_support.run_unittest(QuopriTestCase)
|
||||
def test_main():
|
||||
test_support.run_unittest(QuopriTestCase)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_main()
|
||||
|
|
|
|||
|
|
@ -265,6 +265,11 @@ def __repr__(self):
|
|||
raise Exception("This should be caught by Repr.repr_instance")
|
||||
|
||||
|
||||
run_unittest(ReprTests)
|
||||
if os.name != 'mac':
|
||||
run_unittest(LongReprTest)
|
||||
def test_main():
|
||||
run_unittest(ReprTests)
|
||||
if os.name != 'mac':
|
||||
run_unittest(LongReprTest)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_main()
|
||||
|
|
|
|||
|
|
@ -177,4 +177,10 @@ def test_rfc2822_phrases(self):
|
|||
self.check('To: User J. Person <person@dom.ain>\n\n',
|
||||
[('User J. Person', 'person@dom.ain')])
|
||||
|
||||
test_support.run_unittest(MessageTestCase)
|
||||
|
||||
def test_main():
|
||||
test_support.run_unittest(MessageTestCase)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_main()
|
||||
|
|
|
|||
|
|
@ -27,4 +27,9 @@ def test_case_3(self):
|
|||
"34aa973cd4c4daa4f61eeb2bdbad27316534016f")
|
||||
|
||||
|
||||
test_support.run_unittest(SHATestCase)
|
||||
def test_main():
|
||||
test_support.run_unittest(SHATestCase)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_main()
|
||||
|
|
|
|||
|
|
@ -125,4 +125,9 @@ def __len__(self): return len(self.seq)
|
|||
def __getitem__(self, i): return self.seq[i]
|
||||
|
||||
|
||||
test_support.run_unittest(StropFunctionTestCase)
|
||||
def test_main():
|
||||
test_support.run_unittest(StropFunctionTestCase)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_main()
|
||||
|
|
|
|||
|
|
@ -48,4 +48,9 @@ def test_mktime(self):
|
|||
999999))
|
||||
|
||||
|
||||
test_support.run_unittest(TimeTestCase)
|
||||
def test_main():
|
||||
test_support.run_unittest(TimeTestCase)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_main()
|
||||
|
|
|
|||
|
|
@ -37,4 +37,10 @@ def test_nocaret(self):
|
|||
self.assert_(len(err) == 3)
|
||||
self.assert_(err[1].strip() == "[x for x in x] = x")
|
||||
|
||||
run_unittest(TracebackCases)
|
||||
|
||||
def test_main():
|
||||
run_unittest(TracebackCases)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_main()
|
||||
|
|
|
|||
|
|
@ -49,4 +49,10 @@ def test_bad_types(self):
|
|||
self.assertRaises(TypeError, eval, "~2j")
|
||||
self.assertRaises(TypeError, eval, "~2.0")
|
||||
|
||||
run_unittest(UnaryOpTestCase)
|
||||
|
||||
def test_main():
|
||||
run_unittest(UnaryOpTestCase)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_main()
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
import unittest
|
||||
import weakref
|
||||
|
||||
from test_support import run_unittest
|
||||
import test_support
|
||||
|
||||
|
||||
class C:
|
||||
|
|
@ -434,5 +434,13 @@ def test_weak_valued_delitem(self):
|
|||
self.assert_(d.items() == [('something else', o2)])
|
||||
|
||||
|
||||
run_unittest(ReferencesTestCase)
|
||||
run_unittest(MappingTestCase)
|
||||
def test_main():
|
||||
loader = unittest.TestLoader()
|
||||
suite = unittest.TestSuite()
|
||||
suite.addTest(loader.loadTestsFromTestCase(ReferencesTestCase))
|
||||
suite.addTest(loader.loadTestsFromTestCase(MappingTestCase))
|
||||
test_support.run_suite(suite)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_main()
|
||||
|
|
|
|||
|
|
@ -27,4 +27,9 @@ def test_simple(self):
|
|||
parser.close()
|
||||
|
||||
|
||||
test_support.run_unittest(XMLParserTestCase)
|
||||
def test_main():
|
||||
test_support.run_unittest(XMLParserTestCase)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_main()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue