Revision: 3376
Author: KariHusa
Date: Fri May 21 03:36:44 2010
Log: Handle also test and userkeyword settings in model
http://code.google.com/p/robotframework/source/detail?r=3376
Modified:
/trunk/src/robot/parsing/datareader.py
/trunk/src/robot/parsing/newmodel.py
/trunk/src/robot/parsing/populator.py
=======================================
--- /trunk/src/robot/parsing/datareader.py Fri May 21 01:31:42 2010
+++ /trunk/src/robot/parsing/datareader.py Fri May 21 03:36:44 2010
@@ -160,6 +160,9 @@
def is_commented(self):
return bool(not self.cells and self.comments)
+ def test_or_user_keyword_setting_name(self):
+ return self.head[1:-1]
+
def _parse(self, row):
return self._purge_empty_cells(self._extract_data(row)), \
self._extract_comments(row)
=======================================
--- /trunk/src/robot/parsing/newmodel.py Fri May 21 02:03:30 2010
+++ /trunk/src/robot/parsing/newmodel.py Fri May 21 03:36:44 2010
@@ -129,7 +129,15 @@
self.parent.report_invalid_syntax(table, message, level)
-class _SettingTable(_Table):
+class _WithSettings(object):
+ def setter_for(self, setting_name):
+ return self._setters[setting_name]
+
+ def is_setting(self, setting_name):
+ return setting_name in self._setters
+
+
+class _SettingTable(_Table, _WithSettings):
def __init__(self, parent):
_Table.__init__(self, parent)
@@ -143,7 +151,7 @@
self.default_tags = Tags()
self.metadata = []
self.imports = []
- self._setting_setters = self._get_setting_setters()
+ self._setters = self._get_setters()
def add_metadata(self, name, value, comment=None):
self.metadata.append(Metadata(self, name, value, comment))
@@ -168,16 +176,10 @@
+ self.metadata + self.imports:
yield setting
- def setter_for(self, setting_name):
- return self._setting_setters[setting_name]
-
- def is_setting(self, setting_name):
- return setting_name in self._setting_setters
-
class TestCaseFileSettingTable(_SettingTable):
- def _get_setting_setters(self):
+ def _get_setters(self):
return utils.NormalizedDict({'Documentation': self.doc.set,
'Document': self.doc.set,
'Suite Setup': self.suite_setup.set,
@@ -205,7 +207,7 @@
class ResourceFileSettingTable(_SettingTable):
- def _get_setting_setters(self):
+ def _get_setters(self):
return utils.NormalizedDict({'Documentation': self.doc.set,
'Document': self.doc.set,
'Library':
ImportSetter(self.add_library),
@@ -214,7 +216,7 @@
class InitFileSettingTable(_SettingTable):
- def _get_setting_setters(self):
+ def _get_setters(self):
return utils.NormalizedDict({'Documentation': self.doc.set,
'Document': self.doc.set,
'Suite Setup': self.suite_setup.set,
@@ -306,7 +308,7 @@
return self.steps[-1]
-class TestCase(_WithSteps):
+class TestCase(_WithSteps, _WithSettings):
def __init__(self, parent, name):
self.parent = parent
@@ -317,6 +319,17 @@
self.teardown = Fixture()
self.timeout = Timeout()
self.steps = []
+ self._setters = self._get_setters()
+
+ def _get_setters(self):
+ return utils.NormalizedDict({'Documentation': self.doc.set,
+ 'Document': self.doc.set,
+ 'Setup': self.setup.set,
+ 'Precondition': self.setup.set,
+ 'Teardown': self.teardown.set,
+ 'Postcondition': self.teardown.set,
+ 'Tags': self.tags.set,
+ 'Timeout': self.timeout.set})
def add_for_loop(self, data):
self.steps.append(ForLoop(data))
@@ -332,6 +345,14 @@
self.return_ = Return()
self.timeout = Timeout()
self.steps = []
+ self._setters = self._get_setters()
+
+ def _get_setters(self):
+ return utils.NormalizedDict({'Documentation': self.doc.set,
+ 'Document': self.doc.set,
+ 'Arguments': self.args.set,
+ 'Return': self.return_.set,
+ 'Timeout': self.timeout.set})
class ForLoop(_WithSteps):
=======================================
--- /trunk/src/robot/parsing/populator.py Fri May 21 01:31:42 2010
+++ /trunk/src/robot/parsing/populator.py Fri May 21 03:36:44 2010
@@ -12,7 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-from robot import utils
from robot.output import LOGGER
@@ -193,7 +192,7 @@
def _get_populator(self, row):
if row.starts_test_or_user_keyword_setting():
- setter = self._setting_setter(row.head)
+ setter = self._setting_setter(row)
return SettingPopulator(setter) if setter else NullPopulator()
if row.starts_for_loop():
return ForLoopPopulator(self._test_or_uk.add_for_loop)
@@ -203,16 +202,13 @@
return row.is_continuing() or \
(isinstance(self._populator, ForLoopPopulator) and
row.is_indented())
- def _setting_setter(self, cell):
- if self._setting_name(cell) in self.attrs_by_name:
- attr_name = self.attrs_by_name[self._setting_name(cell)]
- return getattr(self._test_or_uk, attr_name).set
- self._log_invalid_setting(cell)
+ def _setting_setter(self, row):
+ setting_name = row.test_or_user_keyword_setting_name()
+ if self._test_or_uk.is_setting(setting_name):
+ return self._test_or_uk.setter_for(setting_name)
+ self._log_invalid_setting(row.head)
return None
- def _setting_name(self, cell):
- return cell[1:-1].strip()
-
def _log_invalid_setting(self, value):
report_invalid_setting("'%s' in %s '%s'" % (value, self._item_type,
self._test_or_uk.name))
@@ -220,23 +216,10 @@
class TestCasePopulator(_TestCaseUserKeywordPopulator):
_item_type = 'test case'
- attrs_by_name = utils.NormalizedDict({'Documentation': 'doc',
- 'Document': 'doc',
- 'Setup': 'setup',
- 'Precondition': 'setup',
- 'Teardown': 'teardown',
- 'Postcondition': 'teardown',
- 'Tags': 'tags',
- 'Timeout': 'timeout'})
class UserKeywordPopulator(_TestCaseUserKeywordPopulator):
_item_type = 'keyword'
- attrs_by_name = utils.NormalizedDict({'Documentation': 'doc',
- 'Document': 'doc',
- 'Arguments': 'args',
- 'Return': 'return_',
- 'Timeout': 'timeout'})
class Comments(object):