Combine the functionality of test_support.run_unittest()

and test_support.run_classtests() into run_unittest()
and use it wherever possible.

Also don't use "from test.test_support import ...", but
"from test import test_support" in a few spots.

From SF patch #662807.
This commit is contained in:
Walter Dörwald 2003-05-01 17:45:56 +00:00
parent 90437c03f2
commit 21d3a32b99
63 changed files with 310 additions and 402 deletions

View File

@ -105,10 +105,12 @@ class TestBuffercStringIO(TestcStringIO):
def test_main(): def test_main():
test_support.run_unittest(TestStringIO) test_support.run_unittest(
test_support.run_unittest(TestcStringIO) TestStringIO,
test_support.run_unittest(TestBufferStringIO) TestcStringIO,
test_support.run_unittest(TestBuffercStringIO) TestBufferStringIO,
TestBuffercStringIO
)
if __name__ == '__main__': if __name__ == '__main__':
test_main() test_main()

View File

@ -192,9 +192,7 @@ class AllTest(unittest.TestCase):
def test_main(): def test_main():
suite = unittest.TestSuite() test_support.run_unittest(AllTest)
suite.addTest(unittest.makeSuite(AllTest))
test_support.run_suite(suite)
if __name__ == "__main__": if __name__ == "__main__":
test_main() test_main()

View File

@ -1,16 +1,16 @@
from unittest import TestCase import unittest
from test.test_support import vereq, run_unittest from test import test_support
from base64 import encodestring, decodestring import base64
class Base64TestCase(TestCase): class Base64TestCase(unittest.TestCase):
def test_encodestring(self): def test_encodestring(self):
vereq(encodestring("www.python.org"), "d3d3LnB5dGhvbi5vcmc=\n") self.assertEqual(base64.encodestring("www.python.org"), "d3d3LnB5dGhvbi5vcmc=\n")
vereq(encodestring("a"), "YQ==\n") self.assertEqual(base64.encodestring("a"), "YQ==\n")
vereq(encodestring("ab"), "YWI=\n") self.assertEqual(base64.encodestring("ab"), "YWI=\n")
vereq(encodestring("abc"), "YWJj\n") self.assertEqual(base64.encodestring("abc"), "YWJj\n")
vereq(encodestring(""), "") self.assertEqual(base64.encodestring(""), "")
vereq(encodestring("abcdefghijklmnopqrstuvwxyz" self.assertEqual(base64.encodestring("abcdefghijklmnopqrstuvwxyz"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ" "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"0123456789!@#0^&*();:<>,. []{}"), "0123456789!@#0^&*();:<>,. []{}"),
"YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXpBQkNE" "YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXpBQkNE"
@ -18,20 +18,20 @@ class Base64TestCase(TestCase):
"Y3ODkhQCMwXiYqKCk7Ojw+LC4gW117fQ==\n") "Y3ODkhQCMwXiYqKCk7Ojw+LC4gW117fQ==\n")
def test_decodestring(self): def test_decodestring(self):
vereq(decodestring("d3d3LnB5dGhvbi5vcmc=\n"), "www.python.org") self.assertEqual(base64.decodestring("d3d3LnB5dGhvbi5vcmc=\n"), "www.python.org")
vereq(decodestring("YQ==\n"), "a") self.assertEqual(base64.decodestring("YQ==\n"), "a")
vereq(decodestring("YWI=\n"), "ab") self.assertEqual(base64.decodestring("YWI=\n"), "ab")
vereq(decodestring("YWJj\n"), "abc") self.assertEqual(base64.decodestring("YWJj\n"), "abc")
vereq(decodestring("YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXpBQkNE" self.assertEqual(base64.decodestring("YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXpBQkNE"
"RUZHSElKS0xNTk9QUVJTVFVWV1hZWjAxMjM0\nNT" "RUZHSElKS0xNTk9QUVJTVFVWV1hZWjAxMjM0\nNT"
"Y3ODkhQCMwXiYqKCk7Ojw+LC4gW117fQ==\n"), "Y3ODkhQCMwXiYqKCk7Ojw+LC4gW117fQ==\n"),
"abcdefghijklmnopqrstuvwxyz" "abcdefghijklmnopqrstuvwxyz"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ" "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"0123456789!@#0^&*();:<>,. []{}") "0123456789!@#0^&*();:<>,. []{}")
vereq(decodestring(''), '') self.assertEqual(base64.decodestring(''), '')
def test_main(): def test_main():
run_unittest(Base64TestCase) test_support.run_unittest(Base64TestCase)
if __name__ == "__main__": if __name__ == "__main__":
test_main() test_main()

View File

@ -198,8 +198,7 @@ __test__ = {'libreftest' : libreftest}
def test_main(verbose=None): def test_main(verbose=None):
from test import test_bisect from test import test_bisect
test_support.run_classtests(TestBisect, test_support.run_unittest(TestBisect, TestInsort)
TestInsort)
test_support.run_doctest(test_bisect, verbose) test_support.run_doctest(test_bisect, verbose)
if __name__ == "__main__": if __name__ == "__main__":

View File

@ -321,7 +321,7 @@ class BoolTest(unittest.TestCase):
self.assertEqual(cPickle.dumps(False, True), "I00\n.") self.assertEqual(cPickle.dumps(False, True), "I00\n.")
def test_main(): def test_main():
test_support.run_classtests(BoolTest) test_support.run_unittest(BoolTest)
if __name__ == "__main__": if __name__ == "__main__":
test_main() test_main()

View File

@ -1219,9 +1219,7 @@ class BuiltinTest(unittest.TestCase):
self.assertRaises(ValueError, zip, BadSeq(), BadSeq()) self.assertRaises(ValueError, zip, BadSeq(), BadSeq())
def test_main(): def test_main():
suite = unittest.TestSuite() test.test_support.run_unittest(BuiltinTest)
suite.addTest(unittest.makeSuite(BuiltinTest))
test.test_support.run_suite(suite)
if __name__ == "__main__": if __name__ == "__main__":
test_main() test_main()

View File

@ -309,13 +309,12 @@ class FuncTest(BaseTest):
self.assertRaises(ValueError, bz2.decompress, self.DATA[:-10]) self.assertRaises(ValueError, bz2.decompress, self.DATA[:-10])
def test_main(): def test_main():
suite = unittest.TestSuite() test_support.run_unittest(
for test in (BZ2FileTest, BZ2FileTest,
BZ2CompressorTest, BZ2CompressorTest,
BZ2DecompressorTest, BZ2DecompressorTest,
FuncTest): FuncTest
suite.addTest(unittest.makeSuite(test)) )
test_support.run_suite(suite)
if __name__ == '__main__': if __name__ == '__main__':
test_main() test_main()

View File

@ -1,7 +1,7 @@
import calendar import calendar
import unittest import unittest
from test.test_support import run_unittest from test import test_support
class CalendarTestCase(unittest.TestCase): class CalendarTestCase(unittest.TestCase):
@ -55,7 +55,7 @@ class CalendarTestCase(unittest.TestCase):
self.assertEqual(len(d), 13) self.assertEqual(len(d), 13)
def test_main(): def test_main():
run_unittest(CalendarTestCase) test_support.run_unittest(CalendarTestCase)
if __name__ == "__main__": if __name__ == "__main__":
test_main() test_main()

View File

@ -1,5 +1,5 @@
import unittest import unittest
from test.test_support import run_unittest from test import test_support
# The test cases here cover several paths through the function calling # The test cases here cover several paths through the function calling
# code. They depend on the METH_XXX flag that is used to define a C # code. They depend on the METH_XXX flag that is used to define a C
@ -124,7 +124,7 @@ class CFunctionCalls(unittest.TestCase):
def test_main(): def test_main():
run_unittest(CFunctionCalls) test_support.run_unittest(CFunctionCalls)
if __name__ == "__main__": if __name__ == "__main__":

