Revision: 3565
Author: jussi.ao.malinen
Date: Wed May 26 07:44:31 2010
Log: refactoring of population
http://code.google.com/p/robotframework/source/detail?r=3565
Added:
/trunk/atest/robot/parsing/failing_init.txt
/trunk/atest/testdata/parsing/failing_init
/trunk/atest/testdata/parsing/failing_init/__init__.txt
/trunk/atest/testdata/parsing/failing_init/failing_init.txt
Modified:
/trunk/src/robot/parsing/datareader.py
/trunk/src/robot/parsing/model.py
/trunk/src/robot/parsing/populator.py
=======================================
--- /dev/null
+++ /trunk/atest/robot/parsing/failing_init.txt Wed May 26 07:44:31 2010
@@ -0,0 +1,11 @@
+*** Settings ***
+Documentation Verify that even if __init__ file fails, the documentation
from that file is available in the suite
+Suite Setup Run Tests ${EMPTY} parsing/failing_init/
+Force Tags regression pybot jybot
+Resource atest_resource.txt
+
+*** Test Cases ***
+Failing Init
+ Should Be Equal ${SUITE.doc} This should exist
+ Check Log Message ${ERRORS.msgs[0]} Test case table not allowed in
test suite init file. ERROR
+ Check Test Case Fail Init
=======================================
--- /dev/null
+++ /trunk/atest/testdata/parsing/failing_init/__init__.txt Wed May 26
07:44:31 2010
@@ -0,0 +1,6 @@
+*** Test Cases ***
+foo Log bar
+
+*** Settings ***
+Documentation This should exist
+Force tags frominit
=======================================
--- /dev/null
+++ /trunk/atest/testdata/parsing/failing_init/failing_init.txt Wed May 26
07:44:31 2010
@@ -0,0 +1,3 @@
+*** Test Cases ***
+Fail Init
+ Log This should be logged
=======================================
--- /trunk/src/robot/parsing/datareader.py Wed May 26 02:31:24 2010
+++ /trunk/src/robot/parsing/datareader.py Wed May 26 07:44:31 2010
@@ -42,17 +42,10 @@
class FromFilePopulator(object):
_null_populator = NullPopulator()
- populators = utils.NormalizedDict({'Setting':
SettingTablePopulator,
- 'Settings':
SettingTablePopulator,
- 'Metadata':
SettingTablePopulator,
- 'Variable':
VariableTablePopulator,
- 'Variables':
VariableTablePopulator,
- 'Test Case': TestTablePopulator,
- 'Test Cases': TestTablePopulator,
- 'Keyword':
KeywordTablePopulator,
- 'Keywords':
KeywordTablePopulator,
- 'User Keyword':
KeywordTablePopulator,
- 'User Keywords':
KeywordTablePopulator})
+ populators = utils.NormalizedDict({'setting':
SettingTablePopulator,
+ 'variable':
VariableTablePopulator,
+ 'testcase': TestTablePopulator,
+ 'keyword':
KeywordTablePopulator})
def __init__(self, datafile):
self._datafile = datafile
@@ -90,9 +83,10 @@
def start_table(self, header):
self._current_populator.populate()
header = DataRow(header)
- try:
- self._current_populator =
self.populators[header.head](self._datafile, header.all)
- except KeyError:
+ 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
@@ -222,7 +216,6 @@
try:
FromFilePopulator(datadir).populate(initfile)
except DataError, err:
- # TODO: Reverse control?
LOGGER.error(unicode(err))
for child in children:
try:
=======================================
--- /trunk/src/robot/parsing/model.py Wed May 26 06:32:21 2010
+++ /trunk/src/robot/parsing/model.py Wed May 26 07:44:31 2010
@@ -37,6 +37,29 @@
self.source = os.path.abspath(source) if source else None
self.children = []
+ def start_table(self, header_row):
+ tables = self._get_tables()
+ try:
+ table = tables[header_row[0]]
+ 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):
if not self.source:
@@ -72,6 +95,19 @@
if not self.testcase_table.is_started():
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})
+
def __iter__(self):
for table in [self.setting_table, self.variable_table,
self.testcase_table, self.keyword_table]:
@@ -164,6 +200,7 @@
class _SettingTable(_Table, _WithSettings):
+ type = 'setting'
def __init__(self, parent):
_Table.__init__(self, parent)
@@ -263,6 +300,7 @@
class VariableTable(_Table):
+ type = 'variable'
def __init__(self, parent):
_Table.__init__(self, parent)
@@ -279,6 +317,7 @@
class TestCaseTable(_Table):
+ type = 'testcase'
def __init__(self, parent):
_Table.__init__(self, parent)
@@ -299,6 +338,7 @@
class KeywordTable(_Table):
+ type = 'keyword'
def __init__(self, parent):
_Table.__init__(self, parent)
=======================================
--- /trunk/src/robot/parsing/populator.py Wed May 26 02:04:27 2010
+++ /trunk/src/robot/parsing/populator.py Wed May 26 07:44:31 2010
@@ -38,9 +38,8 @@
class _TablePopulator(Populator):
- def __init__(self, datafile, header):
+ def __init__(self, datafile):
self._table = self._get_table(datafile)
- self._table.set_header(header)
self._populator = NullPopulator()
self._comments = CommentCacher()