def test_nested_table_in_cell(self): """Test nested table in cell""" inner_table = Table([['1', '2', '3']]) cell = TableCell(inner_table) self.html += ' <h2>Table nested in Cell</h2>\n' body = (' <tbody>\n' ' <tr>\n' ' <td><table class="table table-striped condensed">\n' ' <tbody>\n' ' <tr>\n' ' <td>1</td>\n' ' <td>2</td>\n' ' <td>3</td>\n' ' </tr>\n' ' </tbody>\n' '</table></td>\n' ' </tr>\n' ' </tbody>\n') expected_result = ('%s%s%s' % (self.html_table_start, body, self.html_table_end)) actual_result = Table([[cell]]) message = 'Expected: %s\n\nGot: %s' % (expected_result, actual_result) self.html += str(actual_result) self.writeHtml('table_nested_in_cell') assert expected_result.strip() == str(actual_result).strip(), message
def test_row_span(self): """Testing row spanning""" table_cell_aa = TableCell('aa spanned', row_span=2) table_row1 = TableRow([table_cell_aa, self.table_cell_b, self.table_cell_c, self.table_cell_d]) table_row2 = TableRow([self.table_cell_b, self.table_cell_c, self.table_cell_d]) self.html += ' <h2>Spanning Table Columns</h2>\n' body = (' <tbody>\n' ' <tr>\n' ' <td rowspan="2">aa spanned</td>\n' ' <td>b</td>\n' ' <td>c</td>\n' ' <td>d</td>\n' ' </tr>\n' ' <tr>\n' ' <td>b</td>\n' ' <td>c</td>\n' ' <td>d</td>\n' ' </tr>\n' ' </tbody>\n') expected_result = ('%s%s%s' % (self.html_table_start, body, self.html_table_end)) actual_result = Table([table_row1, table_row2]) message = 'Expected: %s\n\nGot: %s' % (expected_result, actual_result) assert expected_result.strip() == str(actual_result).strip(), message self.html += str(actual_result) self.writeHtml('table_rowspanning')
def test_cell_link(self): """Test cell links work""" table_cell_link = Link('InaSAFE', 'http://inasafe.org') table_row = TableRow([ TableCell(table_cell_link), self.table_cell_b, self.table_cell_c, self.table_cell_d ]) self.html += ' <h2>Link Cell Columns</h2>\n' body = (' <tbody>\n' ' <tr>\n' ' <td><a href="http://inasafe.org">InaSAFE</a></td>\n' ' <td>b</td>\n' ' <td>c</td>\n' ' <td>d</td>\n' ' </tr>\n' ' </tbody>\n') expected_result = ('%s%s%s' % (self.html_table_start, body, self.html_table_end)) actual_result = Table([table_row]) message = 'Expected: %s\n\nGot: %s' % (expected_result, actual_result) assert expected_result.strip() == str(actual_result).strip(), message self.html += str(actual_result) self.writeHtml('table_colspanning')
def setUp(self): """Fixture run before all tests""" self.table_header = ['1', '2', '3', '4'] self.table_data = [ ['a', 'b', 'c', 'd'], ['a', 'b', 'c', 'd'], ['a', 'b', 'c', 'd'], ['a', 'b', 'c', 'd']] self.table_row = TableRow(['a', 'b', 'c', 'd']) self.table_row_data = [self.table_row, self.table_row, self.table_row, self.table_row] self.table_cell_a = TableCell('a') self.table_cell_b = TableCell('b') self.table_cell_c = TableCell('c') self.table_cell_d = TableCell('d') self.table_row_cells = TableRow([self.table_cell_a, self.table_cell_b, self.table_cell_c, self.table_cell_d]) self.table_cell_data = [self.table_row_cells, self.table_row_cells, self.table_row_cells, self.table_row_cells] self.table_caption = 'Man this is a nice table!' self.html_table_start = ('<table class="table table-striped' ' condensed">\n') self.html_table_end = '</table>\n' self.html_caption = (' <caption>Man this is a nice table!</caption>\n') self.html_bottom_caption = (' <caption class="caption-bottom">' 'Man this is a nice table!</caption>\n') self.html_header = (' <thead>\n' ' <tr>\n' ' <th>1</th>\n' ' <th>2</th>\n' ' <th>3</th>\n' ' <th>4</th>\n' ' </tr>\n' ' </thead>\n') self.html_body = (' <tbody>\n' ' <tr>\n' ' <td>a</td>\n' ' <td>b</td>\n' ' <td>c</td>\n' ' <td>d</td>\n' ' </tr>\n' ' <tr>\n' ' <td>a</td>\n' ' <td>b</td>\n' ' <td>c</td>\n' ' <td>d</td>\n' ' </tr>\n' ' <tr>\n' ' <td>a</td>\n' ' <td>b</td>\n' ' <td>c</td>\n' ' <td>d</td>\n' ' </tr>\n' ' <tr>\n' ' <td>a</td>\n' ' <td>b</td>\n' ' <td>c</td>\n' ' <td>d</td>\n' ' </tr>\n' ' </tbody>\n')
def test_table_with_colalign(self): """Table columns can be right justified""" # First with default alignment actual_result = Table(['12', '3000', '5']) expected_strings = ['<td colspan="100%">12</td>', '<td colspan="100%">3000</td>', '<td colspan="100%">5</td>'] for s in expected_strings: message = ('Did not find expected string "%s" in result: %s' % (s, actual_result)) assert s in str(actual_result).strip(), message # Then using explicit alignment (all right justified) # FIXME (Ole): This does not work if e.g. col_align has # different strings: col_align = ['right', 'left', 'center'] actual_result = Table(['12', '3000', '5'], col_align=['right', 'right', 'right']) expected_strings = [ ('<td colspan="100%" align="right" style="text-align: ' 'right;">12</td>'), ('<td colspan="100%" align="right" style="text-align: ' 'right;">3000</td>'), ('<td colspan="100%" align="right" style="text-align: ' 'right;">5</td>')] for s in expected_strings: message = ('Did not find expected string "%s" in result: %s' % (s, actual_result)) assert s in str(actual_result).strip(), message # Now try at the TableRow level # FIXME (Ole): Breaks tables! #row = TableRow(['12', '3000', '5'], # col_align=['right', 'right', 'right']) #actual_result = Table(row) #print actual_result # This breaks too - what's going on? #row = TableRow(['12', '3000', '5']) #actual_result = Table(row) #print actual_result # Try at the cell level cell_1 = TableCell('12') cell_2 = TableCell('3000') cell_3 = TableCell('5') row = TableRow([cell_1, cell_2, cell_3]) #print row # OK table = Table(row) #print table # Broken # Try at the cell level cell_1 = TableCell('12', align='right') cell_2 = TableCell('3000', align='right') cell_3 = TableCell('5', align='right') row = TableRow([cell_1, cell_2, cell_3]) #print row # OK # This is OK for cell in [cell_1, cell_2, cell_3]: msg = 'Wrong cell alignment %s' % cell assert 'align="right"' in str(cell), msg table = Table(row) self.html += str(table) self.writeHtml('table_column_alignment')
def test_cell_header(self): """Test we can make a cell as a <th> element""" cell = TableCell('Foo', header=True) row = TableRow([cell]) table = Table(row) del table