View File

@ -322,11 +322,11 @@ class SafeConfigParserTestCase(ConfigParserTestCase):
def test_main(): def test_main():
suite = unittest.TestSuite() test_support.run_unittest(
suite.addTests([unittest.makeSuite(ConfigParserTestCase), ConfigParserTestCase,
unittest.makeSuite(RawConfigParserTestCase), RawConfigParserTestCase,
unittest.makeSuite(SafeConfigParserTestCase)]) SafeConfigParserTestCase
test_support.run_suite(suite) )
if __name__ == "__main__": if __name__ == "__main__":
test_main() test_main()

View File

@ -39,9 +39,7 @@ class CharmapCodecTest(unittest.TestCase):
self.assertRaises(UnicodeError, unicode, 'abc\001', codecname) self.assertRaises(UnicodeError, unicode, 'abc\001', codecname)
def test_main(): def test_main():
suite = unittest.TestSuite() test.test_support.run_unittest(CharmapCodecTest)
suite.addTest(unittest.makeSuite(CharmapCodecTest))
test.test_support.run_suite(suite)
if __name__ == "__main__": if __name__ == "__main__":
test_main() test_main()

View File

@ -659,9 +659,7 @@ class CodecCallbackTest(unittest.TestCase):
self.assertRaises(TypeError, u"\xff".translate, {0xff: ()}) self.assertRaises(TypeError, u"\xff".translate, {0xff: ()})
def test_main(): def test_main():
suite = unittest.TestSuite() test.test_support.run_unittest(CodecCallbackTest)
suite.addTest(unittest.makeSuite(CodecCallbackTest))
test.test_support.run_suite(suite)
if __name__ == "__main__": if __name__ == "__main__":
test_main() test_main()

View File

@ -333,13 +333,13 @@ class NameprepTest(unittest.TestCase):
raise test_support.TestFailed("Test 3.%d: %s" % (pos+1, str(e))) raise test_support.TestFailed("Test 3.%d: %s" % (pos+1, str(e)))
def test_main(): def test_main():
suite = unittest.TestSuite() test_support.run_unittest(
suite.addTest(unittest.makeSuite(UTF16Test)) UTF16Test,
suite.addTest(unittest.makeSuite(EscapeDecodeTest)) EscapeDecodeTest,
suite.addTest(unittest.makeSuite(RecodingTest)) RecodingTest,
suite.addTest(unittest.makeSuite(PunycodeTest)) PunycodeTest,
suite.addTest(unittest.makeSuite(NameprepTest)) NameprepTest
test_support.run_suite(suite) )
if __name__ == "__main__": if __name__ == "__main__":

View File

@ -516,9 +516,7 @@ class TestCopy(unittest.TestCase):
self.assert_(x[0] is not y[0]) self.assert_(x[0] is not y[0])
def test_main(): def test_main():
suite = unittest.TestSuite() test_support.run_unittest(TestCopy)
suite.addTest(unittest.makeSuite(TestCopy))
test_support.run_suite(suite)
if __name__ == "__main__": if __name__ == "__main__":
test_main() test_main()

View File

@ -92,13 +92,12 @@ class cPickleFastPicklerTests(AbstractPickleTests):
self.assertEqual(a, b) self.assertEqual(a, b)
def test_main(): def test_main():
loader = unittest.TestLoader() test_support.run_unittest(
suite = unittest.TestSuite() cPickleTests,
suite.addTest(loader.loadTestsFromTestCase(cPickleTests)) cPicklePicklerTests,
suite.addTest(loader.loadTestsFromTestCase(cPicklePicklerTests)) cPickleListPicklerTests,
suite.addTest(loader.loadTestsFromTestCase(cPickleListPicklerTests)) cPickleFastPicklerTests
suite.addTest(loader.loadTestsFromTestCase(cPickleFastPicklerTests)) )
test_support.run_suite(suite)
if __name__ == "__main__": if __name__ == "__main__":
test_main() test_main()

View File

@ -6,7 +6,7 @@ import unittest
from StringIO import StringIO from StringIO import StringIO
import csv import csv
import gc import gc
from test.test_support import verbose from test import test_support
class Test_Csv(unittest.TestCase): class Test_Csv(unittest.TestCase):
""" """
@ -568,7 +568,7 @@ Stonecutters Seafood and Chop House, Lemont, IL, 12/19/02, Week Back
self.assertEqual(dialect.skipinitialspace, False) self.assertEqual(dialect.skipinitialspace, False)
if not hasattr(sys, "gettotalrefcount"): if not hasattr(sys, "gettotalrefcount"):
if verbose: print "*** skipping leakage tests ***" if test_support.verbose: print "*** skipping leakage tests ***"
else: else:
class NUL: class NUL:
def write(s, *args): def write(s, *args):
@ -640,15 +640,11 @@ else:
# if writer leaks during write, last delta should be 5 or more # if writer leaks during write, last delta should be 5 or more
self.assertEqual(delta < 5, True) self.assertEqual(delta < 5, True)
def _testclasses(): def test_main():
mod = sys.modules[__name__] mod = sys.modules[__name__]
return [getattr(mod, name) for name in dir(mod) if name.startswith('Test')] test_support.run_unittest(
*[getattr(mod, name) for name in dir(mod) if name.startswith('Test')]
def suite(): )
suite = unittest.TestSuite()
for testclass in _testclasses():
suite.addTest(unittest.makeSuite(testclass))
return suite
if __name__ == '__main__': if __name__ == '__main__':
unittest.main(defaultTest='suite') test_main()

View File

@ -162,11 +162,7 @@ def test_main(imported_module=None):
if test_support.verbose: if test_support.verbose:
print print
print "*** Using %s as _thread module ***" % _thread print "*** Using %s as _thread module ***" % _thread
suite = unittest.TestSuite() test_support.run_unittest(LockTests, MiscTests, ThreadTests)
suite.addTest(unittest.makeSuite(LockTests))
suite.addTest(unittest.makeSuite(MiscTests))
suite.addTest(unittest.makeSuite(ThreadTests))
test_support.run_suite(suite)
if __name__ == '__main__': if __name__ == '__main__':
test_main() test_main()

View File

@ -104,14 +104,8 @@ class SubclassTestCase(EnumerateTestCase):
enum = MyEnum enum = MyEnum
def suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(EnumerateTestCase))
suite.addTest(unittest.makeSuite(SubclassTestCase))
return suite
def test_main(): def test_main():
test_support.run_suite(suite()) test_support.run_unittest(EnumerateTestCase, SubclassTestCase)
if __name__ == "__main__": if __name__ == "__main__":
test_main() test_main()

View File

@ -119,10 +119,7 @@ class DirCompareTestCase(unittest.TestCase):
def test_main(): def test_main():
suite = unittest.TestSuite() test_support.run_unittest(FileCompareTestCase, DirCompareTestCase)
for cls in FileCompareTestCase, DirCompareTestCase:
suite.addTest(unittest.makeSuite(cls))
test_support.run_suite(suite)
if __name__ == "__main__": if __name__ == "__main__":
test_main() test_main()

View File

