Revision: 94fee341d878
Author:   Robot Framework Developers <[email protected]>
Date:     Mon Jan 30 03:57:40 2012
Log:      writer: do not split rows in any format if there are headers
http://code.google.com/p/robotframework/source/detail?r=94fee341d878

Modified:
 /src/robot/writer/filewriters.py
 /src/robot/writer/formatters.py
 /utest/writer/test_filewriters.py

=======================================
--- /src/robot/writer/filewriters.py    Mon Jan 30 03:07:55 2012
+++ /src/robot/writer/filewriters.py    Mon Jan 30 03:57:40 2012
@@ -57,7 +57,7 @@
     def _write_table(self, table):
         self._write_header(table)
         self._write_rows(self._formatter.format_table(table))
-        self._write_empty_row()
+        self._write_empty_row(table)

     def _write_header(self, table):
         self._write_row(self._formatter.format_header(table))
@@ -66,8 +66,8 @@
         for row in rows:
             self._write_row(row)

-    def _write_empty_row(self):
-        self._write_row(self._formatter.empty_row())
+    def _write_empty_row(self, table):
+        self._write_row(self._formatter.empty_row_after(table))

     def _encode(self, row):
         return row.encode(self._encoding)
=======================================
--- /src/robot/writer/formatters.py     Mon Jan 30 03:07:55 2012
+++ /src/robot/writer/formatters.py     Mon Jan 30 03:57:40 2012
@@ -27,8 +27,8 @@
         self._column_count = column_count
self._extractor = DataExtractor(self._want_names_on_first_content_row)

-    def empty_row(self):
-        return self._format_row([])
+    def empty_row_after(self, table):
+        return self._format_row([], table)

     def format_header(self, table):
         return self._format_row(self._header_for(table))
@@ -40,6 +40,8 @@
         return [self._format_row(r, table) for r in rows]

     def _should_split_rows(self, table):
+        if self._should_align_columns(table):
+            return False
         return True

     def _split_rows(self, rows, table):
@@ -109,11 +111,6 @@
             return aligner.align_row(header)
         return header

-    def _should_split_rows(self, table):
-        if self._should_align_columns(table):
-            return False
-        return True
-
     def _escape(self, row):
         return self._escape_consecutive_whitespace(
             self._escape_empty_cell_from_start(row))
=======================================
--- /utest/writer/test_filewriters.py   Mon Jan 30 03:07:55 2012
+++ /utest/writer/test_filewriters.py   Mon Jan 30 03:57:40 2012
@@ -1,16 +1,41 @@
 import unittest
 from StringIO import StringIO
+from xml.etree.ElementTree import XML

 from robot.parsing import TestCaseFile
 from robot.parsing.model import TestCaseTable
 from robot.utils.asserts import assert_equals


-class TestSpaceSeparatedWriter(unittest.TestCase):
+def create_test_case_file():
+    data = TestCaseFile(source='foo.txt')
+    table = TestCaseTable(data)
+    data.testcase_table = table
+    table.set_header(['test case', 'some', 'and other'])
+    test = table.add('A test')
+    test.add_step(['A kw', 'an arg'])
+    return data
+
+
+class _WriterTestCase(unittest.TestCase):
+
+    def _test_rows_are_not_split_if_there_are_headers(self, format='txt'):
+        output = self._add_long_step_and_save(format)
+        assert_equals(len(output.splitlines()), 4)
+
+    def _add_long_step_and_save(self, format):
+        data = create_test_case_file()
+ data.testcase_table.tests[0].add_step(['A kw', '1', '2', '3', '4', '6', '7', '8'])
+        output = StringIO()
+        data.save(format=format, output=output)
+        return output.getvalue().strip()
+
+
+class TestSpaceSeparatedWriter(_WriterTestCase):

     def test_end_of_line_whitespace_is_removed(self):
         output = StringIO()
-        self._create_test_case_file().save(output=output)
+        create_test_case_file().save(output=output)
         expected = '''
 *** test case ***     some    and other
 A test
@@ -18,12 +43,24 @@
for exp, act in zip(expected.splitlines(), output.getvalue().splitlines()):
             assert_equals(repr(exp), repr(act))

-    def _create_test_case_file(self):
-        data = TestCaseFile(source='foo.txt')
-        table = TestCaseTable(data)
-        data.testcase_table = table
-        table.set_header(['test case', 'some', 'and other'])
-        test = table.add('A test')
-        test.add_step(['A kw', 'an arg'])
-        return data
-
+    def test_rows_are_not_split_if_there_are_headers(self):
+        self._test_rows_are_not_split_if_there_are_headers()
+
+
+class TestTsvWriter(_WriterTestCase):
+
+    def test_rows_are_not_split_if_there_are_headers(self):
+        self._test_rows_are_not_split_if_there_are_headers('tsv')
+
+
+class TestHtmlWriter(_WriterTestCase):
+
+    def test_rows_are_not_split_if_there_are_headers(self):
+        output = self._add_long_step_and_save('html')
+        tree = XML('\n'.join(output.splitlines()[1:]))
+        lines = tree.findall('body/table/tr')
+        assert_equals(len(lines), 4)
+        for l in lines:
+            cols = l.findall('td') or l.findall('th')
+            assert_equals(len(cols), 9)
+

Reply via email to