diff -r 52797b9b79cf Lib/test/test_regrtest.py --- a/Lib/test/test_regrtest.py Sun Sep 27 11:19:08 2015 +0200 +++ b/Lib/test/test_regrtest.py Sun Sep 27 11:39:28 2015 +0200 @@ -6,13 +6,19 @@ import argparse import faulthandler import getopt import os.path +import re +import sys +import textwrap import unittest from test import libregrtest from test import support +from test.support import script_helper + class ParseArgsTestCase(unittest.TestCase): - - """Test regrtest's argument parsing.""" + """ + Test regrtest's argument parsing, function _parse_args(). + """ def checkError(self, args, msg): with support.captured_stderr() as err, self.assertRaises(SystemExit): @@ -272,5 +278,119 @@ class ParseArgsTestCase(unittest.TestCas self.assertEqual(ns.args, ['foo']) +class ProgramsTestCase(unittest.TestCase): + """ + Test various ways to run the Python test suite. Use options close + to options used on the buildbot. + """ + + NTEST = 4 + TESTCASE = textwrap.dedent(""" + import unittest + + + class NoopTestCase(unittest.TestCase): + def test_noop(self): + pass + + + if __name__ == '__main__': + unittest.main() + """) + + def setUp(self): + path = os.path.dirname(__file__) + path = os.path.normpath(os.path.join(path, '..', '..')) + self.root = os.path.abspath(path) + + # Create NTEST tests doing nothing + self.tests = [] + testdir = os.path.join(self.root, 'Lib', 'test') + for index in range(1, self.NTEST + 1): + name = 'test_noop%s' % index + self.tests.append(name) + path = os.path.join(testdir, name + '.py') + self.addCleanup(support.unlink, path) + # Use 'x' mode to ensure that we do not override existing tests + with open(path, 'x', encoding='utf-8') as fp: + fp.write(self.TESTCASE) + + self.python_args = ['-Wd', '-E', '-bb'] + self.regrtest_args = ['-uall', '-rwW', '--timeout', '3600', '-j4'] + if sys.platform == 'win32': + self.regrtest_args.append('-n') + + def check_line(self, output, regex): + regex = re.compile(r'^' + regex, re.MULTILINE) + self.assertRegex(output, regex) + + def check_output(self, res): + stdout = os.fsdecode(res.out) + self.check_line(stdout, r'Using random seed [0-9]+') + for name in self.tests: + self.check_line(stdout, r'\[[0-9]/[0-9]\] %s$' % name) + self.check_line(stdout, r'All %s tests OK\.$' % self.NTEST) + + def test_script_regrtest(self): + # Lib/test/regrtest.py + script = os.path.join(self.root, 'Lib', 'test', 'regrtest.py') + + args = [*self.python_args, script, *self.regrtest_args, *self.tests] + res = script_helper.assert_python_ok(*args) + self.check_output(res) + + def test_module_test(self): + # -m test + args = [*self.python_args, '-m', 'test', + *self.regrtest_args, *self.tests] + res = script_helper.assert_python_ok(*args) + self.check_output(res) + + def test_module_regrtest(self): + # -m test.regrtest + args = [*self.python_args, '-m', 'test.regrtest', + *self.regrtest_args, *self.tests] + res = script_helper.assert_python_ok(*args) + self.check_output(res) + + def test_module_autotest(self): + # -m test.autotest + args = [*self.python_args, '-m', 'test.autotest', + *self.regrtest_args, *self.tests] + res = script_helper.assert_python_ok(*args) + self.check_output(res) + + def test_module_from_test_autotest(self): + # from test import autotest + code = 'from test import autotest' + args = [*self.python_args, '-c', code, + *self.regrtest_args, *self.tests] + res = script_helper.assert_python_ok(*args) + self.check_output(res) + + def test_script_autotest(self): + # Lib/test/autotest.py + script = os.path.join(self.root, 'Lib', 'test', 'autotest.py') + args = [*self.python_args, script, *self.regrtest_args, *self.tests] + res = script_helper.assert_python_ok(*args) + self.check_output(res) + + def test_tools_script_run_tests(self): + # Tools/scripts/run_tests.py + script = os.path.join(self.root, 'Tools', 'scripts', 'run_tests.py') + res = script_helper.assert_python_ok(script, *self.tests) + self.check_output(res) + + @unittest.skipUnless(sys.platform == 'win32', + 'test.bat is specific to Windows') + def test_tools_buildbot_test(self): + # Tools/buildbot/test.bat + script = os.path.join(self.root, 'Tools', 'buildbot', 'test.bat') + res = script_helper.assert_python_ok(script, *self.tests) + self.check_output(res) + + # FIXME: test PCbuild/rt.bat? + + if __name__ == '__main__': unittest.main()