@ -223,16 +223,14 @@ class LongLong_TestCase(unittest.TestCase):
self.failUnlessEqual(VERY_LARGE & ULLONG_MAX, getargs_K(VERY_LARGE)) self.failUnlessEqual(VERY_LARGE & ULLONG_MAX, getargs_K(VERY_LARGE))
def test_main(): def test_main():
suite = unittest.TestSuite() tests = [Signed_TestCase, Unsigned_TestCase]
suite.addTest(unittest.makeSuite(Signed_TestCase))
suite.addTest(unittest.makeSuite(Unsigned_TestCase))
try: try:
from _testcapi import getargs_L, getargs_K from _testcapi import getargs_L, getargs_K
except ImportError: except ImportError:
pass # PY_LONG_LONG not available pass # PY_LONG_LONG not available
else: else:
suite.addTest(unittest.makeSuite(LongLong_TestCase)) tests.append(LongLong_TestCase)
test_support.run_suite(suite) test_support.run_unittest(*tests)
if __name__ == "__main__": if __name__ == "__main__":
test_main() test_main()

View File

@ -97,9 +97,7 @@ class GroupDatabaseTestCase(unittest.TestCase):
self.assertRaises(KeyError, grp.getgrgid, fakegid) self.assertRaises(KeyError, grp.getgrgid, fakegid)
def test_main(): def test_main():
suite = unittest.TestSuite() test_support.run_unittest(GroupDatabaseTestCase)
suite.addTest(unittest.makeSuite(GroupDatabaseTestCase))
test_support.run_suite(suite)
if __name__ == "__main__": if __name__ == "__main__":
test_main() test_main()

View File

@ -118,9 +118,7 @@ class TextHexOct(unittest.TestCase):
\n""" \n"""
def test_main(): def test_main():
suite = unittest.TestSuite() test_support.run_unittest(TextHexOct)
suite.addTest(unittest.makeSuite(TextHexOct))
test_support.run_suite(suite)
if __name__ == "__main__": if __name__ == "__main__":
test_main() test_main()

View File

@ -103,12 +103,12 @@ class CopyTestCase(unittest.TestCase):
"Hexdigest of copy doesn't match original hexdigest.") "Hexdigest of copy doesn't match original hexdigest.")
def test_main(): def test_main():
suite = unittest.TestSuite() test_support.run_unittest(
suite.addTest(unittest.makeSuite(TestVectorsTestCase)) TestVectorsTestCase,
suite.addTest(unittest.makeSuite(ConstructorTestCase)) ConstructorTestCase,
suite.addTest(unittest.makeSuite(SanityTestCase)) SanityTestCase,
suite.addTest(unittest.makeSuite(CopyTestCase)) CopyTestCase
test_support.run_suite(suite) )
if __name__ == "__main__": if __name__ == "__main__":
test_main() test_main()

View File

@ -248,11 +248,11 @@ class TestIsInstanceIsSubclass(unittest.TestCase):
def test_main(): def test_main():
suite = unittest.TestSuite() test_support.run_unittest(
suite.addTest(unittest.makeSuite(TestIsInstanceExceptions)) TestIsInstanceExceptions,
suite.addTest(unittest.makeSuite(TestIsSubclassExceptions)) TestIsSubclassExceptions,
suite.addTest(unittest.makeSuite(TestIsInstanceIsSubclass)) TestIsInstanceIsSubclass
test_support.run_suite(suite) )
if __name__ == '__main__': if __name__ == '__main__':

View File

@ -162,9 +162,7 @@ __test__ = {'libreftest' : libreftest}
def test_main(verbose=None): def test_main(verbose=None):
import test_itertools import test_itertools
suite = unittest.TestSuite() suite = unittest.TestSuite()
for testclass in (TestBasicOps, suite.addTest(unittest.makeSuite(TestBasicOps))
):
suite.addTest(unittest.makeSuite(testclass))
test_support.run_suite(suite) test_support.run_suite(suite)
test_support.run_doctest(test_itertools, verbose) test_support.run_doctest(test_itertools, verbose)

View File

@ -1193,18 +1193,11 @@ class TestMatchAbbrev(BaseTest):
"ambiguous option: --f (%s?)" % possibilities, "ambiguous option: --f (%s?)" % possibilities,
funcargs=[s, wordmap]) funcargs=[s, wordmap])
def _testclasses():
mod = sys.modules[__name__]
return [getattr(mod, name) for name in dir(mod) if name.startswith('Test')]
def suite():
suite = unittest.TestSuite()
for testclass in _testclasses():
suite.addTest(unittest.makeSuite(testclass))
return suite
def test_main(): def test_main():
test_support.run_suite(suite()) mod = sys.modules[__name__]
test_support.run_unittest(
*[getattr(mod, name) for name in dir(mod) if name.startswith('Test')]
)
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()

View File

