Commit 9a2730fe authored by Vincent Pelletier's avatar Vincent Pelletier

Add ERP5TypeTestSuite helper classes.

One for automated test lookup.
One for --save/--load support.
parent 759fcd8f
import re, imp, sys, threading, os, shlex, subprocess, shutil import re, imp, sys, threading, os, shlex, subprocess, shutil, glob, random
import traceback import traceback
# The content of this file might be partially moved to an egg # The content of this file might be partially moved to an egg
...@@ -230,6 +230,81 @@ class ERP5TypeTestSuite(TestSuite): ...@@ -230,6 +230,81 @@ class ERP5TypeTestSuite(TestSuite):
+int(groupdict['unexpected_successes'] or 0)) +int(groupdict['unexpected_successes'] or 0))
return status_dict return status_dict
class ProjectTestSuite(ERP5TypeTestSuite):
"""
Helper code to locate all tests in a path list.
To use this class, inherit from it and define the following properties:
_product_list
List of product names to search tests in.
_bt_list
List of bt names to search tests in.
_search_path_list:
List of base paths to search for products & bts.
Defaults to sys.path (upon getTestList execution).
"""
_product_list = ()
_bt_list = ()
_search_path_list = None
def _searchDirectory(path, path_list):
"""
Returns a iterator over directories matching <path> inside directories
given in <path list>.
"""
path = os.path
pjoin = path.join
isdir = path.isdir
return (y for y in (pjoin(x, path) for x in path_list) if isdir(y))
def getTestList(self):
_glob = glob.glob
path = os.path
pjoin = path.join
path_list = self._search_path_list or sys.path
product_test_file_glob = pjoin('tests', 'test*.py')
bt_test_file_glob = pjoin('TestTemplateItem', 'test*.py')
test_file_list = []
extend = test_file_list.extend
for product_dir in self._searchDirectory('product', path_list):
for product_id in self._product_list:
extend(_glob(pjoin(product_dir, product_id, product_test_file_glob)))
for bt_dir in self._searchDirectory('bt5', path_list):
for bt_id in self._bt_list:
extend(_glob(pjoin(bt_dir, bt_id, bt_test_file_glob)))
return [path.splitext(path.basename(name))[0]
for name in test_file_list]
class SavedProjectTestSuite(ERP5TypeTestSuite):
"""
Helper code to use --save/--load to reduce execution time.
To use this class, inherit from it and define the following properties:
_saved_test_id
Name of the test to use for --save execution.
"""
_saved_test_id = None
def __init__(self, *args, **kw):
# Use same portal id for all tests run by current instance
# but keep it (per-run) random.
self._portal_id = 'portal_%i' % (random.randint(0, sys.maxint), )
super(SavedProjectTestSuite, self).__init__(*args, **kw)
def __runUnitTest(self, *args, **kw):
return super(SavedProjectTestSuite, self).runUnitTest(
'--portal_id=' + self._portal_id,
*args, **kw)
def runUnitTest(self, *args, **kw):
return self.__runUnitTest(
'--load',
*args, **kw)
def setup(self):
super(SavedProjectTestSuite, self).setup()
self.__runUnitTest('--save', self._saved_test_id)
class SubprocessError(EnvironmentError): class SubprocessError(EnvironmentError):
def __init__(self, status_dict): def __init__(self, status_dict):
self.status_dict = status_dict self.status_dict = status_dict
......
#!/usr/bin/python2.6 #!/usr/bin/python2.6
import argparse, pprint, socket, sys, time, xmlrpclib import argparse, pprint, socket, sys, time, xmlrpclib
from DummyTaskDistributionTool import DummyTaskDistributionTool from DummyTaskDistributionTool import DummyTaskDistributionTool
from ERP5TypeTestSuite import ERP5TypeTestSuite from ERP5TypeTestSuite import ERP5TypeTestSuite, SavedProjectTestSuite, \
ProjectTestSuite
def makeSuite(node_quantity=None, test_suite=None, revision=None, def makeSuite(node_quantity=None, test_suite=None, revision=None,
db_list=None): db_list=None):
......
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