diff options
author | Fred Drake <fdrake@acm.org> | 2001-09-20 21:33:42 (GMT) |
---|---|---|
committer | Fred Drake <fdrake@acm.org> | 2001-09-20 21:33:42 (GMT) |
commit | 2e2be3760ccdfd4bdde4afdd66f4078022ba3b61 (patch) | |
tree | d1b7dce65ddcecf2f312acfdb319ba656e99c3a1 /Lib | |
parent | 6f7993765ac0989b5d13084240797913627a31d8 (diff) | |
download | cpython-2e2be3760ccdfd4bdde4afdd66f4078022ba3b61.zip cpython-2e2be3760ccdfd4bdde4afdd66f4078022ba3b61.tar.gz cpython-2e2be3760ccdfd4bdde4afdd66f4078022ba3b61.tar.bz2 |
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.
Diffstat (limited to 'Lib')
34 files changed, 229 insertions, 39 deletions
diff --git a/Lib/test/test_binhex.py b/Lib/test/test_binhex.py index c774200..2580fb2 100755 --- a/Lib/test/test_binhex.py +++ b/Lib/test/test_binhex.py @@ -42,4 +42,9 @@ class BinHexTestCase(unittest.TestCase): self.assertEqual(self.DATA, finish) -test_support.run_unittest(BinHexTestCase) +def test_main(): + test_support.run_unittest(BinHexTestCase) + + +if __name__ == "__main__": + test_main() diff --git a/Lib/test/test_binop.py b/Lib/test/test_binop.py index c64e3a8..976e7ff 100644 --- a/Lib/test/test_binop.py +++ b/Lib/test/test_binop.py @@ -320,4 +320,9 @@ self.assertEqual(Rat(1, 2) * 3.0, 1.5) 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() diff --git a/Lib/test/test_call.py b/Lib/test/test_call.py index 529f15b..886bf18 100644 --- a/Lib/test/test_call.py +++ b/Lib/test/test_call.py @@ -122,4 +122,10 @@ class CFunctionCalls(unittest.TestCase): 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() diff --git a/Lib/test/test_codecs.py b/Lib/test/test_codecs.py index 6d9e31d..28d84ce 100644 --- a/Lib/test/test_codecs.py +++ b/Lib/test/test_codecs.py @@ -22,4 +22,10 @@ class UTF16Test(unittest.TestCase): 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() diff --git a/Lib/test/test_codeop.py b/Lib/test/test_codeop.py index 7847fb3..fbe4a31 100644 --- a/Lib/test/test_codeop.py +++ b/Lib/test/test_codeop.py @@ -87,4 +87,10 @@ class CodeopTests(unittest.TestCase): 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() diff --git a/Lib/test/test_commands.py b/Lib/test/test_commands.py index 54ae676..77372c5 100644 --- a/Lib/test/test_commands.py +++ b/Lib/test/test_commands.py @@ -42,4 +42,10 @@ class CommandTests(unittest.TestCase): self.assert_(re.match(pat, getstatus("/bin/ls"), re.VERBOSE)) -run_unittest(CommandTests) + +def test_main(): + run_unittest(CommandTests) + + +if __name__ == "__main__": + test_main() diff --git a/Lib/test/test_copy_reg.py b/Lib/test/test_copy_reg.py index 51ec60b..0f5c96f 100644 --- a/Lib/test/test_copy_reg.py +++ b/Lib/test/test_copy_reg.py @@ -22,4 +22,9 @@ class CopyRegTestCase(unittest.TestCase): type(1), int, "not a callable") -test_support.run_unittest(CopyRegTestCase) +def test_main(): + test_support.run_unittest(CopyRegTestCase) + + +if __name__ == "__main__": + test_main() diff --git a/Lib/test/test_dircache.py b/Lib/test/test_dircache.py index 6d57dcf..95dc2af 100644 --- a/Lib/test/test_dircache.py +++ b/Lib/test/test_dircache.py @@ -65,4 +65,10 @@ class DircacheTests(unittest.TestCase): 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() diff --git a/Lib/test/test_dospath.py b/Lib/test/test_dospath.py index 74bdd4a..3cca159 100644 --- a/Lib/test/test_dospath.py +++ b/Lib/test/test_dospath.py @@ -53,4 +53,9 @@ class DOSPathTestCase(unittest.TestCase): self.assertEquals(splitdrive("c:"), ('c:', '')) -test_support.run_unittest(DOSPathTestCase) +def test_main(): + test_support.run_unittest(DOSPathTestCase) + + +if __name__ == "__main__": + test_main() diff --git a/Lib/test/test_fnmatch.py b/Lib/test/test_fnmatch.py index 9f08926..0bd7d6a 100644 --- a/Lib/test/test_fnmatch.py +++ b/Lib/test/test_fnmatch.py @@ -38,4 +38,9 @@ class FnmatchTestCase(unittest.TestCase): check('\\', r'[!\]', 0) -test_support.run_unittest(FnmatchTestCase) +def test_main(): + test_support.run_unittest(FnmatchTestCase) + + +if __name__ == "__main__": + test_main() diff --git a/Lib/test/test_fpformat.py b/Lib/test/test_fpformat.py index 9d20dc9..d4a5eb2 100644 --- a/Lib/test/test_fpformat.py +++ b/Lib/test/test_fpformat.py @@ -66,4 +66,10 @@ class FpformatTest(unittest.TestCase): else: self.fail("No exception on non-numeric sci") -run_unittest(FpformatTest) + +def test_main(): + run_unittest(FpformatTest) + + +if __name__ == "__main__": + test_main() diff --git a/Lib/test/test_glob.py b/Lib/test/test_glob.py index 804ae1d..8cf6ecf 100644 --- a/Lib/test/test_glob.py +++ b/Lib/test/test_glob.py @@ -106,4 +106,10 @@ class GlobTests(unittest.TestCase): 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() diff --git a/Lib/test/test_grp.py b/Lib/test/test_grp.py index 1edb417..a16a922 100755 --- a/Lib/test/test_grp.py +++ b/Lib/test/test_grp.py @@ -19,4 +19,9 @@ class GroupDatabaseTestCase(unittest.TestCase): 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() diff --git a/Lib/test/test_hash.py b/Lib/test/test_hash.py index 20ec9a4..f8a1523 100644 --- a/Lib/test/test_hash.py +++ b/Lib/test/test_hash.py @@ -28,4 +28,9 @@ class HashEqualityTestCase(unittest.TestCase): 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() diff --git a/Lib/test/test_iter.py b/Lib/test/test_iter.py index 37fab7c..f6084cb 100644 --- a/Lib/test/test_iter.py +++ b/Lib/test/test_iter.py @@ -694,4 +694,10 @@ class TestCase(unittest.TestCase): (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() diff --git a/Lib/test/test_mailbox.py b/Lib/test/test_mailbox.py index 57a8316..4e23398 100644 --- a/Lib/test/test_mailbox.py +++ b/Lib/test/test_mailbox.py @@ -96,4 +96,9 @@ class MaildirTestCase(unittest.TestCase): # XXX We still need more tests! -test_support.run_unittest(MaildirTestCase) +def test_main(): + test_support.run_unittest(MaildirTestCase) + + +if __name__ == "__main__": + test_main() diff --git a/Lib/test/test_mhlib.py b/Lib/test/test_mhlib.py index 30f8ca3..9d5f101 100644 --- a/Lib/test/test_mhlib.py +++ b/Lib/test/test_mhlib.py @@ -331,4 +331,10 @@ class MhlibTests(unittest.TestCase): msg.fp.close() del msg -run_unittest(MhlibTests) + +def test_main(): + run_unittest(MhlibTests) + + +if __name__ == "__main__": + test_main() diff --git a/Lib/test/test_mimetypes.py b/Lib/test/test_mimetypes.py index 9b9d339..8735e27 100644 --- a/Lib/test/test_mimetypes.py +++ b/Lib/test/test_mimetypes.py @@ -39,4 +39,9 @@ class MimeTypesTestCase(unittest.TestCase): ".pyunit") -test_support.run_unittest(MimeTypesTestCase) +def test_main(): + test_support.run_unittest(MimeTypesTestCase) + + +if __name__ == "__main__": + test_main() diff --git a/Lib/test/test_operator.py b/Lib/test/test_operator.py index 6312d9a..439d340 100644 --- a/Lib/test/test_operator.py +++ b/Lib/test/test_operator.py @@ -210,4 +210,9 @@ class OperatorTestCase(unittest.TestCase): 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() diff --git a/Lib/test/test_os.py b/Lib/test/test_os.py index 9cddb5f..3f26f2f 100644 --- a/Lib/test/test_os.py +++ b/Lib/test/test_os.py @@ -62,5 +62,9 @@ class TemporaryFileTests(unittest.TestCase): self.check_tempfile(os.tmpnam()) +def test_main(): + run_unittest(TemporaryFileTests) -run_unittest(TemporaryFileTests) + +if __name__ == "__main__": + test_main() diff --git a/Lib/test/test_parser.py b/Lib/test/test_parser.py index 9e99475..966f3e9 100644 --- a/Lib/test/test_parser.py +++ b/Lib/test/test_parser.py @@ -353,5 +353,13 @@ class IllegalSyntaxTestCase(unittest.TestCase): 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() diff --git a/Lib/test/test_pkgimport.py b/Lib/test/test_pkgimport.py index 2f19509..72889f9 100644 --- a/Lib/test/test_pkgimport.py +++ b/Lib/test/test_pkgimport.py @@ -75,4 +75,10 @@ class TestImport(unittest.TestCase): reload(module) self.assertEqual(getattr(module, var), 1) -run_unittest(TestImport) + +def test_main(): + run_unittest(TestImport) + + +if __name__ == "__main__": + test_main() diff --git a/Lib/test/test_pprint.py b/Lib/test/test_pprint.py index 34c7a84..167b4ac 100644 --- a/Lib/test/test_pprint.py +++ b/Lib/test/test_pprint.py @@ -76,4 +76,10 @@ class QueryTestCase(unittest.TestCase): 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() diff --git a/Lib/test/test_pyclbr.py b/Lib/test/test_pyclbr.py index ce4d8ac..179b3b5 100644 --- a/Lib/test/test_pyclbr.py +++ b/Lib/test/test_pyclbr.py @@ -153,4 +153,10 @@ class PyclbrTest(unittest.TestCase): # pdb plays too many dynamic games # cm('pdb', pdb) -run_unittest(PyclbrTest) + +def test_main(): + run_unittest(PyclbrTest) + + +if __name__ == "__main__": + test_main() diff --git a/Lib/test/test_quopri.py b/Lib/test/test_quopri.py index 348f4bc..0e99727 100644 --- a/Lib/test/test_quopri.py +++ b/Lib/test/test_quopri.py @@ -136,4 +136,9 @@ zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz''') self.assert_(decodestring(e) == p) -test_support.run_unittest(QuopriTestCase) +def test_main(): + test_support.run_unittest(QuopriTestCase) + + +if __name__ == "__main__": + test_main() diff --git a/Lib/test/test_repr.py b/Lib/test/test_repr.py index cd9675a..b7d9374 100644 --- a/Lib/test/test_repr.py +++ b/Lib/test/test_repr.py @@ -265,6 +265,11 @@ class ClassWithFailingRepr: 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() diff --git a/Lib/test/test_rfc822.py b/Lib/test/test_rfc822.py index 4040cdb..ab1746b 100644 --- a/Lib/test/test_rfc822.py +++ b/Lib/test/test_rfc822.py @@ -177,4 +177,10 @@ class MessageTestCase(unittest.TestCase): 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() diff --git a/Lib/test/test_sha.py b/Lib/test/test_sha.py index bc76809..cad7780 100644 --- a/Lib/test/test_sha.py +++ b/Lib/test/test_sha.py @@ -27,4 +27,9 @@ class SHATestCase(unittest.TestCase): "34aa973cd4c4daa4f61eeb2bdbad27316534016f") -test_support.run_unittest(SHATestCase) +def test_main(): + test_support.run_unittest(SHATestCase) + + +if __name__ == "__main__": + test_main() diff --git a/Lib/test/test_strop.py b/Lib/test/test_strop.py index 7a32e08..e26f08f 100644 --- a/Lib/test/test_strop.py +++ b/Lib/test/test_strop.py @@ -125,4 +125,9 @@ class Sequence: 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() diff --git a/Lib/test/test_time.py b/Lib/test/test_time.py index 160ce4d..b2a3a28 100644 --- a/Lib/test/test_time.py +++ b/Lib/test/test_time.py @@ -48,4 +48,9 @@ class TimeTestCase(unittest.TestCase): 999999)) -test_support.run_unittest(TimeTestCase) +def test_main(): + test_support.run_unittest(TimeTestCase) + + +if __name__ == "__main__": + test_main() diff --git a/Lib/test/test_traceback.py b/Lib/test/test_traceback.py index 9f818e1..1b0a124 100644 --- a/Lib/test/test_traceback.py +++ b/Lib/test/test_traceback.py @@ -37,4 +37,10 @@ class TracebackCases(unittest.TestCase): 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() diff --git a/Lib/test/test_unary.py b/Lib/test/test_unary.py index 01c5f01..0c5dd94 100644 --- a/Lib/test/test_unary.py +++ b/Lib/test/test_unary.py @@ -49,4 +49,10 @@ class UnaryOpTestCase(unittest.TestCase): 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() diff --git a/Lib/test/test_weakref.py b/Lib/test/test_weakref.py index fa12a6e..5dfa6ce 100644 --- a/Lib/test/test_weakref.py +++ b/Lib/test/test_weakref.py @@ -2,7 +2,7 @@ import sys import unittest import weakref -from test_support import run_unittest +import test_support class C: @@ -434,5 +434,13 @@ class MappingTestCase(TestBase): 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() diff --git a/Lib/test/test_xmllib.py b/Lib/test/test_xmllib.py index a1c5057..9ea5042 100644 --- a/Lib/test/test_xmllib.py +++ b/Lib/test/test_xmllib.py @@ -27,4 +27,9 @@ class XMLParserTestCase(unittest.TestCase): parser.close() -test_support.run_unittest(XMLParserTestCase) +def test_main(): + test_support.run_unittest(XMLParserTestCase) + + +if __name__ == "__main__": + test_main() |