@ -5,21 +5,20 @@
import os import os
import unittest import unittest
import warnings import warnings
from test import test_support
warnings.filterwarnings("ignore", "tempnam", RuntimeWarning, __name__) warnings.filterwarnings("ignore", "tempnam", RuntimeWarning, __name__)
warnings.filterwarnings("ignore", "tmpnam", RuntimeWarning, __name__) warnings.filterwarnings("ignore", "tmpnam", RuntimeWarning, __name__)
from test.test_support import TESTFN, run_classtests
class TemporaryFileTests(unittest.TestCase): class TemporaryFileTests(unittest.TestCase):
def setUp(self): def setUp(self):
self.files = [] self.files = []
os.mkdir(TESTFN) os.mkdir(test_support.TESTFN)
def tearDown(self): def tearDown(self):
for name in self.files: for name in self.files:
os.unlink(name) os.unlink(name)
os.rmdir(TESTFN) os.rmdir(test_support.TESTFN)
def check_tempfile(self, name): def check_tempfile(self, name):
# make sure it doesn't already exist: # make sure it doesn't already exist:
@ -36,10 +35,10 @@ class TemporaryFileTests(unittest.TestCase):
r"test_os$") r"test_os$")
self.check_tempfile(os.tempnam()) self.check_tempfile(os.tempnam())
name = os.tempnam(TESTFN) name = os.tempnam(test_support.TESTFN)
self.check_tempfile(name) self.check_tempfile(name)
name = os.tempnam(TESTFN, "pfx") name = os.tempnam(test_support.TESTFN, "pfx")
self.assert_(os.path.basename(name)[:3] == "pfx") self.assert_(os.path.basename(name)[:3] == "pfx")
self.check_tempfile(name) self.check_tempfile(name)
@ -84,15 +83,15 @@ class TemporaryFileTests(unittest.TestCase):
# Test attributes on return values from os.*stat* family. # Test attributes on return values from os.*stat* family.
class StatAttributeTests(unittest.TestCase): class StatAttributeTests(unittest.TestCase):
def setUp(self): def setUp(self):
os.mkdir(TESTFN) os.mkdir(test_support.TESTFN)
self.fname = os.path.join(TESTFN, "f1") self.fname = os.path.join(test_support.TESTFN, "f1")
f = open(self.fname, 'wb') f = open(self.fname, 'wb')
f.write("ABC") f.write("ABC")
f.close() f.close()
def tearDown(self): def tearDown(self):
os.unlink(self.fname) os.unlink(self.fname)
os.rmdir(TESTFN) os.rmdir(test_support.TESTFN)
def test_stat_attributes(self): def test_stat_attributes(self):
if not hasattr(os, "stat"): if not hasattr(os, "stat"):
@ -238,10 +237,10 @@ class WalkTests(unittest.TestCase):
# SUB11/ no kids # SUB11/ no kids
# SUB2/ just a file kid # SUB2/ just a file kid
# tmp3 # tmp3
sub1_path = join(TESTFN, "SUB1") sub1_path = join(test_support.TESTFN, "SUB1")
sub11_path = join(sub1_path, "SUB11") sub11_path = join(sub1_path, "SUB11")
sub2_path = join(TESTFN, "SUB2") sub2_path = join(test_support.TESTFN, "SUB2")
tmp1_path = join(TESTFN, "tmp1") tmp1_path = join(test_support.TESTFN, "tmp1")
tmp2_path = join(sub1_path, "tmp2") tmp2_path = join(sub1_path, "tmp2")
tmp3_path = join(sub2_path, "tmp3") tmp3_path = join(sub2_path, "tmp3")
@ -254,39 +253,39 @@ class WalkTests(unittest.TestCase):
f.close() f.close()
# Walk top-down. # Walk top-down.
all = list(os.walk(TESTFN)) all = list(os.walk(test_support.TESTFN))
self.assertEqual(len(all), 4) self.assertEqual(len(all), 4)
# We can't know which order SUB1 and SUB2 will appear in. # We can't know which order SUB1 and SUB2 will appear in.
# Not flipped: TESTFN, SUB1, SUB11, SUB2 # Not flipped: TESTFN, SUB1, SUB11, SUB2
# flipped: TESTFN, SUB2, SUB1, SUB11 # flipped: TESTFN, SUB2, SUB1, SUB11
flipped = all[0][1][0] != "SUB1" flipped = all[0][1][0] != "SUB1"
all[0][1].sort() all[0][1].sort()
self.assertEqual(all[0], (TESTFN, ["SUB1", "SUB2"], ["tmp1"])) self.assertEqual(all[0], (test_support.TESTFN, ["SUB1", "SUB2"], ["tmp1"]))
self.assertEqual(all[1 + flipped], (sub1_path, ["SUB11"], ["tmp2"])) self.assertEqual(all[1 + flipped], (sub1_path, ["SUB11"], ["tmp2"]))
self.assertEqual(all[2 + flipped], (sub11_path, [], [])) self.assertEqual(all[2 + flipped], (sub11_path, [], []))
self.assertEqual(all[3 - 2 * flipped], (sub2_path, [], ["tmp3"])) self.assertEqual(all[3 - 2 * flipped], (sub2_path, [], ["tmp3"]))
# Prune the search. # Prune the search.
all = [] all = []
for root, dirs, files in os.walk(TESTFN): for root, dirs, files in os.walk(test_support.TESTFN):
all.append((root, dirs, files)) all.append((root, dirs, files))
# Don't descend into SUB1. # Don't descend into SUB1.
if 'SUB1' in dirs: if 'SUB1' in dirs:
# Note that this also mutates the dirs we appended to all! # Note that this also mutates the dirs we appended to all!
dirs.remove('SUB1') dirs.remove('SUB1')
self.assertEqual(len(all), 2) self.assertEqual(len(all), 2)
self.assertEqual(all[0], (TESTFN, ["SUB2"], ["tmp1"])) self.assertEqual(all[0], (test_support.TESTFN, ["SUB2"], ["tmp1"]))
self.assertEqual(all[1], (sub2_path, [], ["tmp3"])) self.assertEqual(all[1], (sub2_path, [], ["tmp3"]))
# Walk bottom-up. # Walk bottom-up.
all = list(os.walk(TESTFN, topdown=False)) all = list(os.walk(test_support.TESTFN, topdown=False))
self.assertEqual(len(all), 4) self.assertEqual(len(all), 4)
# We can't know which order SUB1 and SUB2 will appear in. # We can't know which order SUB1 and SUB2 will appear in.
# Not flipped: SUB11, SUB1, SUB2, TESTFN # Not flipped: SUB11, SUB1, SUB2, TESTFN
# flipped: SUB2, SUB11, SUB1, TESTFN # flipped: SUB2, SUB11, SUB1, TESTFN
flipped = all[3][1][0] != "SUB1" flipped = all[3][1][0] != "SUB1"
all[3][1].sort() all[3][1].sort()
self.assertEqual(all[3], (TESTFN, ["SUB1", "SUB2"], ["tmp1"])) self.assertEqual(all[3], (test_support.TESTFN, ["SUB1", "SUB2"], ["tmp1"]))
self.assertEqual(all[flipped], (sub11_path, [], [])) self.assertEqual(all[flipped], (sub11_path, [], []))
self.assertEqual(all[flipped + 1], (sub1_path, ["SUB11"], ["tmp2"])) self.assertEqual(all[flipped + 1], (sub1_path, ["SUB11"], ["tmp2"]))
self.assertEqual(all[2 - 2 * flipped], (sub2_path, [], ["tmp3"])) self.assertEqual(all[2 - 2 * flipped], (sub2_path, [], ["tmp3"]))
@ -295,18 +294,20 @@ class WalkTests(unittest.TestCase):
# Windows, which doesn't have a recursive delete command. The # Windows, which doesn't have a recursive delete command. The
# (not so) subtlety is that rmdir will fail unless the dir's # (not so) subtlety is that rmdir will fail unless the dir's
# kids are removed first, so bottom up is essential. # kids are removed first, so bottom up is essential.
for root, dirs, files in os.walk(TESTFN, topdown=False): for root, dirs, files in os.walk(test_support.TESTFN, topdown=False):
for name in files: for name in files:
os.remove(join(root, name)) os.remove(join(root, name))
for name in dirs: for name in dirs:
os.rmdir(join(root, name)) os.rmdir(join(root, name))
os.rmdir(TESTFN) os.rmdir(test_support.TESTFN)
def test_main(): def test_main():
run_classtests(TemporaryFileTests, test_support.run_unittest(
TemporaryFileTests,
StatAttributeTests, StatAttributeTests,
EnvironTests, EnvironTests,
WalkTests) WalkTests
)
if __name__ == "__main__": if __name__ == "__main__":
test_main() test_main()

View File

@ -374,11 +374,10 @@ class IllegalSyntaxTestCase(unittest.TestCase):
self.check_bad_tree(tree, "malformed global ast") self.check_bad_tree(tree, "malformed global ast")
def test_main(): def test_main():
loader = unittest.TestLoader() test_support.run_unittest(
suite = unittest.TestSuite() RoundtripLegalSyntaxTestCase,
suite.addTest(loader.loadTestsFromTestCase(RoundtripLegalSyntaxTestCase)) IllegalSyntaxTestCase
suite.addTest(loader.loadTestsFromTestCase(IllegalSyntaxTestCase)) )
test_support.run_suite(suite)
if __name__ == "__main__": if __name__ == "__main__":

View File

@ -1,9 +1,9 @@
# Test the Unicode versions of normal file functions # Test the Unicode versions of normal file functions
# open, os.open, os.stat. os.listdir, os.rename, os.remove, os.mkdir, os.chdir, os.rmdir # open, os.open, os.stat. os.listdir, os.rename, os.remove, os.mkdir, os.chdir, os.rmdir
import os, unittest import os, unittest
from test.test_support import TESTFN, TestSkipped, TestFailed, run_suite from test import test_support
if not os.path.supports_unicode_filenames: if not os.path.supports_unicode_filenames:
raise TestSkipped, "test works only on NT+" raise test_support.TestSkipped, "test works only on NT+"
filenames = [ filenames = [
'abc', 'abc',
@ -28,11 +28,11 @@ def deltree(dirname):
os.rmdir(dirname) os.rmdir(dirname)
class UnicodeFileTests(unittest.TestCase): class UnicodeFileTests(unittest.TestCase):
files = [os.path.join(TESTFN, f) for f in filenames] files = [os.path.join(test_support.TESTFN, f) for f in filenames]
def setUp(self): def setUp(self):
try: try:
os.mkdir(TESTFN) os.mkdir(test_support.TESTFN)
except OSError: except OSError:
pass pass
for name in self.files: for name in self.files:
@ -42,17 +42,17 @@ class UnicodeFileTests(unittest.TestCase):
os.stat(name) os.stat(name)
def tearDown(self): def tearDown(self):
deltree(TESTFN) deltree(test_support.TESTFN)
def _apply_failure(self, fn, filename, expected_exception, def _apply_failure(self, fn, filename, expected_exception,
check_fn_in_exception = True): check_fn_in_exception = True):
try: try:
fn(filename) fn(filename)
raise TestFailed("Expected to fail calling '%s(%r)'" raise test_support.TestFailed("Expected to fail calling '%s(%r)'"
% (fn.__name__, filename)) % (fn.__name__, filename))
except expected_exception, details: except expected_exception, details:
if check_fn_in_exception and details.filename != filename: if check_fn_in_exception and details.filename != filename:
raise TestFailed("Function '%s(%r) failed with " raise test_support.TestFailed("Function '%s(%r) failed with "
"bad filename in the exception: %r" "bad filename in the exception: %r"
% (fn.__name__, filename, % (fn.__name__, filename,
details.filename)) details.filename))
@ -77,9 +77,9 @@ class UnicodeFileTests(unittest.TestCase):
os.stat(name) os.stat(name)
def test_listdir(self): def test_listdir(self):
f1 = os.listdir(TESTFN) f1 = os.listdir(test_support.TESTFN)
f1.sort() f1.sort()
f2 = os.listdir(unicode(TESTFN,"mbcs")) f2 = os.listdir(unicode(test_support.TESTFN,"mbcs"))
f2.sort() f2.sort()
print f1 print f1
print f2 print f2
@ -90,7 +90,7 @@ class UnicodeFileTests(unittest.TestCase):
os.rename("tmp",name) os.rename("tmp",name)
def test_directory(self): def test_directory(self):
dirname = os.path.join(TESTFN,u'Gr\xfc\xdf-\u66e8\u66e9\u66eb') dirname = os.path.join(test_support.TESTFN,u'Gr\xfc\xdf-\u66e8\u66e9\u66eb')
filename = u'\xdf-\u66e8\u66e9\u66eb' filename = u'\xdf-\u66e8\u66e9\u66eb'
oldwd = os.getcwd() oldwd = os.getcwd()
os.mkdir(dirname) os.mkdir(dirname)
@ -104,12 +104,10 @@ class UnicodeFileTests(unittest.TestCase):
os.rmdir(dirname) os.rmdir(dirname)
def test_main(): def test_main():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(UnicodeFileTests))
try: try:
run_suite(suite) test_support.run_unittest(UnicodeFileTests)
finally: finally:
deltree(TESTFN) deltree(test_support.TESTFN)
if __name__ == "__main__": if __name__ == "__main__":
test_main() test_main()

View File

@ -62,12 +62,11 @@ class PersPicklerTests(AbstractPersistentPicklerTests):
return u.load() return u.load()
def test_main(): def test_main():
loader = unittest.TestLoader() test_support.run_unittest(
suite = unittest.TestSuite() PickleTests,
suite.addTest(loader.loadTestsFromTestCase(PickleTests)) PicklerTests,
suite.addTest(loader.loadTestsFromTestCase(PicklerTests)) PersPicklerTests
suite.addTest(loader.loadTestsFromTestCase(PersPicklerTests)) )
test_support.run_suite(suite)
test_support.run_doctest(pickle) test_support.run_doctest(pickle)
if __name__ == "__main__": if __name__ == "__main__":

View File

@ -1,11 +1,11 @@
"Test posix functions" "Test posix functions"
from test.test_support import TestSkipped, TestFailed, TESTFN, run_suite from test import test_support
try: try:
import posix import posix
except ImportError: except ImportError:
raise TestSkipped, "posix is not available" raise test_support.TestSkipped, "posix is not available"
import time import time
import os import os
@ -19,11 +19,11 @@ class PosixTester(unittest.TestCase):
def setUp(self): def setUp(self):
# create empty file # create empty file
fp = open(TESTFN, 'w+') fp = open(test_support.TESTFN, 'w+')
fp.close() fp.close()
def tearDown(self): def tearDown(self):
os.unlink(TESTFN) os.unlink(test_support.TESTFN)
def testNoArgFunctions(self): def testNoArgFunctions(self):
# test posix functions which take no arguments and have # test posix functions which take no arguments and have
@ -46,7 +46,7 @@ class PosixTester(unittest.TestCase):
def test_fstatvfs(self): def test_fstatvfs(self):
if hasattr(posix, 'fstatvfs'): if hasattr(posix, 'fstatvfs'):
fp = open(TESTFN) fp = open(test_support.TESTFN)
try: try:
self.assert_(posix.fstatvfs(fp.fileno())) self.assert_(posix.fstatvfs(fp.fileno()))
finally: finally:
@ -54,7 +54,7 @@ class PosixTester(unittest.TestCase):
def test_ftruncate(self): def test_ftruncate(self):
if hasattr(posix, 'ftruncate'): if hasattr(posix, 'ftruncate'):
fp = open(TESTFN, 'w+') fp = open(test_support.TESTFN, 'w+')
try: try:
# we need to have some data to truncate # we need to have some data to truncate
fp.write('test') fp.write('test')
@ -65,7 +65,7 @@ class PosixTester(unittest.TestCase):
def test_dup(self): def test_dup(self):
if hasattr(posix, 'dup'): if hasattr(posix, 'dup'):
fp = open(TESTFN) fp = open(test_support.TESTFN)
try: try:
fd = posix.dup(fp.fileno()) fd = posix.dup(fp.fileno())
self.assert_(isinstance(fd, int)) self.assert_(isinstance(fd, int))
@ -75,8 +75,8 @@ class PosixTester(unittest.TestCase):
def test_dup2(self): def test_dup2(self):
if hasattr(posix, 'dup2'): if hasattr(posix, 'dup2'):
fp1 = open(TESTFN) fp1 = open(test_support.TESTFN)
fp2 = open(TESTFN) fp2 = open(test_support.TESTFN)
try: try:
posix.dup2(fp1.fileno(), fp2.fileno()) posix.dup2(fp1.fileno(), fp2.fileno())
finally: finally:
@ -84,7 +84,7 @@ class PosixTester(unittest.TestCase):
fp2.close() fp2.close()
def fdopen_helper(self, *args): def fdopen_helper(self, *args):
fd = os.open(TESTFN, os.O_RDONLY) fd = os.open(test_support.TESTFN, os.O_RDONLY)
fp2 = posix.fdopen(fd, *args) fp2 = posix.fdopen(fd, *args)
fp2.close() fp2.close()
@ -96,7 +96,7 @@ class PosixTester(unittest.TestCase):
def test_fstat(self): def test_fstat(self):
if hasattr(posix, 'fstat'): if hasattr(posix, 'fstat'):
fp = open(TESTFN) fp = open(test_support.TESTFN)
try: try:
self.assert_(posix.fstat(fp.fileno())) self.assert_(posix.fstat(fp.fileno()))
finally: finally:
@ -104,20 +104,20 @@ class PosixTester(unittest.TestCase):
def test_stat(self): def test_stat(self):
if hasattr(posix, 'stat'): if hasattr(posix, 'stat'):
self.assert_(posix.stat(TESTFN)) self.assert_(posix.stat(test_support.TESTFN))
def test_chdir(self): def test_chdir(self):
if hasattr(posix, 'chdir'): if hasattr(posix, 'chdir'):
posix.chdir(os.curdir) posix.chdir(os.curdir)
self.assertRaises(OSError, posix.chdir, TESTFN) self.assertRaises(OSError, posix.chdir, test_support.TESTFN)
def test_lsdir(self): def test_lsdir(self):
if hasattr(posix, 'lsdir'): if hasattr(posix, 'lsdir'):
self.assert_(TESTFN in posix.lsdir(os.curdir)) self.assert_(test_support.TESTFN in posix.lsdir(os.curdir))
def test_access(self): def test_access(self):
if hasattr(posix, 'access'): if hasattr(posix, 'access'):
self.assert_(posix.access(TESTFN, os.R_OK)) self.assert_(posix.access(test_support.TESTFN, os.R_OK))
def test_umask(self): def test_umask(self):
if hasattr(posix, 'umask'): if hasattr(posix, 'umask'):
@ -149,13 +149,11 @@ class PosixTester(unittest.TestCase):
def test_utime(self): def test_utime(self):
if hasattr(posix, 'utime'): if hasattr(posix, 'utime'):
now = time.time() now = time.time()
posix.utime(TESTFN, None) posix.utime(test_support.TESTFN, None)
posix.utime(TESTFN, (now, now)) posix.utime(test_support.TESTFN, (now, now))
def test_main(): def test_main():
suite = unittest.TestSuite() test_support.run_unittest(PosixTester)
suite.addTest(unittest.makeSuite(PosixTester))
run_suite(suite)
if __name__ == '__main__': if __name__ == '__main__':
test_main() test_main()

View File

@ -103,9 +103,7 @@ class PowTest(unittest.TestCase):
def test_main(): def test_main():
suite = unittest.TestSuite() test.test_support.run_unittest(PowTest)
suite.addTest(unittest.makeSuite(PowTest))
test.test_support.run_suite(suite)
if __name__ == "__main__": if __name__ == "__main__":
test_main() test_main()

View File

@ -349,11 +349,10 @@ def show_events(callable):
def test_main(): def test_main():
loader = unittest.TestLoader() test_support.run_unittest(
suite = unittest.TestSuite() ProfileHookTestCase,
suite.addTest(loader.loadTestsFromTestCase(ProfileHookTestCase)) ProfileSimulatorTestCase
suite.addTest(loader.loadTestsFromTestCase(ProfileSimulatorTestCase)) )
test_support.run_suite(suite)
if __name__ == "__main__": if __name__ == "__main__":

View File

@ -86,9 +86,7 @@ class PwdTest(unittest.TestCase):
self.assertRaises(KeyError, pwd.getpwuid, fakeuid) self.assertRaises(KeyError, pwd.getpwuid, fakeuid)
def test_main(): def test_main():
suite = unittest.TestSuite() test_support.run_unittest(PwdTest)
suite.addTest(unittest.makeSuite(PwdTest))
test_support.run_suite(suite)
if __name__ == "__main__": if __name__ == "__main__":
test_main() test_main()

View File

@ -1,7 +1,7 @@
import sys import sys
sys.path = ['.'] + sys.path sys.path = ['.'] + sys.path
from test.test_support import verbose, run_suite from test.test_support import verbose, run_unittest
import re import re
from sre import Scanner from sre import Scanner
import sys, os, traceback import sys, os, traceback
@ -432,9 +432,7 @@ def run_re_tests():
print '=== Fails on unicode-sensitive match', t print '=== Fails on unicode-sensitive match', t
def test_main(): def test_main():
suite = unittest.TestSuite() run_unittest(ReTests)
suite.addTest(unittest.makeSuite(ReTests))
run_suite(suite)
run_re_tests() run_re_tests()
if __name__ == "__main__": if __name__ == "__main__":

View File

@ -352,7 +352,7 @@ class ListTest(unittest.TestCase):
self.assertIs(op(x, y), True) self.assertIs(op(x, y), True)
def test_main(): def test_main():
test_support.run_classtests(VectorTest, NumberTest, MiscTest, DictTest, ListTest) test_support.run_unittest(VectorTest, NumberTest, MiscTest, DictTest, ListTest)
if __name__ == "__main__": if __name__ == "__main__":
test_main() test_main()

View File

@ -658,9 +658,12 @@ Set(['Jack', 'Jane', 'Janice', 'John', 'Marvin', 'Sam', 'Zack'])
#============================================================================== #==============================================================================
def makeAllTests(): __test__ = {'libreftest' : libreftest}
suite = unittest.TestSuite()
for klass in (TestSetOfSets, def test_main(verbose=None):
from test import test_sets
test_support.run_unittest(
TestSetOfSets,
TestExceptionPropagation, TestExceptionPropagation,
TestBasicOpsEmpty, TestBasicOpsEmpty,
TestBasicOpsSingleton, TestBasicOpsSingleton,
@ -681,19 +684,8 @@ def makeAllTests():
TestCopyingSingleton, TestCopyingSingleton,
TestCopyingTriple, TestCopyingTriple,
TestCopyingTuple, TestCopyingTuple,
TestCopyingNested, TestCopyingNested
): )
suite.addTest(unittest.makeSuite(klass))
return suite
#------------------------------------------------------------------------------
__test__ = {'libreftest' : libreftest}
def test_main(verbose=None):
from test import test_sets
suite = makeAllTests()
test_support.run_suite(suite)
test_support.run_doctest(test_sets, verbose) test_support.run_doctest(test_sets, verbose)
if __name__ == "__main__": if __name__ == "__main__":

View File

@ -121,15 +121,15 @@ class TestProto2MemShelve(TestShelveBase):
_in_mem = True _in_mem = True
def test_main(): def test_main():
suite = unittest.TestSuite() test_support.run_unittest(
suite.addTest(unittest.makeSuite(TestAsciiFileShelve)) TestAsciiFileShelve,
suite.addTest(unittest.makeSuite(TestBinaryFileShelve)) TestBinaryFileShelve,
suite.addTest(unittest.makeSuite(TestProto2FileShelve)) TestProto2FileShelve,
suite.addTest(unittest.makeSuite(TestAsciiMemShelve)) TestAsciiMemShelve,
suite.addTest(unittest.makeSuite(TestBinaryMemShelve)) TestBinaryMemShelve,
suite.addTest(unittest.makeSuite(TestProto2MemShelve)) TestProto2MemShelve,
suite.addTest(unittest.makeSuite(TestCase)) TestCase
test_support.run_suite(suite) )
if __name__ == "__main__": if __name__ == "__main__":
test_main() test_main()

View File

@ -14,15 +14,9 @@ class TestShutil(unittest.TestCase):
def suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TestShutil))
return suite
def test_main(): def test_main():
test_support.run_suite(suite()) test_support.run_unittest(TestShutil)
if __name__ == '__main__': if __name__ == '__main__':
unittest.main(defaultTest='suite') test_main()

