Revision: 3568
Author: janne.t.harkonen
Date: Thu May 27 00:50:14 2010
Log: cleanup
http://code.google.com/p/robotframework/source/detail?r=3568
Modified:
/trunk/src/robot/parsing/datareader.py
/trunk/src/robot/parsing/model.py
/trunk/src/robot/parsing/populator.py
=======================================
--- /trunk/src/robot/parsing/datareader.py Wed May 26 07:44:31 2010
+++ /trunk/src/robot/parsing/datareader.py Thu May 27 00:50:14 2010
@@ -41,15 +41,14 @@
class FromFilePopulator(object):
- _null_populator = NullPopulator()
- populators = utils.NormalizedDict({'setting':
SettingTablePopulator,
- 'variable':
VariableTablePopulator,
- 'testcase': TestTablePopulator,
- 'keyword':
KeywordTablePopulator})
+ _populators = {'setting': SettingTablePopulator,
+ 'variable': VariableTablePopulator,
+ 'testcase': TestTablePopulator,
+ 'keyword': KeywordTablePopulator}
def __init__(self, datafile):
self._datafile = datafile
- self._current_populator = self._null_populator
+ self._current_populator = NullPopulator()
self._curdir = self._get_curdir(datafile.directory)
def _get_curdir(self, path):
@@ -82,13 +81,13 @@
def start_table(self, header):
self._current_populator.populate()
- header = DataRow(header)
- table = self._datafile.start_table(header.all)
- if table is not None:
- self._current_populator =
self.populators[table.type](self._datafile)
- else:
- self._current_populator = self._null_populator
- return self._current_populator is not self._null_populator
+ 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()
+ return bool(self._current_populator)
def eof(self):
self._current_populator.populate()
=======================================
--- /trunk/src/robot/parsing/model.py Wed May 26 07:44:31 2010
+++ /trunk/src/robot/parsing/model.py Thu May 27 00:50:14 2010
@@ -36,29 +36,34 @@
self.parent = parent
self.source = os.path.abspath(source) if source else None
self.children = []
+ self._tables = None
+
+ def _get_tables(self):
+ if not self._tables:
+ self._tables = utils.NormalizedDict({'Setting':
self.setting_table,
+ 'Settings':
self.setting_table,
+ 'Metadata':
self.setting_table,
+ 'Variable':
self.variable_table,
+ 'Variables':
self.variable_table,
+ 'Keyword':
self.keyword_table,
+ 'Keywords':
self.keyword_table,
+ 'User Keyword':
self.keyword_table,
+ 'User Keywords':
self.keyword_table,
+ 'Test Case':
self.testcase_table,
+ 'Test Cases':
self.testcase_table})
+ return self._tables
def start_table(self, header_row):
- tables = self._get_tables()
+ table_name = header_row[0]
try:
- table = tables[header_row[0]]
+ table = self._get_tables()[table_name]
+ except KeyError:
+ raise DataError("Invalid table name '%s'." % table_name)
+ else:
+ if isinstance(table, TestCaseTableNotAllowed):
+ raise DataError(table.message)
table.set_header(header_row)
return table
- except KeyError:
- # FIXME: This is not handled
- if utils.normalize(header_row[0]) == 'testcases':
- LOGGER.error('Test case table not allowed in test suite
init file.')
- return None
-
- def _get_tables(self):
- return utils.NormalizedDict({'Setting': self.setting_table,
- 'Settings': self.setting_table,
- 'Metadata': self.setting_table,
- 'Variable': self.variable_table,
- 'Variables': self.variable_table,
- 'Keyword': self.keyword_table,
- 'Keywords': self.keyword_table,
- 'User Keyword': self.keyword_table,
- 'User Keywords': self.keyword_table})
@property
def name(self):
@@ -96,17 +101,9 @@
raise DataError('File has no test case table.')
def _get_tables(self):
- return utils.NormalizedDict({'Setting': self.setting_table,
- 'Settings': self.setting_table,
- 'Metadata': self.setting_table,
- 'Variable': self.variable_table,
- 'Variables': self.variable_table,
- 'Test Case': self.testcase_table,
- 'Test Cases': self.testcase_table,
- 'Keyword': self.keyword_table,
- 'Keywords': self.keyword_table,
- 'User Keyword': self.keyword_table,
- 'User Keywords': self.keyword_table})
+ tables = _TestData._get_tables(self)
+ tables.update({})
+ return tables
def __iter__(self):
for table in [self.setting_table, self.variable_table,
=======================================
--- /trunk/src/robot/parsing/populator.py Wed May 26 07:44:31 2010
+++ /trunk/src/robot/parsing/populator.py Thu May 27 00:50:14 2010
@@ -38,8 +38,8 @@
class _TablePopulator(Populator):
- def __init__(self, datafile):
- self._table = self._get_table(datafile)
+ def __init__(self, table):
+ self._table = table
self._populator = NullPopulator()
self._comments = CommentCacher()
@@ -66,9 +66,6 @@
class SettingTablePopulator(_TablePopulator):
- def _get_table(self, datafile):
- return datafile.setting_table
-
def _get_populator(self, row):
row.handle_old_style_metadata()
setter = self._table.get_setter(row.head)
@@ -77,9 +74,6 @@
class VariableTablePopulator(_TablePopulator):
- def _get_table(self, datafile):
- return datafile.variable_table
-
def _get_populator(self, row):
return VariablePopulator(self._table.add)
@@ -95,18 +89,12 @@
class TestTablePopulator(_StepContainingTablePopulator):
- def _get_table(self, datafile):
- return datafile.testcase_table
-
def _get_populator(self, row):
return TestCasePopulator(self._table.add)
class KeywordTablePopulator(_StepContainingTablePopulator):
- def _get_table(self, datafile):
- return datafile.keyword_table
-
def _get_populator(self, row):
return UserKeywordPopulator(self._table.add)