Revision: 97647bb9f493
Author:   Janne Härkönen <[email protected]>
Date:     Mon Dec 19 08:11:10 2011
Log:      writer: handle splitted multi-cell comments properly
http://code.google.com/p/robotframework/source/detail?r=97647bb9f493

Modified:
 /src/robot/writer/tableformatters.py
 /utest/writer/test_formatters.py
 /utest/writer/test_serializer.py

=======================================
--- /src/robot/writer/tableformatters.py        Tue Dec 13 05:25:10 2011
+++ /src/robot/writer/tableformatters.py        Mon Dec 19 08:11:10 2011
@@ -228,12 +228,16 @@


 class RowSplitter(object):
+    _comment_mark = '#'
+    _empty_cell_escape = '${EMPTY}'
+    _line_continuation = '...'

     def __init__(self, padding='', cols=8):
         self._cols = cols
         self._padding = padding

     def split(self, row, indent):
+        self._in_comment = False
         # TODO: encoding does not belong here
         return [self._encode(r) for r in self._split_to_rows(row, indent)]

@@ -245,23 +249,27 @@
             return [[]]
         rows = []
         while data:
-            current, data = self._split(data, indent)
+            current, data = self._split(self._indent(data, indent))
             rows.append(self._escape_last_empty_cell(current))
-            data = self._add_line_continuation(data)
         return rows

-    def _split(self, data, indent):
-        data = self._indent(data, indent)
-        return data[:self._cols], data[self._cols:]
+    def _split(self, data):
+        row, rest = data[:self._cols], data[self._cols:]
+        self._in_comment = any(c for c in row if
+                               c.startswith(self._comment_mark))
+        rest = self._add_line_continuation(rest)
+        return row, rest

     def _escape_last_empty_cell(self, row):
         if not row[-1].strip():
-            row[-1] = '${EMPTY}'
+            row[-1] = self._empty_cell_escape
         return row

     def _add_line_continuation(self, data):
         if data:
-            data = ['...'] + data
+            if self._in_comment:
+                data[0] = self._comment_mark + data[0]
+            data = [self._line_continuation] + data
         return data

     def _indent(self, row, indent):
=======================================
--- /utest/writer/test_formatters.py    Wed Dec 14 23:28:07 2011
+++ /utest/writer/test_formatters.py    Mon Dec 19 08:11:10 2011
@@ -6,7 +6,7 @@
 from robot.utils.asserts import assert_equals


-class TestTxtFormatter(unittest.TestCase):
+class TestRowSplitter(unittest.TestCase):

     def test_escaping_empty_cells_at_eol(self):
         formatter = RowSplitter(cols=3)
@@ -14,7 +14,15 @@
                                        [['Some', 'text', '${EMPTY}'],
                                         ['...', 'with empty']])

-    def test_escaping(self):
+    def test_splitting_inside_comment(self):
+        formatter = RowSplitter(cols=3)
+ assert_equals(formatter.split(['Kw', 'Arg', '#Comment in', 'many cells'], 0), + [['Kw', 'Arg', '#Comment in'], ['...', '#many cells']])
+
+
+class TestTxtFormatter(unittest.TestCase):
+
+   def test_escaping(self):
         formatter = TxtFormatter()
         assert_equals(formatter._escape(['so  me']), ['so \ me'])

=======================================
--- /utest/writer/test_serializer.py    Tue Dec 13 07:01:35 2011
+++ /utest/writer/test_serializer.py    Mon Dec 19 08:11:10 2011
@@ -118,8 +118,6 @@

     def _serializer(self, datafile):
         result= self._serialize(datafile, 'html')
-        with open('foo.html', 'w') as o:
-            o.write(result)
         return result

     def test_serializer_with_html_testcase_file(self):

Reply via email to