View File

@ -683,17 +683,18 @@ class SmallBufferedFileObjectClassTestCase(FileObjectClassTestCase):
bufsize = 2 # Exercise the buffering code bufsize = 2 # Exercise the buffering code
def test_main(): def test_main():
suite = unittest.TestSuite() tests = [ GeneralModuleTests, BasicTCPTest ]
suite.addTest(unittest.makeSuite(GeneralModuleTests))
suite.addTest(unittest.makeSuite(BasicTCPTest))
if sys.platform != 'mac': if sys.platform != 'mac':
suite.addTest(unittest.makeSuite(BasicUDPTest)) tests.append(BasicUDPTest)
suite.addTest(unittest.makeSuite(NonBlockingTCPTests))
suite.addTest(unittest.makeSuite(FileObjectClassTestCase)) tests.extend([
suite.addTest(unittest.makeSuite(UnbufferedFileObjectClassTestCase)) NonBlockingTCPTests,
suite.addTest(unittest.makeSuite(LineBufferedFileObjectClassTestCase)) FileObjectClassTestCase,
suite.addTest(unittest.makeSuite(SmallBufferedFileObjectClassTestCase)) UnbufferedFileObjectClassTestCase,
test_support.run_suite(suite) LineBufferedFileObjectClassTestCase,
SmallBufferedFileObjectClassTestCase
])
test_support.run_unittest(*tests)
if __name__ == "__main__": if __name__ == "__main__":
test_main() test_main()

View File

