Revision: 3570
Author: janne.t.harkonen
Date: Thu May 27 02:54:57 2010
Log: Got rid of class
http://code.google.com/p/robotframework/source/detail?r=3570
Modified:
/trunk/src/robot/parsing/datareader.py
/trunk/src/robot/parsing/model.py
=======================================
--- /trunk/src/robot/parsing/datareader.py Thu May 27 00:50:14 2010
+++ /trunk/src/robot/parsing/datareader.py Thu May 27 02:54:57 2010
@@ -81,12 +81,9 @@
def start_table(self, header):
self._current_populator.populate()
- try:
- table = self._datafile.start_table(DataRow(header).all)
- self._current_populator = self._populators[table.type](table)
- except DataError, err:
- LOGGER.error(unicode(err))
- self._current_populator = NullPopulator()
+ table = self._datafile.start_table(DataRow(header).all)
+ self._current_populator = self._populators[table.type](table) \
+ if table is not None else
NullPopulator()
return bool(self._current_populator)
def eof(self):
=======================================
--- /trunk/src/robot/parsing/model.py Thu May 27 00:50:14 2010
+++ /trunk/src/robot/parsing/model.py Thu May 27 02:54:57 2010
@@ -56,13 +56,12 @@
def start_table(self, header_row):
table_name = header_row[0]
try:
- table = self._get_tables()[table_name]
+ table = self._valid_table(self._get_tables()[table_name])
except KeyError:
- raise DataError("Invalid table name '%s'." % table_name)
+ return None
else:
- if isinstance(table, TestCaseTableNotAllowed):
- raise DataError(table.message)
- table.set_header(header_row)
+ if table is not None:
+ table.set_header(header_row)
return table
@property
@@ -100,10 +99,8 @@
if not self.testcase_table.is_started():
raise DataError('File has no test case table.')
- def _get_tables(self):
- tables = _TestData._get_tables(self)
- tables.update({})
- return tables
+ def _valid_table(self, table):
+ return table
def __iter__(self):
for table in [self.setting_table, self.variable_table,
@@ -118,17 +115,12 @@
self.directory = os.path.dirname(self.source) if self.source else
None
self.setting_table = ResourceFileSettingTable(self)
self.variable_table = VariableTable(self)
- self.testcase_table = TestCaseTableNotAllowed('resource file')
+ self.testcase_table = TestCaseTable(self)
self.keyword_table = KeywordTable(self)
if self.source:
FromFilePopulator(self).populate(source)
self._report_status()
- def __iter__(self):
- for table in [self.setting_table, self.variable_table,
- self.keyword_table]:
- yield table
-
def _report_status(self):
if self.setting_table or self.variable_table or self.keyword_table:
LOGGER.info("Imported resource file '%s' (%d keywords)."
@@ -136,6 +128,17 @@
else:
LOGGER.warn("Imported resource file '%s' is empty." %
self.source)
+ def _valid_table(self, table):
+ if table is self.testcase_table:
+ raise DataError('Test case table not allowed in resource
file.')
+ return table
+
+ def __iter__(self):
+ for table in [self.setting_table, self.variable_table,
+ self.keyword_table]:
+ yield table
+
+
class TestDataDirectory(_TestData):
@@ -145,11 +148,17 @@
self.initfile = None
self.setting_table = InitFileSettingTable(self)
self.variable_table = VariableTable(self)
- self.testcase_table = TestCaseTableNotAllowed('test suite init
file')
+ self.testcase_table = TestCaseTable(self)
self.keyword_table = KeywordTable(self)
if self.source:
FromDirectoryPopulator().populate(self.source, self,
include_suites)
+ def _valid_table(self, table):
+ if table is self.testcase_table:
+ LOGGER.error('Test case table not allowed in test suite init
file.')
+ return None
+ return table
+
def add_child(self, path, include_suites):
self.children.append(TestData(parent=self,source=path,
include_suites=include_suites))
@@ -352,21 +361,6 @@
return bool(self.keywords)
-class TestCaseTableNotAllowed(object):
-
- def __init__(self, where):
- self.message = 'Test case table not allowed in %s.' % where
-
- def __getattr__(self, name):
- raise DataError(self.message)
-
- def __nonzero__(self):
- return False
-
- def __iter__(self):
- return iter([])
-
-
class Variable(object):
def __init__(self, name, value, comment=None):