Revision: 09358a36f574
Author: Pekka Klärck
Date: Wed Aug 29 02:05:15 2012
Log: variable table parsing: keep standalone comments standalone
Update issue 1210
Status: Started
I changed parsing logic so that standalone comments (i.e. rows having only
comments) are not added to the next (or previous) variable but kept
standalone. In practice variable table nowadays can have variables that
have no name and no value but only comments.
After this change standalone comments are still written back to disk in
incorrectly. Fixing that will be part of the next commit.
http://code.google.com/p/robotframework/source/detail?r=09358a36f574
Modified:
/src/robot/parsing/model.py
/src/robot/parsing/tablepopulators.py
/src/robot/variables/variables.py
/utest/parsing/test_populator.py
=======================================
--- /src/robot/parsing/model.py Tue Aug 28 13:41:31 2012
+++ /src/robot/parsing/model.py Wed Aug 29 02:05:15 2012
@@ -472,6 +472,9 @@
def is_for_loop(self):
return False
+ def __nonzero__(self):
+ return bool(self.name or ''.join(self.value))
+
class _WithSteps(object):
=======================================
--- /src/robot/parsing/tablepopulators.py Wed Aug 29 00:27:29 2012
+++ /src/robot/parsing/tablepopulators.py Wed Aug 29 02:05:15 2012
@@ -57,10 +57,12 @@
return row.is_commented()
def _add(self, row):
- if not self._is_continuing(row):
+ if self._is_continuing(row):
+ self._consume_comments()
+ else:
self._populator.populate()
self._populator = self._get_populator(row)
- self._comment_cache.consume(self._populator.add)
+ self._consume_standalone_comments()
self._populator.add(row)
def _is_continuing(self, row):
@@ -69,8 +71,14 @@
def _get_populator(self, row):
raise NotImplementedError
- def populate(self):
+ def _consume_comments(self):
self._comment_cache.consume(self._populator.add)
+
+ def _consume_standalone_comments(self):
+ self._consume_comments()
+
+ def populate(self):
+ self._consume_comments()
self._populator.populate()
@@ -93,6 +101,18 @@
def _get_populator(self, row):
return VariablePopulator(self._table.add, row.head)
+ def _consume_standalone_comments(self):
+ self._comment_cache.consume(self._populate_standalone_comment)
+
+ def _populate_standalone_comment(self, comment):
+ populator = self._get_populator(comment)
+ populator.add(comment)
+ populator.populate()
+
+ def populate(self):
+ self._populator.populate()
+ self._consume_standalone_comments()
+
class _StepContainingTablePopulator(_TablePopulator):
=======================================
--- /src/robot/variables/variables.py Tue Mar 6 00:46:30 2012
+++ /src/robot/variables/variables.py Wed Aug 29 02:05:15 2012
@@ -262,6 +262,8 @@
def set_from_variable_table(self, variable_table, overwrite=False):
for variable in variable_table:
+ if not variable:
+ continue
try:
name, value = self._get_var_table_name_and_value(
variable.name, variable.value, variable_table.source)
=======================================
--- /utest/parsing/test_populator.py Thu May 31 00:04:27 2012
+++ /utest/parsing/test_populator.py Wed Aug 29 02:05:15 2012
@@ -78,7 +78,7 @@
tag = self._setting_with(tag_name)
assert_equals(tag.value, exp_value)
- def _assert_variable(self, index, exp_name, exp_value,
exp_comment=None):
+ def _assert_variable(self, index, exp_name, exp_value, exp_comment=[]):
var = self._datafile.variable_table.variables[index]
assert_equals(var.name, exp_name)
assert_equals(var.value, exp_value)
@@ -534,15 +534,19 @@
def test_variable_table(self):
self._create_table('variables', [['${varname}', 'varvalue', '#has
comment'],
+ ['${name}', '# no value'],
['#label', 'A', 'B', 'C'],
['@{items}', '1', '2', '3'],
- ['${ohtervarname}', '##end
comment'],
+ ['${X}', '##end comment'],
['', '', '#comment'],
- ['...', 'otherval'],
+ ['...', 'VAL'],
['#EOT']])
self._assert_variable(0, '${varname}', ['varvalue'], ['# has
comment'])
- self._assert_variable(1, '@{items}', ['1', '2', '3'], ['#
label', 'A', 'B', 'C'])
- self._assert_variable(2, '${ohtervarname}', ['otherval'], ['#end
comment', 'comment', 'EOT'])
+ self._assert_variable(1, '${name}', [''], ['# no value'])
+ self._assert_variable(2, '', [], ['# label', 'A', 'B', 'C'])
+ self._assert_variable(3, '@{items}', ['1', '2', '3'])
+ self._assert_variable(4, '${X}', ['VAL'], ['#end
comment', 'comment'])
+ self._assert_variable(5, '', [], ['# EOT'])
def test_test_case_table(self):
self._create_table('test cases', [['#start of table comment'],