@ -19,9 +19,7 @@ class StrTest(
self.assertRaises(OverflowError, '%c'.__mod__, 0x1234) self.assertRaises(OverflowError, '%c'.__mod__, 0x1234)
def test_main(): def test_main():
suite = unittest.TestSuite() test_support.run_unittest(StrTest)
suite.addTest(unittest.makeSuite(StrTest))
test_support.run_suite(suite)
if __name__ == "__main__": if __name__ == "__main__":
test_main() test_main()

View File

@ -95,10 +95,7 @@ class ModuleTest(unittest.TestCase):
self.assertEqual(string.capwords('ABC-def DEF-ghi GHI'), 'Abc-def Def-ghi Ghi') self.assertEqual(string.capwords('ABC-def DEF-ghi GHI'), 'Abc-def Def-ghi Ghi')
def test_main(): def test_main():
suite = unittest.TestSuite() test_support.run_unittest(StringTest, ModuleTest)
suite.addTest(unittest.makeSuite(StringTest))
suite.addTest(unittest.makeSuite(ModuleTest))
test_support.run_suite(suite)
if __name__ == "__main__": if __name__ == "__main__":
test_main() test_main()

View File

@ -406,14 +406,14 @@ class CalculationTests(unittest.TestCase):
"%s != %s" % (result.tm_wday, self.time_tuple.tm_wday)) "%s != %s" % (result.tm_wday, self.time_tuple.tm_wday))
def test_main(): def test_main():
suite = unittest.TestSuite() test_support.run_unittest(
suite.addTest(unittest.makeSuite(LocaleTime_Tests)) LocaleTime_Tests,
suite.addTest(unittest.makeSuite(TimeRETests)) TimeRETests,
suite.addTest(unittest.makeSuite(StrptimeTests)) StrptimeTests,
suite.addTest(unittest.makeSuite(Strptime12AMPMTests)) Strptime12AMPMTests,
suite.addTest(unittest.makeSuite(JulianTests)) JulianTests,
suite.addTest(unittest.makeSuite(CalculationTests)) CalculationTests
test_support.run_suite(suite) )
if __name__ == '__main__': if __name__ == '__main__':

View File

@ -229,15 +229,16 @@ def run_suite(suite, testclass=None):
raise TestFailed(err) raise TestFailed(err)
def run_unittest(testclass): def run_unittest(*classes):
"""Run tests from a unittest.TestCase-derived class.""" """Run tests from unittest.TestCase-derived classes."""
run_suite(unittest.makeSuite(testclass), testclass)
def run_classtests(*classnames):
suite = unittest.TestSuite() suite = unittest.TestSuite()
for cls in classnames: for cls in classes:
suite.addTest(unittest.makeSuite(cls)) suite.addTest(unittest.makeSuite(cls))
run_suite(suite) if len(classes)==1:
testclass = classes[0]
else:
testclass = None
run_suite(suite, testclass)
#======================================================================= #=======================================================================

View File

@ -247,9 +247,7 @@ class SysModuleTest(unittest.TestCase):
self.assert_(isinstance(vi[4], int)) self.assert_(isinstance(vi[4], int))
def test_main(): def test_main():
suite = unittest.TestSuite() test.test_support.run_unittest(SysModuleTest)
suite.addTest(unittest.makeSuite(SysModuleTest))
test.test_support.run_suite(suite)
if __name__ == "__main__": if __name__ == "__main__":
test_main() test_main()

View File

@ -240,27 +240,26 @@ def test_main():
# create testtar.tar.bz2 # create testtar.tar.bz2
bz2.BZ2File(tarname("bz2"), "wb").write(file(tarname(), "rb").read()) bz2.BZ2File(tarname("bz2"), "wb").write(file(tarname(), "rb").read())
try: tests = [
suite = unittest.TestSuite() ReadTest,
ReadStreamTest,
suite.addTest(unittest.makeSuite(ReadTest)) WriteTest,
suite.addTest(unittest.makeSuite(ReadStreamTest)) WriteStreamTest
suite.addTest(unittest.makeSuite(WriteTest)) ]
suite.addTest(unittest.makeSuite(WriteStreamTest))
if gzip: if gzip:
suite.addTest(unittest.makeSuite(ReadTestGzip)) tests.extend([
suite.addTest(unittest.makeSuite(ReadStreamTestGzip)) ReadTestGzip, ReadStreamTestGzip,
suite.addTest(unittest.makeSuite(WriteTestGzip)) WriteTestGzip, WriteStreamTestGzip
suite.addTest(unittest.makeSuite(WriteStreamTestGzip)) ])
if bz2: if bz2:
suite.addTest(unittest.makeSuite(ReadTestBzip2)) tests.extend([
suite.addTest(unittest.makeSuite(ReadStreamTestBzip2)) ReadTestBzip2, ReadStreamTestBzip2,
suite.addTest(unittest.makeSuite(WriteTestBzip2)) WriteTestBzip2, WriteStreamTestBzip2
suite.addTest(unittest.makeSuite(WriteStreamTestBzip2)) ])
try:
test_support.run_suite(suite) test_support.run_unittest(*tests)
finally: finally:
if gzip: if gzip:
os.remove(tarname("gz")) os.remove(tarname("gz"))

View File

@ -645,10 +645,7 @@ if tempfile.NamedTemporaryFile is not tempfile.TemporaryFile:
test_classes.append(test_TemporaryFile) test_classes.append(test_TemporaryFile)
def test_main(): def test_main():
suite = unittest.TestSuite() test_support.run_unittest(*test_classes)
for c in test_classes:
suite.addTest(unittest.makeSuite(c))
test_support.run_suite(suite)
if __name__ == "__main__": if __name__ == "__main__":
test_main() test_main()

View File

