2 new revisions:
Revision: af5779a68e64
Author: Robot Framework Developers <[email protected]>
Date: Tue Jan 3 04:46:29 2012
Log: HtmlFormatter: support serialization based on custom headers
http://code.google.com/p/robotframework/source/detail?r=af5779a68e64
Revision: 9ebaa855c8cc
Author: Robot Framework Developers <[email protected]>
Date: Tue Jan 3 04:46:37 2012
Log: Automated merge with https://code.google.com/p/robotframework/
http://code.google.com/p/robotframework/source/detail?r=9ebaa855c8cc
==============================================================================
Revision: af5779a68e64
Author: Robot Framework Developers <[email protected]>
Date: Tue Jan 3 04:46:29 2012
Log: HtmlFormatter: support serialization based on custom headers
http://code.google.com/p/robotframework/source/detail?r=af5779a68e64
Modified:
/src/robot/writer/formatters.py
/src/robot/writer/tableformatters.py
/utest/writer/test_formatters.py
=======================================
--- /src/robot/writer/formatters.py Tue Dec 20 05:00:36 2011
+++ /src/robot/writer/formatters.py Tue Jan 3 04:46:29 2012
@@ -13,6 +13,7 @@
# limitations under the License.
import re
+from robot.writer.tableformatters import SingleLineHtmlFormatter
from .tableformatters import (RowSplittingFormatter,
SplittingHtmlFormatter,
ColumnAligner, SettingTableAligner, NameCell, HeaderCell, HtmlCell)
@@ -146,23 +147,46 @@
class HtmlFormatter(_TestDataFileFormatter):
def __init__(self):
- self._cols = 5
- self._formatter = SplittingHtmlFormatter(self._cols)
+ self._default_cols = 5
+ self._cols = self._default_cols
+ self._formatter = SplittingHtmlFormatter(self._default_cols)
def empty_row(self):
return [NameCell('')] + [HtmlCell('') for _ in range(self._cols-1)]
def _setting_table_formatter(self):
+ self._cols = self._default_cols
return self._formatter
def _variable_table_formatter(self):
+ self._cols = self._default_cols
return self._formatter
def _test_table_formatter(self, tests):
- return self._formatter
+ return self._dynamic_width_formatter(tests)
def _keyword_table_formatter(self, keywords):
- return self._formatter
+ return self._dynamic_width_formatter(keywords)
+
+ def _dynamic_width_formatter(self, table):
+ if len(table.header) == 1:
+ self._cols = self._default_cols
+ return SplittingHtmlFormatter(self._cols)
+ self._cols = max(self._max_column_count(table), len(table.header))
+ return SingleLineHtmlFormatter(self._cols)
def header_row(self, table):
- return [HeaderCell(table.header[0], self._cols)]
+ if len(table.header) == 1:
+ return [HeaderCell(table.header[0], self._default_cols)]
+ headers = self._pad_header(table)
+ return [HeaderCell(hdr) for hdr in headers]
+
+ def _pad_header(self, table):
+ return table.header + [''] * (self._max_column_count(table) -
len(table.header))
+
+ def _max_column_count(self, table):
+ count = 0
+ for item in table:
+ for child in item:
+ count = max(count, len(child.as_list()) + 1)
+ return count
=======================================
--- /src/robot/writer/tableformatters.py Thu Dec 22 01:27:59 2011
+++ /src/robot/writer/tableformatters.py Tue Jan 3 04:46:29 2012
@@ -178,6 +178,48 @@
return row + [HtmlCell()] * (self._cols - len(row) - indent)
+class SingleLineHtmlFormatter(_Formatter):
+
+ def __init__(self, cols):
+ self._cols = cols
+
+ def format_indented_table(self, table):
+ items = list(table)
+ for i, item in enumerate(items):
+ rows = list(self._rows_from_item(item, 1))
+ yield self._pad(self._first_row(item, rows[0]))
+ for row in rows[1:]:
+ yield self._pad(row)
+ if i < len(items) - 1:
+ yield self._pad([NameCell()])
+
+ def _pad(self, row):
+ return row + [HtmlCell()] * (self._cols - len(row))
+
+ def _first_row(self, item, row):
+ return [self._format_name(item)] + row[1:]
+
+ def _format_name(self, item):
+ from robot.parsing.model import UserKeyword
+ type_ = 'keyword' if isinstance(item, UserKeyword) else 'test'
+ return AnchorNameCell(item.name, type_)
+
+ def _format_model_item(self, item, indent):
+ if isinstance(item, Documentation):
+ return self._format_documentation(item, indent)
+ data = [''] * indent + item.as_list()
+ return [[NameCell(data[0])] + [HtmlCell(c) for c in data[1:]]]
+
+ def _format_documentation(self, doc, indent):
+ if indent:
+ start = [NameCell(), HtmlCell(doc.setting_name)]
+ value = doc.as_list()[1:]
+ if len(value) == 1:
+ return [start + [DocumentationCell(doc.value, 1)]]
+ return [start + [HtmlCell(v) for v in value]]
+ return [[NameCell(doc.setting_name), DocumentationCell(doc.value,
1)]]
+
+
class HtmlCell(object):
_backslash_matcher = re.compile(r'(\\+)n ')
@@ -224,7 +266,7 @@
class HeaderCell(HtmlCell):
- def __init__(self, name, span):
+ def __init__(self, name, span=1):
HtmlCell.__init__(self, name, {'class': 'name', 'colspan': '%d' %
span},
tag='th')
=======================================
--- /utest/writer/test_formatters.py Tue Dec 20 05:00:36 2011
+++ /utest/writer/test_formatters.py Tue Jan 3 04:46:29 2012
@@ -3,7 +3,7 @@
from robot.writer.formatters import TxtFormatter, HtmlFormatter,
TsvFormatter, PipeFormatter
from robot.writer.tableformatters import RowSplitter, HtmlCell
-from robot.utils.asserts import assert_equals
+from robot.utils.asserts import assert_equals, assert_true
class TestRowSplitter(unittest.TestCase):
@@ -52,11 +52,14 @@
class TestHtmlFormatter(unittest.TestCase):
+ def setUp(self):
+ self._formatter = HtmlFormatter()
+
def test_setting_table_doc(self):
table = TestCaseFileSettingTable(None)
table.set_header('Settings')
table.doc.value = 'Some documentation'
- formatted = list(HtmlFormatter().setting_rows(table))
+ formatted = list(self._formatter.setting_rows(table))
assert_equals(self._rows_to_text(formatted),
[['Documentation', 'Some documentation']])
assert_equals(formatted[0][1].attributes,
@@ -77,7 +80,7 @@
test.doc.value = 'Some doc'
assert_equals(self._rows(table)[0],
['<a name="test_Test">Test</a>', '[Documentation]', 'Some
doc'])
-
assert_equals(list(HtmlFormatter().test_rows(table))[0][2].attributes,
+
assert_equals(list(self._formatter.test_rows(table))[0][2].attributes,
{'colspan': '3', 'class': 'colspan3'})
def test_test_documentation_with_comment(self):
@@ -87,17 +90,58 @@
test.doc._set_comment('a comment')
assert_equals(self._rows(table)[0],
['<a name="test_Test">Test</a>', '[Documentation]', 'Some
doc', '# a comment', ''])
-
assert_equals(list(HtmlFormatter().test_rows(table))[0][2].attributes, {})
+
assert_equals(list(self._formatter.test_rows(table))[0][2].attributes, {})
+
+ def test_testcase_table_custom_headers(self):
+ self._check_header_length([], 1)
+ self._check_header_length(['a', 'b', 'ceee dee'], 4)
+ self._check_header_length(['akjsakjskjd kjsda kdjs'], 2)
+ self._check_header_length([str(i) for i in range(1000)], 1001)
+
+ def test_header_width_matches_widest_row(self):
+ table = self._create_test_table(['h', 'e'])
+ test = table.add('Some test')
+ test.add_step(['kw', 'arg1', 'arg2', 'arg3'])
+ assert_equals(len(self._formatter.header_row(table)), 5)
+
+ def _check_header_length(self, headers, expected_length):
+ table = self._create_test_table(headers)
+ assert_equals(len(self._formatter.header_row(table)),
expected_length)
+
+ def test_testcase_table_header_colspan(self):
+ self._assert_header_colspan([], 5)
+ self._assert_header_colspan(['a', 'b'], 1)
+
+ def _assert_header_colspan(self, header, expected_colspan):
+ table = self._create_test_table(header)
+
assert_equals(self._formatter.header_row(table)[0].attributes['colspan'],
+ str(expected_colspan))
+
+ def test_number_of_columns_is_max_of_header_and_row_widths(self):
+ table = self._create_test_table(['a', 'b'])
+ test = table.add('Test')
+ test.add_step(['Log Many', 'kukka', 'nen'])
+ self._check_row_lengths(table, 4)
+ table = self._create_test_table(['a', 'b', 'c'])
+ test = table.add('Test')
+ test.add_step(['No Operation'])
+ self._check_row_lengths(table, 4)
+
+ def _check_row_lengths(self, table, expected_length):
+ rows = list(self._formatter.test_rows(table))
+ assert_true(len(rows) > 0)
+ for row in rows:
+ assert_equals(len(row), expected_length)
def _rows(self, table):
- return self._rows_to_text(HtmlFormatter().test_rows(table))
+ return self._rows_to_text(self._formatter.test_rows(table))
def _rows_to_text(self, rows):
return [[cell.content for cell in row] for row in rows]
- def _create_test_table(self):
+ def _create_test_table(self, additional_headers=[]):
table = TestCaseTable(None)
- table.set_header('Test Cases')
+ table.set_header(['Test Cases'] + additional_headers)
return table
def test_add_br_to_newlines(self):
==============================================================================
Revision: 9ebaa855c8cc
Author: Robot Framework Developers <[email protected]>
Date: Tue Jan 3 04:46:37 2012
Log: Automated merge with https://code.google.com/p/robotframework/
http://code.google.com/p/robotframework/source/detail?r=9ebaa855c8cc