Revision: 3849
Author: janne.t.harkonen
Date: Wed Aug 18 23:52:44 2010
Log: Allow variable amount of leading empty cells before ..., issue 609
http://code.google.com/p/robotframework/source/detail?r=3849
Modified:
/trunk/src/robot/parsing/datarow.py
/trunk/src/robot/parsing/tablepopulators.py
=======================================
--- /trunk/src/robot/parsing/datarow.py Tue Aug 17 07:06:38 2010
+++ /trunk/src/robot/parsing/datarow.py Wed Aug 18 23:52:44 2010
@@ -23,6 +23,28 @@
def __init__(self, cells):
self.cells, self.comments = self._parse(cells)
+ def _parse(self, row):
+ data = []
+ comments = []
+ for cell in row:
+ cell = self._collapse_whitespace(cell)
+ if cell.startswith('#') and not comments:
+ comments.append(cell[1:])
+ elif comments:
+ comments.append(cell)
+ else:
+ data.append(cell)
+ return self._purge_empty_cells(data),
self._purge_empty_cells(comments)
+
+ def _collapse_whitespace(self, cell):
+ return self._whitespace_regexp.sub(' ', cell).strip()
+
+ def _purge_empty_cells(self, row):
+ while row and not row[-1]:
+ row.pop()
+ # Cells with only a single backslash are considered empty
+ return [cell if cell != '\\' else '' for cell in row]
+
@property
def head(self):
return self.cells[0] if self.cells else None
@@ -35,6 +57,15 @@
def all(self):
return self.cells
+ @property
+ def data(self):
+ if self.is_continuing():
+ index = self.cells.index(self._row_continuation_marker) + 1
+ return self.cells[index:]
+ if self.starts_test_or_user_keyword_setting():
+ return self.cells[1:]
+ return self.cells
+
def dedent(self):
datarow = DataRow([])
datarow.cells = self.tail
@@ -67,7 +98,11 @@
return self.head == ''
def is_continuing(self):
- return self.head == self._row_continuation_marker
+ for cell in self.cells:
+ if cell == self._row_continuation_marker:
+ return True
+ if cell:
+ return False
def is_commented(self):
return bool(not self.cells and self.comments)
@@ -75,27 +110,5 @@
def test_or_user_keyword_setting_name(self):
return self.head[1:-1].strip()
- def _parse(self, row):
- data = []
- comments = []
- for cell in row:
- cell = self._collapse_whitespace(cell)
- if cell.startswith('#') and not comments:
- comments.append(cell[1:])
- elif comments:
- comments.append(cell)
- else:
- data.append(cell)
- return self._purge_empty_cells(data),
self._purge_empty_cells(comments)
-
- def _collapse_whitespace(self, cell):
- return self._whitespace_regexp.sub(' ', cell).strip()
-
- def _purge_empty_cells(self, row):
- while row and not row[-1]:
- row.pop()
- # Cells with only a single backslash are considered empty
- return [cell if cell != '\\' else '' for cell in row]
-
def __nonzero__(self):
return bool(self.cells or self.comments)
=======================================
--- /trunk/src/robot/parsing/tablepopulators.py Thu Jul 22 04:36:26 2010
+++ /trunk/src/robot/parsing/tablepopulators.py Wed Aug 18 23:52:44 2010
@@ -51,7 +51,10 @@
self._populator.populate()
self._populator = self._get_populator(row)
self._comments.consume_comments_with(self._populator.add)
- self._populator.add(row)
+ if isinstance(self._populator, (SettingPopulator,
VariablePopulator)):
+ self._populator.add(row.dedent())
+ else:
+ self._populator.add(row)
def populate(self):
self._comments.consume_comments_with(self._populator.add)
@@ -75,7 +78,7 @@
class VariableTablePopulator(_TablePopulator):
def _get_populator(self, row):
- return VariablePopulator(self._table.add)
+ return VariablePopulator(self._table.add, row.head)
class _StepContainingTablePopulator(_TablePopulator):
@@ -114,14 +117,14 @@
if not declaration_ready:
return
self._loop = self._for_loop_creator(self._declaration)
- if not (row.is_continuing() or dedented_row.is_continuing()):
+ if not row.is_continuing():
self._populator.populate()
self._populator = StepPopulator(self._loop.add_step)
self._populator.add(dedented_row)
def _populate_declaration(self, row):
if row.starts_for_loop() or row.is_continuing():
- self._declaration.extend(row.tail)
+ self._declaration.extend(row.dedent().data)
return False
return True
@@ -224,20 +227,22 @@
class VariablePopulator(_PropertyPopulator):
+ def __init__(self, setter, name):
+ _PropertyPopulator.__init__(self, setter)
+ self._name = name
+
def _add(self, row):
- if row.is_continuing() and self._value:
- row = row.dedent()
- self._value.extend(row.all)
+ self._value.extend(row.data)
def populate(self):
- name, value = self._value[0], self._value[1:]
- self._setter(name, value, self._comments.formatted_value())
+ self._setter(self._name, self._value,
+ self._comments.formatted_value())
class SettingPopulator(_PropertyPopulator):
def _add(self, row):
- self._value.extend(row.tail)
+ self._value.extend(row.data)
def populate(self):
self._setter(self._value, self._comments.formatted_value())
@@ -246,9 +251,7 @@
class StepPopulator(_PropertyPopulator):
def _add(self, row):
- if row.is_continuing():
- row = row.dedent()
- self._value.extend(row.all)
+ self._value.extend(row.data)
def populate(self):
if self._value or self._comments: