Revision: 3420
Author: jprantan
Date: Mon May 24 07:26:21 2010
Log: Added filtering by suite name to parsing to optimize loading time.
http://code.google.com/p/robotframework/source/detail?r=3420
Modified:
/trunk/src/robot/parsing/datareader.py
/trunk/src/robot/parsing/model.py
/trunk/src/robot/running/model.py
=======================================
--- /trunk/src/robot/parsing/datareader.py Mon May 24 05:34:13 2010
+++ /trunk/src/robot/parsing/datareader.py Mon May 24 07:26:21 2010
@@ -217,9 +217,10 @@
ignored_prefixes = ('_', '.')
ignored_dirs = ('CVS',)
- def populate(self, path, datadir):
+ def populate(self, path, datadir, include_suites):
LOGGER.info("Parsing test data directory '%s'" % path)
- initfile, children = self._get_children(path)
+ include_sub_suites = self._get_include_suites(path, include_suites)
+ initfile, children = self._get_children(path, include_sub_suites)
datadir.initfile = initfile
if initfile:
try:
@@ -229,12 +230,19 @@
LOGGER.error(unicode(err))
for child in children:
try:
- datadir.add_child(child)
+ datadir.add_child(child, include_sub_suites)
except DataError, err:
LOGGER.info("Parsing data source '%s' failed: %s"
% (path, unicode(err)))
- def _get_children(self, dirpath):
+ def _get_include_suites(self, path, include_suites):
+ # If directory is included also all it children should be included
+ if
self._is_in_incl_suites(os.path.basename(os.path.normpath(path)),
+ include_suites):
+ return []
+ return include_suites
+
+ def _get_children(self, dirpath, include_suites):
initfile = None
children = []
for name, path in self._list_dir(dirpath):
@@ -243,7 +251,7 @@
initfile = path
else:
LOGGER.error("Ignoring second test suite init
file '%s'." % path)
- elif self._is_ignored(name, path):
+ elif self._is_ignored(name, path, include_suites):
LOGGER.info("Ignoring file or directory '%s'." % name)
else:
children.append(path)
@@ -265,11 +273,21 @@
base, extension = name.lower().rsplit('.', 1)
return base == '__init__' and extension in READERS
- def _is_ignored(self, name, path):
+ def _is_ignored(self, name, path, include_suites):
if name.startswith(self.ignored_prefixes):
return True
if os.path.isdir(path):
return name in self.ignored_dirs
- extension = path.lower().split('.')[-1]
- return extension not in READERS
-
+ base, extension = name.lower().rsplit('.', 1)
+ if extension not in READERS:
+ return True
+ return not self._is_in_incl_suites(base, include_suites)
+
+ def _is_in_incl_suites(self, name, include_suites):
+ if include_suites == []:
+ return True
+ # Match only to the last part of name given like '--suite
parent.child'
+ include_suites = [ incl.split('.')[-1] for incl in include_suites ]
+ name = name.split('__', 1)[-1] # Strip possible prefix
+ return utils.matches_any(name, include_suites, ignore=['_'])
+
=======================================
--- /trunk/src/robot/parsing/model.py Mon May 24 05:12:04 2010
+++ /trunk/src/robot/parsing/model.py Mon May 24 07:26:21 2010
@@ -24,9 +24,9 @@
from datareader import FromFilePopulator, FromDirectoryPopulator
-def TestData(parent=None, source=None):
+def TestData(parent=None, source=None, include_suites=[]):
if os.path.isdir(source):
- return TestDataDirectory(parent, source)
+ return TestDataDirectory(parent, source, include_suites)
return TestCaseFile(parent, source)
@@ -91,7 +91,7 @@
class TestDataDirectory(_TestData):
- def __init__(self, parent=None, source=None):
+ def __init__(self, parent=None, source=None, include_suites=[]):
_TestData.__init__(self, parent, source)
self.directory = self.source
self.initfile = None
@@ -100,10 +100,11 @@
self.testcase_table = TestCaseTableNotAllowed('test suite init
file')
self.keyword_table = KeywordTable(self)
if self.source:
- FromDirectoryPopulator().populate(self.source, self)
-
- def add_child(self, path):
- self.children.append(TestData(parent=self,source=path))
+ FromDirectoryPopulator().populate(self.source, self,
include_suites)
+
+ def add_child(self, path, include_suites):
+ self.children.append(TestData(parent=self,source=path,
+ include_suites=include_suites))
def __iter__(self):
for table in [self.setting_table, self.variable_table,
=======================================
--- /trunk/src/robot/running/model.py Mon May 24 01:27:12 2010
+++ /trunk/src/robot/running/model.py Mon May 24 07:26:21 2010
@@ -34,27 +34,28 @@
def TestSuite(datasources, settings):
datasources = [ utils.normpath(path) for path in datasources ]
- suite_names = settings['SuiteNames']
+ include_suites = settings['SuiteNames']
if not datasources:
raise DataError("No data sources given.")
elif len(datasources) > 1:
suitedatas = []
for datasource in datasources:
try:
- suitedatas.append(_get_directory_or_file_suite(datasource,
suite_names))
+ suitedatas.append(_get_directory_or_file_suite(datasource,
+
include_suites))
except DataError:
pass
# FIXME: needs to be implemented
suite = RunnableMultiTestSuite(suitedatas)
else:
- suitedata = _get_directory_or_file_suite(datasources[0],
suite_names)
+ suitedata = _get_directory_or_file_suite(datasources[0],
include_suites)
suite = RunnableTestSuite(suitedata)
suite.set_options(settings)
return suite
-def _get_directory_or_file_suite(path, suite_names):
+def _get_directory_or_file_suite(path, include_suites):
if os.path.isdir(path):
- return TestDataDirectory(source=path) #FIXME: filter suites: ,
suite_names)
+ return TestDataDirectory(source=path,
include_suites=include_suites)
return TestCaseFile(source=path)
@@ -187,6 +188,7 @@
teardown = tc_data.teardown.is_set() and tc_data.teardown or
self._get_parent_test_teardown(tc_data.parent.parent)
self.teardown = Teardown(teardown.name, teardown.args)
self.tags = self._get_tags(tc_data)
+ #FIXME: Handle parent timeout!!
self.timeout = TestTimeout(tc_data.timeout.value,
tc_data.timeout.message)
self.keywords = Keywords(tc_data.steps)