Author: aconway
Date: Thu Jun 26 01:58:37 2014
New Revision: 1605648
URL: http://svn.apache.org/r1605648
Log:
NO-JIRA: Fix python system tests to work on python 2.5.
Modified:
qpid/dispatch/trunk/tests/run.py.in
qpid/dispatch/trunk/tests/run_system_tests.py
qpid/dispatch/trunk/tests/system_test.py
Modified: qpid/dispatch/trunk/tests/run.py.in
URL:
http://svn.apache.org/viewvc/qpid/dispatch/trunk/tests/run.py.in?rev=1605648&r1=1605647&r2=1605648&view=diff
==============================================================================
--- qpid/dispatch/trunk/tests/run.py.in (original)
+++ qpid/dispatch/trunk/tests/run.py.in Thu Jun 26 01:58:37 2014
@@ -117,27 +117,22 @@ def run_path(file_path, run_name=None):
os.execvp(sys.executable, [sys.executable]+sys.argv)
if __name__ == "__main__":
- try:
- if len(sys.argv) == 1:
- print usage
- elif sys.argv[1] == '-m':
- sys.argv = sys.argv[2:]
- runpy.run_module(sys.argv[0], alter_sys=True, run_name="__main__")
- elif sys.argv[1] == '-s':
- sys.argv = sys.argv[2:]
- run_path(sys.argv[0], run_name="__main__")
- elif sys.argv[1] == '--sh':
- for name, value in env_vars.iteritems(): print "%s=%s"%(name,
value)
- print "export %s"%' '.join(env_vars.keys())
- elif sys.argv[1] == '--vg':
- args = with_valgrind(sys.argv[2:])
- os.execvp(args[0], args)
- elif sys.argv[1].startswith('-'):
- print usage
- else:
- args = sys.argv[1:]
- os.execvp(args[0], args)
-
- except Exception, e:
- print "Error in %s: %s"%(" ".join(sys.argv), e)
- sys.exit(1)
+ if len(sys.argv) == 1:
+ print usage
+ elif sys.argv[1] == '-m':
+ sys.argv = sys.argv[2:]
+ runpy.run_module(sys.argv[0], alter_sys=True, run_name="__main__")
+ elif sys.argv[1] == '-s':
+ sys.argv = sys.argv[2:]
+ run_path(sys.argv[0], run_name="__main__")
+ elif sys.argv[1] == '--sh':
+ for name, value in env_vars.iteritems(): print "%s=%s"%(name, value)
+ print "export %s"%' '.join(env_vars.keys())
+ elif sys.argv[1] == '--vg':
+ args = with_valgrind(sys.argv[2:])
+ os.execvp(args[0], args)
+ elif sys.argv[1].startswith('-'):
+ print usage
+ else:
+ args = sys.argv[1:]
+ os.execvp(args[0], args)
Modified: qpid/dispatch/trunk/tests/run_system_tests.py
URL:
http://svn.apache.org/viewvc/qpid/dispatch/trunk/tests/run_system_tests.py?rev=1605648&r1=1605647&r2=1605648&view=diff
==============================================================================
--- qpid/dispatch/trunk/tests/run_system_tests.py (original)
+++ qpid/dispatch/trunk/tests/run_system_tests.py Thu Jun 26 01:58:37 2014
@@ -26,10 +26,18 @@ import os
import sys
from fnmatch import fnmatch
import runpy
-
+import unittest
# Collect all system_tests_*.py scripts in the same directory as this script.
test_dir = os.path.normpath(os.path.dirname(__file__))
-tests = [os.path.splitext(f)[0] for f in os.listdir(test_dir) if fnmatch(f,
"system_tests_*.py")]
+test_modules = [os.path.splitext(f)[0] for f in os.listdir(test_dir) if
fnmatch(f, "system_tests_*.py")]
sys.path = [test_dir] + sys.path # Find test modules in sys.path
+
+# python < 2.7 unittest main won't load tests from modules, so use the loader:
+all_tests = unittest.TestSuite()
+for m in test_modules:
+ tests = unittest.defaultTestLoader.loadTestsFromModule(__import__(m))
+ all_tests.addTest(tests)
+result = unittest.TextTestRunner(verbosity=2).run(all_tests)
+sys.exit(not result.wasSuccessful())
+
sys.argv = ['unittest', '-v'] + tests
-runpy.run_module('unittest', alter_sys=True, run_name="__main__")
Modified: qpid/dispatch/trunk/tests/system_test.py
URL:
http://svn.apache.org/viewvc/qpid/dispatch/trunk/tests/system_test.py?rev=1605648&r1=1605647&r2=1605648&view=diff
==============================================================================
--- qpid/dispatch/trunk/tests/system_test.py (original)
+++ qpid/dispatch/trunk/tests/system_test.py Thu Jun 26 01:58:37 2014
@@ -484,12 +484,13 @@ class Tester(object):
def __init__(self, id, *args, **kwargs):
"""
- @param id: module.class.method
+ @param id: module.class.method or False if no directory should be
created
"""
self.cleanup_list = []
- self.directory = os.path.join(self.root_dir, *id.split('.'))
- os.makedirs(self.directory)
- os.chdir(self.directory)
+ if id: # not id: means don't create a directory.
+ self.directory = os.path.join(self.root_dir, *id.split('.'))
+ os.makedirs(self.directory)
+ os.chdir(self.directory)
def teardown(self):
"""Clean up (tear-down, stop or close) objects recorded via
cleanup()"""
@@ -553,22 +554,27 @@ class TestCase(unittest.TestCase, Tester
def __init__(self, test_method):
unittest.TestCase.__init__(self, test_method)
- Tester.__init__(self, self.id())
+ # Older python will create an instance of TestCase itself as well as
+ # subclasses, we don't want the Tester to create a directory in that
case.
+ Tester.__init__(self, self.__class__ is not TestCase and self.id())
@classmethod
def setUpClass(cls):
- cls.tester = Tester('.'.join([cls.__module__, cls.__name__, 'setup']))
+ # Python < 2.7 will call setUpClass on the system_test.TestCase class
+ # itself as well as the subclasses. Ignore that.
+ if cls is not TestCase:
+ cls.tester = Tester('.'.join([cls.__module__, cls.__name__,
'setUpClass']))
@classmethod
def tearDownClass(cls):
- if inspect.isclass(cls):
+ if inspect.isclass(cls) and cls is not TestCase and hasattr(cls,
'tester'):
cls.tester.teardown()
del cls.tester
def setUp(self):
# Hack to support setUpClass on older python.
# If the class has not already been set up, do it now.
- if not hasattr(self.__class__, 'tester'):
+ if self.__class__ is not TestCase and not hasattr(self.__class__,
'tester'):
self.setUpClass()
def tearDown(self):
@@ -588,10 +594,12 @@ class TestCase(unittest.TestCase, Tester
# Hack to support tearDownClass on older versions of python.
# The default TestLoader sorts tests alphabetically so we insert
# a fake tests that will run last to call tearDownClass.
+ # NOTE: definitely not safe for a parallel test-runner.
if not hasattr(unittest.TestCase, 'setUpClass'):
def test_zzzz_teardown_class(self):
"""Fake test to call tearDownClass"""
- self.__class__._tear_down_class = True
+ if self.__class__ is not TestCase:
+ self.__class__._tear_down_class = True
def assert_fair(self, seq):
avg = sum(seq)/len(seq)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]