From f5a80d8cf4143edd7434805a568cc0e7eeaf81c0 Mon Sep 17 00:00:00 2001 From: Steven Knight Date: Tue, 26 Jan 2010 16:26:26 +0000 Subject: Win32 portability in runtest.py tests after disabling QMTest by default. --- QMTest/TestRuntest.py | 8 ++++++++ test/runtest/aegis/batch-output.py | 14 ++++++++++---- test/runtest/baseline/combined.py | 15 +++++++-------- test/runtest/baseline/fail.py | 4 ++-- test/runtest/baseline/no_result.py | 4 ++-- test/runtest/baseline/pass.py | 7 +++++-- test/runtest/fallback.py | 27 ++++----------------------- test/runtest/noqmtest.py | 29 +++++------------------------ test/runtest/print_time.py | 14 +++++++------- test/runtest/python.py | 14 ++++++++++++-- test/runtest/simple/combined.py | 14 +++++++------- test/runtest/simple/fail.py | 4 ++-- test/runtest/simple/no_result.py | 4 ++-- test/runtest/simple/pass.py | 4 ++-- test/runtest/src.py | 8 ++++---- test/runtest/testlistfile.py | 5 +++-- test/runtest/xml/output.py | 26 +++++++++----------------- 17 files changed, 91 insertions(+), 110 deletions(-) diff --git a/QMTest/TestRuntest.py b/QMTest/TestRuntest.py index 08cfb4f..679a6ab 100644 --- a/QMTest/TestRuntest.py +++ b/QMTest/TestRuntest.py @@ -18,6 +18,7 @@ __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" import os import os.path +import re import string import shutil import sys @@ -27,12 +28,19 @@ from TestCommon import __all__ __all__.extend([ 'TestRuntest', 'python', + 'pythonstring', '_python_', ]) python = python_executable _python_ = '"' + python_executable + '"' +if re.search('\s', python): + pythonstring = _python_ +else: + pythonstring = python +pythonstring = string.replace(pythonstring, '\\', '\\\\') + failing_test_template = """\ import sys diff --git a/test/runtest/aegis/batch-output.py b/test/runtest/aegis/batch-output.py index e2f00ee..68bd166 100644 --- a/test/runtest/aegis/batch-output.py +++ b/test/runtest/aegis/batch-output.py @@ -28,8 +28,14 @@ __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" Test writing Aegis batch output to a file. """ +import os + import TestRuntest +test_fail_py = os.path.join('test', 'fail.py') +test_no_result_py = os.path.join('test', 'no_result.py') +test_pass_py = os.path.join('test', 'pass.py') + test = TestRuntest.TestRuntest() test.subdir('test') @@ -50,14 +56,14 @@ test.run(arguments = '-o aegis.out --aegis test', stderr=expect_stderr) expect = """\ test_result = [ - { file_name = "test/fail.py"; + { file_name = "%(test_fail_py)s"; exit_status = 1; }, - { file_name = "test/no_result.py"; + { file_name = "%(test_no_result_py)s"; exit_status = 2; }, - { file_name = "test/pass.py"; + { file_name = "%(test_pass_py)s"; exit_status = 0; }, ]; -""" +""" % locals() # The mode is 'r' (not default 'rb') because QMTest opens the file # description on which we write as non-binary. diff --git a/test/runtest/baseline/combined.py b/test/runtest/baseline/combined.py index 02f3f53..119fc63 100644 --- a/test/runtest/baseline/combined.py +++ b/test/runtest/baseline/combined.py @@ -1,4 +1,3 @@ - #!/usr/bin/env python # # __COPYRIGHT__ @@ -30,11 +29,11 @@ Test a combination of a passing test, failing test, and no-result test with no argument on the command line. """ -import os.path +import os import TestRuntest -python = TestRuntest.python +pythonstring = TestRuntest.pythonstring test_fail_py = os.path.join('test', 'fail.py') test_no_result_py = os.path.join('test', 'no_result.py') test_pass_py = os.path.join('test', 'pass.py') @@ -50,18 +49,18 @@ test.write_no_result_test(['test', 'no_result.py']) test.write_passing_test(['test', 'pass.py']) expect_stdout = """\ -%(python)s -tt test/fail.py +%(pythonstring)s -tt %(test_fail_py)s FAILING TEST STDOUT -%(python)s -tt test/no_result.py +%(pythonstring)s -tt %(test_no_result_py)s NO RESULT TEST STDOUT -%(python)s -tt test/pass.py +%(pythonstring)s -tt %(test_pass_py)s PASSING TEST STDOUT Failed the following test: -\ttest/fail.py +\t%(test_fail_py)s NO RESULT from the following test: -\ttest/no_result.py +\t%(test_no_result_py)s """ % locals() expect_stderr = """\ diff --git a/test/runtest/baseline/fail.py b/test/runtest/baseline/fail.py index fb7265e..baa974a 100644 --- a/test/runtest/baseline/fail.py +++ b/test/runtest/baseline/fail.py @@ -30,7 +30,7 @@ Test how we handle a failing test specified on the command line. import TestRuntest -python = TestRuntest.python +pythonstring = TestRuntest.pythonstring test = TestRuntest.TestRuntest() @@ -39,7 +39,7 @@ test.subdir('test') test.write_failing_test(['test', 'fail.py']) expect_stdout = """\ -%(python)s -tt test/fail.py +%(pythonstring)s -tt test/fail.py FAILING TEST STDOUT """ % locals() diff --git a/test/runtest/baseline/no_result.py b/test/runtest/baseline/no_result.py index 8641c90..8e0d0dd 100644 --- a/test/runtest/baseline/no_result.py +++ b/test/runtest/baseline/no_result.py @@ -30,7 +30,7 @@ Test how we handle a no-results test specified on the command line. import TestRuntest -python = TestRuntest.python +pythonstring = TestRuntest.pythonstring test = TestRuntest.TestRuntest() @@ -39,7 +39,7 @@ test.subdir('test') test.write_no_result_test(['test', 'no_result.py']) expect_stdout = """\ -%(python)s -tt test/no_result.py +%(pythonstring)s -tt test/no_result.py NO RESULT TEST STDOUT """ % locals() diff --git a/test/runtest/baseline/pass.py b/test/runtest/baseline/pass.py index ef3a99e..77cd84d 100644 --- a/test/runtest/baseline/pass.py +++ b/test/runtest/baseline/pass.py @@ -28,9 +28,12 @@ __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" Test how we handle a passing test specified on the command line. """ +import os + import TestRuntest -python = TestRuntest.python +pythonstring = TestRuntest.pythonstring +test_pass_py = os.path.join('test', 'pass.py') test = TestRuntest.TestRuntest() @@ -39,7 +42,7 @@ test.subdir('test') test.write_passing_test(['test', 'pass.py']) expect_stdout = """\ -%(python)s -tt test/pass.py +%(pythonstring)s -tt %(test_pass_py)s PASSING TEST STDOUT """ % locals() diff --git a/test/runtest/fallback.py b/test/runtest/fallback.py index c7354a3..6a971f8 100644 --- a/test/runtest/fallback.py +++ b/test/runtest/fallback.py @@ -30,13 +30,11 @@ if it can't find qmtest on the $PATH. """ import os -import re import string import TestRuntest -python = TestRuntest.python -_python_ = TestRuntest._python_ +pythonstring = TestRuntest.pythonstring test = TestRuntest.TestRuntest(noqmtest=1) @@ -54,33 +52,16 @@ test_fail_py = os.path.join('test', 'fail.py') test_no_result_py = os.path.join('test', 'no_result.py') test_pass_py = os.path.join('test', 'pass.py') -workpath_fail_py = test.workpath(test_fail_py) -workpath_no_result_py = test.workpath(test_no_result_py) -workpath_pass_py = test.workpath(test_pass_py) - test.write_failing_test(test_fail_py) test.write_no_result_test(test_no_result_py) test.write_passing_test(test_pass_py) -if re.search('\s', python): - expect_python = _python_ -else: - expect_python = python - -def escape(s): - return string.replace(s, '\\', '\\\\') - -expect_python = escape(expect_python) -expect_workpath_fail_py = escape(test_fail_py) -expect_workpath_no_result_py = escape(test_no_result_py) -expect_workpath_pass_py = escape(test_pass_py) - expect_stdout = """\ -%(expect_python)s -tt %(expect_workpath_fail_py)s +%(pythonstring)s -tt %(test_fail_py)s FAILING TEST STDOUT -%(expect_python)s -tt %(expect_workpath_no_result_py)s +%(pythonstring)s -tt %(test_no_result_py)s NO RESULT TEST STDOUT -%(expect_python)s -tt %(expect_workpath_pass_py)s +%(pythonstring)s -tt %(test_pass_py)s PASSING TEST STDOUT Failed the following test: diff --git a/test/runtest/noqmtest.py b/test/runtest/noqmtest.py index 2ff4f65..78b021d 100644 --- a/test/runtest/noqmtest.py +++ b/test/runtest/noqmtest.py @@ -29,14 +29,12 @@ Test that the --noqmtest option invokes tests directly via Python, not using qmtest. """ -import os.path -import re +import os import string import TestRuntest -python = TestRuntest.python -_python_ = TestRuntest._python_ +pythonstring = TestRuntest.pythonstring test = TestRuntest.TestRuntest(noqmtest=1) @@ -46,33 +44,16 @@ test_fail_py = os.path.join('test', 'fail.py') test_no_result_py = os.path.join('test', 'no_result.py') test_pass_py = os.path.join('test', 'pass.py') -workpath_fail_py = test.workpath(test_fail_py) -workpath_no_result_py = test.workpath(test_no_result_py) -workpath_pass_py = test.workpath(test_pass_py) - test.write_failing_test(test_fail_py) test.write_no_result_test(test_no_result_py) test.write_passing_test(test_pass_py) -if re.search('\s', python): - expect_python = _python_ -else: - expect_python = python - -def escape(s): - return string.replace(s, '\\', '\\\\') - -expect_python = escape(expect_python) -expect_workpath_fail_py = escape(test_fail_py) -expect_workpath_no_result_py = escape(test_no_result_py) -expect_workpath_pass_py = escape(test_pass_py) - expect_stdout = """\ -%(expect_python)s -tt %(expect_workpath_fail_py)s +%(pythonstring)s -tt %(test_fail_py)s FAILING TEST STDOUT -%(expect_python)s -tt %(expect_workpath_no_result_py)s +%(pythonstring)s -tt %(test_no_result_py)s NO RESULT TEST STDOUT -%(expect_python)s -tt %(expect_workpath_pass_py)s +%(pythonstring)s -tt %(test_pass_py)s PASSING TEST STDOUT Failed the following test: diff --git a/test/runtest/print_time.py b/test/runtest/print_time.py index 54f90fe..e068447 100644 --- a/test/runtest/print_time.py +++ b/test/runtest/print_time.py @@ -29,13 +29,13 @@ Test a combination of a passing test, failing test, and no-result test with no argument on the command line. """ -import os.path +import os import re import TestCmd import TestRuntest -python = TestRuntest.python +pythonstring = re.escape(TestRuntest.pythonstring) test_fail_py = re.escape(os.path.join('test', 'fail.py')) test_no_result_py = re.escape(os.path.join('test', 'no_result.py')) test_pass_py = re.escape(os.path.join('test', 'pass.py')) @@ -51,22 +51,22 @@ test.write_no_result_test(['test', 'no_result.py']) test.write_passing_test(['test', 'pass.py']) expect_stdout = """\ -%(python)s -tt test/fail.py +%(pythonstring)s -tt %(test_fail_py)s FAILING TEST STDOUT Test execution time: \\d+.\\d seconds -%(python)s -tt test/no_result.py +%(pythonstring)s -tt %(test_no_result_py)s NO RESULT TEST STDOUT Test execution time: \\d+.\\d seconds -%(python)s -tt test/pass.py +%(pythonstring)s -tt %(test_pass_py)s PASSING TEST STDOUT Test execution time: \\d+.\\d seconds Total execution time for all tests: \\d+.\\d seconds Failed the following test: -\ttest/fail.py +\t%(test_fail_py)s NO RESULT from the following test: -\ttest/no_result.py +\t%(test_no_result_py)s """ % locals() expect_stderr = """\ diff --git a/test/runtest/python.py b/test/runtest/python.py index e798a53..9579746 100644 --- a/test/runtest/python.py +++ b/test/runtest/python.py @@ -28,7 +28,9 @@ __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" Test that the -P option lets us specify a Python version to use. """ -import os.path +import os +import re +import string if not hasattr(os.path, 'pardir'): os.path.pardir = '..' @@ -44,12 +46,20 @@ head, dir = os.path.split(head) mypython = os.path.join(head, dir, os.path.pardir, dir, python) +def escape(s): + return string.replace(s, '\\', '\\\\') + +if re.search('\s', mypython): + mypythonstring = '"%s"' % escape(mypython) +else: + mypythonstring = escape(mypython) + test.subdir('test') test.write_passing_test(['test', 'pass.py']) expect_stdout = """\ -%(mypython)s -tt test/pass.py +%(mypythonstring)s -tt %(test_pass_py)s PASSING TEST STDOUT """ % locals() diff --git a/test/runtest/simple/combined.py b/test/runtest/simple/combined.py index 6794ea5..6817820 100644 --- a/test/runtest/simple/combined.py +++ b/test/runtest/simple/combined.py @@ -30,13 +30,13 @@ Test a combination of a passing test, failing test, and no-result test with no argument on the command line. """ -import os.path +import os import TestRuntest test = TestRuntest.TestRuntest() -python = TestRuntest.python +pythonstring = TestRuntest.pythonstring test_fail_py = os.path.join('test', 'fail.py') test_no_result_py = os.path.join('test', 'no_result.py') test_pass_py = os.path.join('test', 'pass.py') @@ -50,18 +50,18 @@ test.write_no_result_test(['test', 'no_result.py']) test.write_passing_test(['test', 'pass.py']) expect_stdout = """\ -%(python)s -tt test/fail.py +%(pythonstring)s -tt %(test_fail_py)s FAILING TEST STDOUT -%(python)s -tt test/no_result.py +%(pythonstring)s -tt %(test_no_result_py)s NO RESULT TEST STDOUT -%(python)s -tt test/pass.py +%(pythonstring)s -tt %(test_pass_py)s PASSING TEST STDOUT Failed the following test: -\ttest/fail.py +\t%(test_fail_py)s NO RESULT from the following test: -\ttest/no_result.py +\t%(test_no_result_py)s """ % locals() expect_stderr = """\ diff --git a/test/runtest/simple/fail.py b/test/runtest/simple/fail.py index 4a36c47..36ec0d0 100644 --- a/test/runtest/simple/fail.py +++ b/test/runtest/simple/fail.py @@ -30,7 +30,7 @@ Test how we handle a failing test specified on the command line. import TestRuntest -python = TestRuntest.python +pythonstring = TestRuntest.pythonstring test = TestRuntest.TestRuntest() @@ -39,7 +39,7 @@ test.subdir('test') test.write_failing_test(['test', 'fail.py']) expect_stdout = """\ -%(python)s -tt test/fail.py +%(pythonstring)s -tt test/fail.py FAILING TEST STDOUT """ % locals() diff --git a/test/runtest/simple/no_result.py b/test/runtest/simple/no_result.py index 475c5a8..97dcede 100644 --- a/test/runtest/simple/no_result.py +++ b/test/runtest/simple/no_result.py @@ -30,7 +30,7 @@ Test how we handle a no-results test specified on the command line. import TestRuntest -python = TestRuntest.python +pythonstring = TestRuntest.pythonstring test = TestRuntest.TestRuntest() @@ -39,7 +39,7 @@ test.subdir('test') test.write_no_result_test(['test', 'no_result.py']) expect_stdout = """\ -%(python)s -tt test/no_result.py +%(pythonstring)s -tt test/no_result.py NO RESULT TEST STDOUT """ % locals() diff --git a/test/runtest/simple/pass.py b/test/runtest/simple/pass.py index 873be09..6332e5f 100644 --- a/test/runtest/simple/pass.py +++ b/test/runtest/simple/pass.py @@ -30,7 +30,7 @@ Test how we handle a passing test specified on the command line. import TestRuntest -python = TestRuntest.python +pythonstring = TestRuntest.pythonstring test = TestRuntest.TestRuntest() @@ -39,7 +39,7 @@ test.subdir('test') test.write_passing_test(['test', 'pass.py']) expect_stdout = """\ -%(python)s -tt test/pass.py +%(pythonstring)s -tt test/pass.py PASSING TEST STDOUT """ % locals() diff --git a/test/runtest/src.py b/test/runtest/src.py index 18db972..9136a4d 100644 --- a/test/runtest/src.py +++ b/test/runtest/src.py @@ -29,7 +29,7 @@ Verify that we find tests under the src/ tree only if they end with *Tests.py. """ -import os.path +import os import TestRuntest @@ -38,7 +38,7 @@ test = TestRuntest.TestRuntest() test.subdir(['src'], ['src', 'suite']) -python = TestRuntest.python +pythonstring = TestRuntest.pythonstring src_passTests_py = os.path.join('src', 'passTests.py') src_suite_passTests_py = os.path.join('src', 'suite', 'passTests.py') @@ -51,9 +51,9 @@ test.write_passing_test(['src', 'suite', 'pass.py']) test.write_passing_test(['src', 'suite', 'passTests.py']) expect_stdout = """\ -%(python)s -tt src/passTests.py +%(pythonstring)s -tt %(src_passTests_py)s PASSING TEST STDOUT -%(python)s -tt src/suite/passTests.py +%(pythonstring)s -tt %(src_suite_passTests_py)s PASSING TEST STDOUT """ % locals() diff --git a/test/runtest/testlistfile.py b/test/runtest/testlistfile.py index dc78c29..8836c8e 100644 --- a/test/runtest/testlistfile.py +++ b/test/runtest/testlistfile.py @@ -29,10 +29,11 @@ Test a list of tests to run in a file specified with the -f option. """ import os.path +import re import TestRuntest -python = TestRuntest.python +pythonstring = TestRuntest.pythonstring test_fail_py = os.path.join('test', 'fail.py') test_no_result_py = os.path.join('test', 'no_result.py') test_pass_py = os.path.join('test', 'pass.py') @@ -53,7 +54,7 @@ test.write('t.txt', """\ """ % locals()) expect_stdout = """\ -%(python)s -tt test/pass.py +%(pythonstring)s -tt %(test_pass_py)s PASSING TEST STDOUT """ % locals() diff --git a/test/runtest/xml/output.py b/test/runtest/xml/output.py index 3641d22..c024f37 100644 --- a/test/runtest/xml/output.py +++ b/test/runtest/xml/output.py @@ -28,28 +28,20 @@ __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" Test writing XML output to a file. """ -import os.path +import os import re -import sys +import string import TestCmd import TestRuntest test = TestRuntest.TestRuntest(match = TestCmd.match_re) -python = TestRuntest.python +pythonstring = re.escape(TestRuntest.pythonstring) test_fail_py = re.escape(os.path.join('test', 'fail.py')) test_no_result_py = re.escape(os.path.join('test', 'no_result.py')) test_pass_py = re.escape(os.path.join('test', 'pass.py')) -# sys.stdout and sys.stderr are open non-binary ('w' instead of 'wb') -# so the lines written on Windows are terminated \r\n, not just \n. The -# expressions below use 'cr' as the optional carriage return character. -if sys.platform in ['win32']: - cr = '\r' -else: - cr = '' - test.subdir('test') test.write_fake_scons_source_tree() @@ -65,8 +57,8 @@ test.run(arguments = '-o xml.out --xml test', status=1) expect = """\ - test/fail.py - %(python)s -tt test/fail.py + %(test_fail_py)s + %(pythonstring)s -tt %(test_fail_py)s 1 FAILING TEST STDOUT @@ -75,8 +67,8 @@ expect = """\ - test/no_result.py - %(python)s -tt test/no_result.py + %(test_no_result_py)s + %(pythonstring)s -tt %(test_no_result_py)s 2 NO RESULT TEST STDOUT @@ -85,8 +77,8 @@ expect = """\ - test/pass.py - %(python)s -tt test/pass.py + %(test_pass_py)s + %(pythonstring)s -tt %(test_pass_py)s 0 PASSING TEST STDOUT -- cgit v0.12