Commit 9240d498 authored by Arnaud Fontaine's avatar Arnaud Fontaine

ERP5TypeLiveTestCase: Remove FS reloader as ZODB Components should be used from now on.

parent a306c7c6
...@@ -162,31 +162,10 @@ class ERP5TypeLiveTestCase(ERP5TypeTestCaseMixin): ...@@ -162,31 +162,10 @@ class ERP5TypeLiveTestCase(ERP5TypeTestCaseMixin):
from Products.ERP5Type.dynamic.component_package import ComponentDynamicPackage from Products.ERP5Type.dynamic.component_package import ComponentDynamicPackage
from Products.ERP5Type.tests.runUnitTest import ERP5TypeTestLoader from Products.ERP5Type.tests.runUnitTest import ERP5TypeTestLoader
class ERP5TypeTestReLoader(ERP5TypeTestLoader): class ERP5TypeLiveTestLoader(ERP5TypeTestLoader):
"""ERP5Type test re-loader supports reloading test modules before """
running them. ERP5Type Live Test loader which allows to load ZODB Components if any
""" """
def __init__(self, filter_test_list=()):
super(ERP5TypeTestReLoader, self).__init__()
if len(filter_test_list):
# do not filter if no filter, otherwise no tests run
self.filter_test_list = filter_test_list
def loadTestsFromNames(self, test_list):
# ERP5TypeTestLoader is monkey-patched into unittest
# so we have to monkeypatch it in turn
if self.filter_test_list is not None:
old_filter_test_list = ERP5TypeTestLoader.filter_test_list
ERP5TypeTestLoader.filter_test_list = self.filter_test_list
try:
return super(ERP5TypeTestReLoader,
self).loadTestsFromNames(test_list)
finally:
# and undo the monkeypatch afterwards
if self.filter_test_list:
ERP5TypeTestLoader.filter_test_list = old_filter_test_list
def loadTestsFromName(self, name, module=None): def loadTestsFromName(self, name, module=None):
""" """
Load the test from the given name from ZODB if it can be imported, Load the test from the given name from ZODB if it can be imported,
...@@ -200,34 +179,13 @@ class ERP5TypeTestReLoader(ERP5TypeTestLoader): ...@@ -200,34 +179,13 @@ class ERP5TypeTestReLoader(ERP5TypeTestLoader):
fromlist=['erp5.component.test'], fromlist=['erp5.component.test'],
level=0) level=0)
except ImportError: except ImportError:
pass raise
else: else:
module = erp5.component.test module = erp5.component.test
return super(ERP5TypeTestReLoader, self).loadTestsFromName(name, return super(ERP5TypeLiveTestLoader, self).loadTestsFromName(name,
module) module)
def loadTestsFromModule(self, module):
"""
If the module is not a ZODB Component, then reload it to consider
modifications on the filesystem
"""
if not isinstance(getattr(module, '__loader__', None),
ComponentDynamicPackage):
reload(module)
return super(ERP5TypeTestReLoader, self).loadTestsFromModule(module)
def loadTestsFromTestCase(self, testCaseClass):
testModule = sys.modules[testCaseClass.__module__]
# Do not reload ERP5TypeTestCase because we patch it nor ZODB Test
# Component as it is reset upon modification anyway
if (testCaseClass is not ERP5TypeTestCase and
not isinstance(getattr(testModule, '__loader__', None),
ComponentDynamicPackage)):
testModule = reload(testModule)
testCaseClass = getattr(testModule, testCaseClass.__name__)
return ERP5TypeTestLoader.loadTestsFromTestCase(self, testCaseClass)
def runLiveTest(test_list, verbosity=1, stream=None, **kw): def runLiveTest(test_list, verbosity=1, stream=None, **kw):
from Products.ERP5Type.tests.runUnitTest import DebugTestResult from Products.ERP5Type.tests.runUnitTest import DebugTestResult
from Products.ERP5Type.tests import backportUnittest from Products.ERP5Type.tests import backportUnittest
...@@ -257,7 +215,7 @@ def runLiveTest(test_list, verbosity=1, stream=None, **kw): ...@@ -257,7 +215,7 @@ def runLiveTest(test_list, verbosity=1, stream=None, **kw):
run_only = kw.get('run_only', ()) run_only = kw.get('run_only', ())
filter_test_list = [re.compile(x).search filter_test_list = [re.compile(x).search
for x in run_only] for x in run_only]
loader = ERP5TypeTestReLoader(filter_test_list) loader = ERP5TypeLiveTestLoader(filter_test_list)
suite = loader.loadTestsFromNames(test_list) suite = loader.loadTestsFromNames(test_list)
output = stream output = stream
if stream is None: if stream is None:
......
...@@ -270,13 +270,16 @@ else: ...@@ -270,13 +270,16 @@ else:
class ERP5TypeTestLoader(unittest.TestLoader): class ERP5TypeTestLoader(unittest.TestLoader):
"""Load test cases from the name passed on the command line. """Load test cases from the name passed on the command line.
""" """
filter_test_list = None
_testMethodPrefix = 'test' _testMethodPrefix = 'test'
testMethodPrefix = property( testMethodPrefix = property(
lambda self: self._testMethodPrefix, lambda self: self._testMethodPrefix,
lambda self, value: None) lambda self, value: None)
def __init__(self, filter_test_list=()):
super(ERP5TypeTestLoader, self).__init__()
self.filter_test_list = filter_test_list
def loadTestsFromName(self, name, module=None): def loadTestsFromName(self, name, module=None):
""" """
This method is here for compatibility with old style arguments: This method is here for compatibility with old style arguments:
...@@ -654,14 +657,9 @@ def runUnitTestList(test_list, verbosity=1, debug=0, run_only=None): ...@@ -654,14 +657,9 @@ def runUnitTestList(test_list, verbosity=1, debug=0, run_only=None):
result = super(DebugTextTestRunner, self)._makeResult() result = super(DebugTextTestRunner, self)._makeResult()
return DebugTestResult(result) return DebugTestResult(result)
TestRunner = DebugTextTestRunner TestRunner = DebugTextTestRunner
loader = ERP5TypeTestLoader() loader = ERP5TypeTestLoader(
if run_only: [re.compile(x).search for x in run_only.split(',')] if run_only else ())
ERP5TypeTestLoader.filter_test_list = [re.compile(x).search for x in
run_only.split(',')]
suite = loader.loadTestsFromNames(test_list) suite = loader.loadTestsFromNames(test_list)
if run_only:
ERP5TypeTestLoader.filter_test_list = None
if node_pid_list is None: if node_pid_list is None:
result = suite() result = suite()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment