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():
test_support.run_unittest(TestStringIO)
test_support.run_unittest(TestcStringIO)
test_support.run_unittest(TestBufferStringIO)
test_support.run_unittest(TestBuffercStringIO)
test_support.run_unittest(
TestStringIO,
TestcStringIO,
TestBufferStringIO,
TestBuffercStringIO
)
if __name__ == '__main__':
test_main()

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,5 +1,5 @@
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
# 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():
run_unittest(CFunctionCalls)
test_support.run_unittest(CFunctionCalls)
if __name__ == "__main__":

View File

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

View File

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

View File

@ -659,9 +659,7 @@ class CodecCallbackTest(unittest.TestCase):
self.assertRaises(TypeError, u"\xff".translate, {0xff: ()})
def test_main():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(CodecCallbackTest))
test.test_support.run_suite(suite)
test.test_support.run_unittest(CodecCallbackTest)
if __name__ == "__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)))
def test_main():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(UTF16Test))
suite.addTest(unittest.makeSuite(EscapeDecodeTest))
suite.addTest(unittest.makeSuite(RecodingTest))
suite.addTest(unittest.makeSuite(PunycodeTest))
suite.addTest(unittest.makeSuite(NameprepTest))
test_support.run_suite(suite)
test_support.run_unittest(
UTF16Test,
EscapeDecodeTest,
RecodingTest,
PunycodeTest,
NameprepTest
)
if __name__ == "__main__":

View File

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

View File

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

View File

@ -6,7 +6,7 @@ import unittest
from StringIO import StringIO
import csv
import gc
from test.test_support import verbose
from test import test_support
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)
if not hasattr(sys, "gettotalrefcount"):
if verbose: print "*** skipping leakage tests ***"
if test_support.verbose: print "*** skipping leakage tests ***"
else:
class NUL:
def write(s, *args):
@ -640,15 +640,11 @@ else:
# if writer leaks during write, last delta should be 5 or more
self.assertEqual(delta < 5, True)
def _testclasses():
def test_main():
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
test_support.run_unittest(
*[getattr(mod, name) for name in dir(mod) if name.startswith('Test')]
)
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:
print
print "*** Using %s as _thread module ***" % _thread
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(LockTests))
suite.addTest(unittest.makeSuite(MiscTests))
suite.addTest(unittest.makeSuite(ThreadTests))
test_support.run_suite(suite)
test_support.run_unittest(LockTests, MiscTests, ThreadTests)
if __name__ == '__main__':
test_main()

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1193,18 +1193,11 @@ class TestMatchAbbrev(BaseTest):
"ambiguous option: --f (%s?)" % possibilities,
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():
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__':
unittest.main()

View File

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

View File

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

View File

@ -1,9 +1,9 @@
# 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
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:
raise TestSkipped, "test works only on NT+"
raise test_support.TestSkipped, "test works only on NT+"
filenames = [
'abc',
@ -28,11 +28,11 @@ def deltree(dirname):
os.rmdir(dirname)
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):
try:
os.mkdir(TESTFN)
os.mkdir(test_support.TESTFN)
except OSError:
pass
for name in self.files:
@ -42,17 +42,17 @@ class UnicodeFileTests(unittest.TestCase):
os.stat(name)
def tearDown(self):
deltree(TESTFN)
deltree(test_support.TESTFN)
def _apply_failure(self, fn, filename, expected_exception,
check_fn_in_exception = True):
try:
fn(filename)
raise TestFailed("Expected to fail calling '%s(%r)'"
raise test_support.TestFailed("Expected to fail calling '%s(%r)'"
% (fn.__name__, filename))
except expected_exception, details:
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"
% (fn.__name__, filename,
details.filename))
@ -77,9 +77,9 @@ class UnicodeFileTests(unittest.TestCase):
os.stat(name)
def test_listdir(self):
f1 = os.listdir(TESTFN)
f1 = os.listdir(test_support.TESTFN)
f1.sort()
f2 = os.listdir(unicode(TESTFN,"mbcs"))
f2 = os.listdir(unicode(test_support.TESTFN,"mbcs"))
f2.sort()
print f1
print f2
@ -90,7 +90,7 @@ class UnicodeFileTests(unittest.TestCase):
os.rename("tmp",name)
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'
oldwd = os.getcwd()
os.mkdir(dirname)
@ -104,12 +104,10 @@ class UnicodeFileTests(unittest.TestCase):
os.rmdir(dirname)
def test_main():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(UnicodeFileTests))
try:
run_suite(suite)
test_support.run_unittest(UnicodeFileTests)
finally:
deltree(TESTFN)
deltree(test_support.TESTFN)
if __name__ == "__main__":
test_main()

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -121,15 +121,15 @@ class TestProto2MemShelve(TestShelveBase):
_in_mem = True
def test_main():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TestAsciiFileShelve))
suite.addTest(unittest.makeSuite(TestBinaryFileShelve))
suite.addTest(unittest.makeSuite(TestProto2FileShelve))
suite.addTest(unittest.makeSuite(TestAsciiMemShelve))
suite.addTest(unittest.makeSuite(TestBinaryMemShelve))
suite.addTest(unittest.makeSuite(TestProto2MemShelve))
suite.addTest(unittest.makeSuite(TestCase))
test_support.run_suite(suite)
test_support.run_unittest(
TestAsciiFileShelve,
TestBinaryFileShelve,
TestProto2FileShelve,
TestAsciiMemShelve,
TestBinaryMemShelve,
TestProto2MemShelve,
TestCase
)
if __name__ == "__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():
test_support.run_suite(suite())
test_support.run_unittest(TestShutil)
if __name__ == '__main__':
unittest.main(defaultTest='suite')
test_main()

View File

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

View File

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

View File

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

View File

@ -229,15 +229,16 @@ def run_suite(suite, testclass=None):
raise TestFailed(err)
def run_unittest(testclass):
"""Run tests from a unittest.TestCase-derived class."""
run_suite(unittest.makeSuite(testclass), testclass)
def run_classtests(*classnames):
def run_unittest(*classes):
"""Run tests from unittest.TestCase-derived classes."""
suite = unittest.TestSuite()
for cls in classnames:
for cls in classes:
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))
def test_main():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(SysModuleTest))
test.test_support.run_suite(suite)
test.test_support.run_unittest(SysModuleTest)
if __name__ == "__main__":
test_main()

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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