예제 #1
0
 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')
예제 #2
0
 def test_row_from_string(self):
     """Test row from string - it should span to the table width too"""
     table_row1 = TableRow([self.table_cell_a,
                            self.table_cell_b,
                            self.table_cell_c,
                            self.table_cell_d])
     self.html += '  <h2>Table row from string</h2>\n'
     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 colspan="100%">foobar</td>\n'
             '  </tr>\n'
             '  <tr>\n'
             '   <td colspan="100%">Piet Pompies</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, 'foobar', 'Piet Pompies'])
     message = 'Expected: %s\n\nGot: %s' % (expected_result, actual_result)
     self.html += str(actual_result)
     self.writeHtml('table_row_from_string')
     assert expected_result.strip() == str(actual_result).strip(), message
예제 #3
0
 def test_column(self):
     """Test to retrieve all element in a column.
     """
     table_body = []
     header = TableRow(['header1', 'header2', 'header3', 'header4'],
                       header=True)
     table_body.append(header)
     table_body.append(TableRow([1, 2, 3, 4]))
     table_body.append(TableRow(['a', 'b', 'c', 'd']))
     table_body.append(TableRow(['x', 'y', 'z', 't']))
     myTable = Table(table_body)
     expected_result1 = ['header1', 1, 'a', 'x']
     expected_result2 = [2, 'b', 'y']
     real_result1 = myTable.column(0, True)
     real_result2 = myTable.column(1)
     myMessage1 = "Expected %s but got %s" % (expected_result1,
                                             real_result1)
     myMessage2 = "Expected %s but got %s" % (expected_result2,
                                              real_result2)
     assert expected_result1 == real_result1, myMessage1
     assert expected_result2 == real_result2, myMessage2
예제 #4
0
 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')
예제 #5
0
 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')
예제 #6
0
    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')
예제 #7
0
 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