[Python-checkins] cpython: Update various test modules to use unittest.main() for test discovery
brett.cannon
python-checkins at python.org
Thu Jun 13 03:26:10 CEST 2013
http://hg.python.org/cpython/rev/05f7883ee92d
changeset: 84108:05f7883ee92d
user: Brett Cannon <brett at python.org>
date: Wed Jun 12 21:25:59 2013 -0400
summary:
Update various test modules to use unittest.main() for test discovery
instead of manually listing tests for test.support.run_unittest().
files:
Lib/test/test_ast.py | 5 +---
Lib/test/test_asynchat.py | 6 +----
Lib/test/test_buffer.py | 6 +----
Lib/test/test_codeccallbacks.py | 4 +--
Lib/test/test_contextlib.py | 6 +----
Lib/test/test_faulthandler.py | 5 +---
Lib/test/test_fileinput.py | 18 +-------------
Lib/test/test_frozen.py | 4 +--
Lib/test/test_getargs2.py | 26 ++++----------------
Lib/test/test_hashlib.py | 4 +--
Lib/test/test_ioctl.py | 4 +--
Lib/test/test_runpy.py | 9 +------
Lib/test/test_sched.py | 5 +---
Lib/test/test_shutil.py | 6 +----
Lib/test/test_site.py | 4 +--
Lib/test/test_strftime.py | 4 +--
Lib/test/test_sundry.py | 5 +---
Lib/test/test_urllib2net.py | 11 +-------
18 files changed, 24 insertions(+), 108 deletions(-)
diff --git a/Lib/test/test_ast.py b/Lib/test/test_ast.py
--- a/Lib/test/test_ast.py
+++ b/Lib/test/test_ast.py
@@ -951,9 +951,6 @@
compile(mod, fn, "exec")
-def test_main():
- support.run_unittest(AST_Tests, ASTHelpers_Test, ASTValidatorTests)
-
def main():
if __name__ != '__main__':
return
@@ -966,7 +963,7 @@
print("]")
print("main()")
raise SystemExit
- test_main()
+ unittest.main()
#### EVERYTHING BELOW IS GENERATED #####
exec_results = [
diff --git a/Lib/test/test_asynchat.py b/Lib/test/test_asynchat.py
--- a/Lib/test/test_asynchat.py
+++ b/Lib/test/test_asynchat.py
@@ -283,9 +283,5 @@
self.assertEqual(f.pop(), (0, None))
-def test_main(verbose=None):
- support.run_unittest(TestAsynchat, TestAsynchat_WithPoll,
- TestHelperFunctions, TestFifo)
-
if __name__ == "__main__":
- test_main(verbose=True)
+ unittest.main()
diff --git a/Lib/test/test_buffer.py b/Lib/test/test_buffer.py
--- a/Lib/test/test_buffer.py
+++ b/Lib/test/test_buffer.py
@@ -4283,9 +4283,5 @@
self.assertRaises(BufferError, memoryview, x)
-def test_main():
- support.run_unittest(TestBufferProtocol)
-
-
if __name__ == "__main__":
- test_main()
+ unittest.main()
diff --git a/Lib/test/test_codeccallbacks.py b/Lib/test/test_codeccallbacks.py
--- a/Lib/test/test_codeccallbacks.py
+++ b/Lib/test/test_codeccallbacks.py
@@ -875,8 +875,6 @@
with self.assertRaises(TypeError):
data.decode(encoding, "test.replacing")
-def test_main():
- test.support.run_unittest(CodecCallbackTest)
if __name__ == "__main__":
- test_main()
+ unittest.main()
diff --git a/Lib/test/test_contextlib.py b/Lib/test/test_contextlib.py
--- a/Lib/test/test_contextlib.py
+++ b/Lib/test/test_contextlib.py
@@ -617,9 +617,5 @@
'Hello'[50]
-# This is needed to make the test actually run under regrtest.py!
-def test_main():
- support.run_unittest(__name__)
-
if __name__ == "__main__":
- test_main()
+ unittest.main()
diff --git a/Lib/test/test_faulthandler.py b/Lib/test/test_faulthandler.py
--- a/Lib/test/test_faulthandler.py
+++ b/Lib/test/test_faulthandler.py
@@ -588,8 +588,5 @@
self.check_register(chain=True)
-def test_main():
- support.run_unittest(FaultHandlerTests)
-
if __name__ == "__main__":
- test_main()
+ unittest.main()
diff --git a/Lib/test/test_fileinput.py b/Lib/test/test_fileinput.py
--- a/Lib/test/test_fileinput.py
+++ b/Lib/test/test_fileinput.py
@@ -835,22 +835,6 @@
self.assertIs(kwargs.pop('encoding'), encoding)
self.assertFalse(kwargs)
-def test_main():
- run_unittest(
- BufferSizesTests,
- FileInputTests,
- Test_fileinput_input,
- Test_fileinput_close,
- Test_fileinput_nextfile,
- Test_fileinput_filename,
- Test_fileinput_lineno,
- Test_fileinput_filelineno,
- Test_fileinput_fileno,
- Test_fileinput_isfirstline,
- Test_fileinput_isstdin,
- Test_hook_compressed,
- Test_hook_encoded,
- )
if __name__ == "__main__":
- test_main()
+ unittest.main()
diff --git a/Lib/test/test_frozen.py b/Lib/test/test_frozen.py
--- a/Lib/test/test_frozen.py
+++ b/Lib/test/test_frozen.py
@@ -72,8 +72,6 @@
del sys.modules['__phello__']
del sys.modules['__phello__.spam']
-def test_main():
- run_unittest(FrozenTests)
if __name__ == "__main__":
- test_main()
+ unittest.main()
diff --git a/Lib/test/test_getargs2.py b/Lib/test/test_getargs2.py
--- a/Lib/test/test_getargs2.py
+++ b/Lib/test/test_getargs2.py
@@ -1,6 +1,10 @@
import unittest
from test import support
from _testcapi import getargs_keywords, getargs_keyword_only
+try:
+ from _testcapi import getargs_L, getargs_K
+except ImportError:
+ getargs_L = None # PY_LONG_LONG not available
# > How about the following counterproposal. This also changes some of
# > the other format codes to be a little more regular.
@@ -182,6 +186,7 @@
self.assertRaises(OverflowError, getargs_n, VERY_LARGE)
+ at unittest.skipIf(getargs_L is None, 'PY_LONG_LONG is not available')
class LongLong_TestCase(unittest.TestCase):
def test_L(self):
from _testcapi import getargs_L
@@ -534,24 +539,5 @@
self.assertIsNone(getargs_Z_hash(None))
-def test_main():
- tests = [
- Signed_TestCase,
- Unsigned_TestCase,
- Boolean_TestCase,
- Tuple_TestCase,
- Keywords_TestCase,
- KeywordOnly_TestCase,
- Bytes_TestCase,
- Unicode_TestCase,
- ]
- try:
- from _testcapi import getargs_L, getargs_K
- except ImportError:
- pass # PY_LONG_LONG not available
- else:
- tests.append(LongLong_TestCase)
- support.run_unittest(*tests)
-
if __name__ == "__main__":
- test_main()
+ unittest.main()
diff --git a/Lib/test/test_hashlib.py b/Lib/test/test_hashlib.py
--- a/Lib/test/test_hashlib.py
+++ b/Lib/test/test_hashlib.py
@@ -494,8 +494,6 @@
self.assertEqual(expected_hash, hasher.hexdigest())
-def test_main():
- support.run_unittest(HashLibTestCase)
if __name__ == "__main__":
- test_main()
+ unittest.main()
diff --git a/Lib/test/test_ioctl.py b/Lib/test/test_ioctl.py
--- a/Lib/test/test_ioctl.py
+++ b/Lib/test/test_ioctl.py
@@ -86,8 +86,6 @@
os.close(mfd)
os.close(sfd)
-def test_main():
- run_unittest(IoctlTests)
if __name__ == "__main__":
- test_main()
+ unittest.main()
diff --git a/Lib/test/test_runpy.py b/Lib/test/test_runpy.py
--- a/Lib/test/test_runpy.py
+++ b/Lib/test/test_runpy.py
@@ -575,12 +575,5 @@
self.assertEqual(result['s'], "non-ASCII: h\xe9")
-def test_main():
- run_unittest(
- ExecutionLayerTestCase,
- RunModuleTestCase,
- RunPathTestCase
- )
-
if __name__ == "__main__":
- test_main()
+ unittest.main()
diff --git a/Lib/test/test_sched.py b/Lib/test/test_sched.py
--- a/Lib/test/test_sched.py
+++ b/Lib/test/test_sched.py
@@ -197,8 +197,5 @@
self.assertEqual(l, [])
-def test_main():
- support.run_unittest(TestCase)
-
if __name__ == "__main__":
- test_main()
+ unittest.main()
diff --git a/Lib/test/test_shutil.py b/Lib/test/test_shutil.py
--- a/Lib/test/test_shutil.py
+++ b/Lib/test/test_shutil.py
@@ -1719,9 +1719,5 @@
self.assertEqual(expected, actual)
-def test_main():
- support.run_unittest(TestShutil, TestMove, TestCopyFile,
- TermsizeTests, TestWhich)
-
if __name__ == '__main__':
- test_main()
+ unittest.main()
diff --git a/Lib/test/test_site.py b/Lib/test/test_site.py
--- a/Lib/test/test_site.py
+++ b/Lib/test/test_site.py
@@ -401,8 +401,6 @@
else:
self.fail("sitecustomize not imported automatically")
-def test_main():
- run_unittest(HelperFunctionsTests, ImportSideEffectTests)
if __name__ == "__main__":
- test_main()
+ unittest.main()
diff --git a/Lib/test/test_strftime.py b/Lib/test/test_strftime.py
--- a/Lib/test/test_strftime.py
+++ b/Lib/test/test_strftime.py
@@ -176,8 +176,6 @@
(e[0], e[2]))
print(" Expected %s, but got %s" % (e[1], result))
-def test_main():
- support.run_unittest(StrftimeTest)
if __name__ == '__main__':
- test_main()
+ unittest.main()
diff --git a/Lib/test/test_sundry.py b/Lib/test/test_sundry.py
--- a/Lib/test/test_sundry.py
+++ b/Lib/test/test_sundry.py
@@ -54,8 +54,5 @@
print("skipping tty")
-def test_main():
- support.run_unittest(TestUntestedModules)
-
if __name__ == "__main__":
- test_main()
+ unittest.main()
diff --git a/Lib/test/test_urllib2net.py b/Lib/test/test_urllib2net.py
--- a/Lib/test/test_urllib2net.py
+++ b/Lib/test/test_urllib2net.py
@@ -338,13 +338,6 @@
self.assertEqual(u.fp.fp.raw._sock.gettimeout(), 60)
-def test_main():
+if __name__ == "__main__":
support.requires("network")
- support.run_unittest(AuthTests,
- OtherNetworkTests,
- CloseSocketTest,
- TimeoutTest,
- )
-
-if __name__ == "__main__":
- test_main()
+ unittest.main()
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list