mirror of https://github.com/python/cpython
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
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue