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

@ -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()