@ -352,11 +352,7 @@ some (including a hanging indent).'''
def test_main(): def test_main():
suite = unittest.TestSuite() test_support.run_unittest(WrapTestCase, LongWordTestCase, IndentTestCases)
suite.addTest(unittest.makeSuite(WrapTestCase))
suite.addTest(unittest.makeSuite(LongWordTestCase))
suite.addTest(unittest.makeSuite(IndentTestCases))
test_support.run_suite(suite)
if __name__ == '__main__': if __name__ == '__main__':
test_main() test_main()

View File

@ -186,10 +186,7 @@ class TimeoutTestCase(unittest.TestCase):
def test_main(): def test_main():
test_support.requires('network') test_support.requires('network')
test_support.run_unittest(CreationTestCase, TimeoutTestCase)
suite = unittest.makeSuite(CreationTestCase)
suite.addTest(unittest.makeSuite(TimeoutTestCase))
test_support.run_suite(suite)
if __name__ == "__main__": if __name__ == "__main__":
test_main() test_main()

View File

@ -531,9 +531,11 @@ class JumpTestCase(unittest.TestCase):
no_jump_without_trace_function() no_jump_without_trace_function()
def test_main(): def test_main():
test_support.run_unittest(TraceTestCase) test_support.run_unittest(
test_support.run_unittest(RaisingTraceFuncTestCase) TraceTestCase,
test_support.run_unittest(JumpTestCase) RaisingTraceFuncTestCase,
JumpTestCase
)
if __name__ == "__main__": if __name__ == "__main__":
test_main() test_main()

View File

@ -138,9 +138,7 @@ class UnicodeNamesTest(unittest.TestCase):
) )
def test_main(): def test_main():
suite = unittest.TestSuite() test_support.run_unittest(UnicodeNamesTest)
suite.addTest(unittest.makeSuite(UnicodeNamesTest))
test_support.run_suite(suite)
if __name__ == "__main__": if __name__ == "__main__":
test_main() test_main()

View File

@ -698,9 +698,7 @@ class UnicodeTest(
print >>out, u'def\n' print >>out, u'def\n'
def test_main(): def test_main():
suite = unittest.TestSuite() test_support.run_unittest(UnicodeTest)
suite.addTest(unittest.makeSuite(UnicodeTest))
test_support.run_suite(suite)
if __name__ == "__main__": if __name__ == "__main__":
test_main() test_main()

View File

@ -203,11 +203,11 @@ class UnicodeMiscTest(UnicodeDatabaseTest):
self.assert_(count >= 10) # should have tested at least the ASCII digits self.assert_(count >= 10) # should have tested at least the ASCII digits
def test_main(): def test_main():
suite = unittest.TestSuite() test.test_support.run_unittest(
suite.addTest(unittest.makeSuite(UnicodeMiscTest)) UnicodeMiscTest,
suite.addTest(unittest.makeSuite(UnicodeMethodsTest)) UnicodeMethodsTest,
suite.addTest(unittest.makeSuite(UnicodeFunctionsTest)) UnicodeFunctionsTest
test.test_support.run_suite(suite) )
if __name__ == "__main__": if __name__ == "__main__":
test_main() test_main()

View File

@ -111,11 +111,13 @@ class TestMixedNewlines(TestGenericUnivNewlines):
def test_main(): def test_main():
test_support.run_unittest(TestNativeNewlines) test_support.run_unittest(
test_support.run_unittest(TestCRNewlines) TestNativeNewlines,
test_support.run_unittest(TestLFNewlines) TestCRNewlines,
test_support.run_unittest(TestCRLFNewlines) TestLFNewlines,
test_support.run_unittest(TestMixedNewlines) TestCRLFNewlines,
TestMixedNewlines
)
if __name__ == '__main__': if __name__ == '__main__':
test_main() test_main()

View File

@ -408,14 +408,14 @@ class Pathname_Tests(unittest.TestCase):
def test_main(): def test_main():
test_suite = unittest.TestSuite() test_support.run_unittest(
test_suite.addTest(unittest.makeSuite(urlopen_FileTests)) urlopen_FileTests,
test_suite.addTest(unittest.makeSuite(urlretrieve_FileTests)) urlretrieve_FileTests,
test_suite.addTest(unittest.makeSuite(QuotingTests)) QuotingTests,
test_suite.addTest(unittest.makeSuite(UnquotingTests)) UnquotingTests,
test_suite.addTest(unittest.makeSuite(urlencode_Tests)) urlencode_Tests,
test_suite.addTest(unittest.makeSuite(Pathname_Tests)) Pathname_Tests
test_support.run_suite(test_suite) )

View File

@ -23,10 +23,7 @@ class URLTimeoutTest(unittest.TestCase):
def test_main(): def test_main():
test_support.requires('network') test_support.requires('network')
test_support.run_unittest(URLTimeoutTest)
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(URLTimeoutTest))
test_support.run_suite(suite)
if __name__ == "__main__": if __name__ == "__main__":
test_main() test_main()

View File

@ -395,11 +395,11 @@ class UserDictMixinTest(TestMappingProtocol):
self.assertEqual(s, t) self.assertEqual(s, t)
def test_main(): def test_main():
suite = unittest.TestSuite() test.test_support.run_unittest(
suite.addTest(unittest.makeSuite(TestMappingProtocol)) TestMappingProtocol,
suite.addTest(unittest.makeSuite(UserDictTest)) UserDictTest,
suite.addTest(unittest.makeSuite(UserDictMixinTest)) UserDictMixinTest
test.test_support.run_suite(suite) )
if __name__ == "__main__": if __name__ == "__main__":
test_main() test_main()

View File

@ -252,9 +252,7 @@ class UserListTest(unittest.TestCase):
self.assertEqual(u, [0, 1, 0, 1, 0, 1]) self.assertEqual(u, [0, 1, 0, 1, 0, 1])
def test_main(): def test_main():
suite = unittest.TestSuite() test.test_support.run_unittest(UserListTest)
suite.addTest(unittest.makeSuite(UserListTest))
test.test_support.run_suite(suite)
if __name__ == "__main__": if __name__ == "__main__":
test_main() test_main()

View File

@ -44,9 +44,7 @@ class UserStringTest(
getattr(object, methodname)(*args) getattr(object, methodname)(*args)
def test_main(): def test_main():
suite = unittest.TestSuite() test_support.run_unittest(UserStringTest)
suite.addTest(unittest.makeSuite(UserStringTest))
test_support.run_suite(suite)
if __name__ == "__main__": if __name__ == "__main__":
test_main() test_main()

View File

@ -534,12 +534,12 @@ class WeakKeyDictionaryTestCase(TestMappingProtocol):
return self.__ref.copy() return self.__ref.copy()
def test_main(): def test_main():
suite = unittest.TestSuite() test_support.run_unittest(
suite.addTest(unittest.makeSuite(ReferencesTestCase)) ReferencesTestCase,
suite.addTest(unittest.makeSuite(MappingTestCase)) MappingTestCase,
suite.addTest(unittest.makeSuite(WeakValueDictionaryTestCase)) WeakValueDictionaryTestCase,
suite.addTest(unittest.makeSuite(WeakKeyDictionaryTestCase)) WeakKeyDictionaryTestCase
test_support.run_suite(suite) )
if __name__ == "__main__": if __name__ == "__main__":

View File

@ -35,12 +35,10 @@ class DumpPickle_LoadCPickle(AbstractPickleTests):
return cPickle.loads(buf) return cPickle.loads(buf)
def test_main(): def test_main():
suite = unittest.TestSuite() test_support.run_unittest(
for test in (DumpCPickle_LoadPickle, DumpCPickle_LoadPickle,
DumpPickle_LoadCPickle, DumpPickle_LoadCPickle
): )
suite.addTest(unittest.makeSuite(test))
test_support.run_suite(suite)
if __name__ == "__main__": if __name__ == "__main__":
test_main() test_main()

View File

@ -187,8 +187,10 @@ class CompressedZipImportTestCase(UncompressedZipImportTestCase):
def test_main(): def test_main():
test_support.run_unittest(UncompressedZipImportTestCase) test_support.run_unittest(
test_support.run_unittest(CompressedZipImportTestCase) UncompressedZipImportTestCase,
CompressedZipImportTestCase
)
if __name__ == "__main__": if __name__ == "__main__":
test_main() test_main()

View File

@ -479,24 +479,24 @@ LAERTES
def test_main(): def test_main():
suite = unittest.TestSuite() test_support.run_unittest(
suite.addTest(unittest.makeSuite(ChecksumTestCase)) ChecksumTestCase,
suite.addTest(unittest.makeSuite(ExceptionTestCase)) ExceptionTestCase,
suite.addTest(unittest.makeSuite(CompressTestCase)) CompressTestCase,
suite.addTest(unittest.makeSuite(CompressObjectTestCase)) CompressObjectTestCase
test_support.run_suite(suite) )
if __name__ == "__main__": if __name__ == "__main__":
test_main() test_main()
def test(tests=''): def test(tests=''):
if not tests: tests = 'o' if not tests: tests = 'o'
suite = unittest.TestSuite() testcases = []
if 'k' in tests: suite.addTest(unittest.makeSuite(ChecksumTestCase)) if 'k' in tests: testcases.append(ChecksumTestCase)
if 'x' in tests: suite.addTest(unittest.makeSuite(ExceptionTestCase)) if 'x' in tests: testcases.append(ExceptionTestCase)
if 'c' in tests: suite.addTest(unittest.makeSuite(CompressTestCase)) if 'c' in tests: testcases.append(CompressTestCase)
if 'o' in tests: suite.addTest(unittest.makeSuite(CompressObjectTestCase)) if 'o' in tests: testcases.append(CompressObjectTestCase)
test_support.run_suite(suite) test_support.run_unittest(*testcases)
if False: if False:
import sys import sys