예제 #1
0
def test_simple_table():
    table = HtmlTable()
    table.column("Col 1")
    table.column("Col 2")
    assert table.format_table() == (
        '<table class="pure-table"><thead><th>Col 1</th><th>Col 2</th></thead>'
        '<tbody>\n\n</tbody></table>')
예제 #2
0
def test_body():
    table = (HtmlTable().column('Col 1', attrs={
        'class': 'test'
    }).column('Col 2'))
    table.row((1, 2), data_row='1')
    table.row((3, 4), data_row='2')
    html = table.format_table()
    assert html == '<table class="pure-table">' \
                   '<thead><th>Col 1</th><th>Col 2</th></thead><tbody>\n' \
                   '<tr data-row="1"><td class="test">1</td><td>2</td></tr>\n' \
                   '<tr data-row="2"><td class="test">3</td><td>4</td></tr>\n' \
                   '</tbody></table>'
예제 #3
0
def test_format_fun():
    table = HtmlTable().column('Test', format_spec=lambda v: 'Hello ' + str(v))
    assert table._format_column(0, "World") == "<td>Hello World</td>"
예제 #4
0
def test_format_spec():
    table = HtmlTable().column('', format_spec='02d')
    assert table._format_column(0, 1) == '<td>01</td>'
예제 #5
0
def test_format_string():
    table = (HtmlTable().column('Test', format_spec='Val: {:02d}'))
    assert table._format_column(0, 1) == "<td>Val: 01</td>"
예제 #6
0
def test_early_fail_wrong_col_attr():
    table = HtmlTable()
    with pytest.raises(Exception):
        table.column('Col 1', attrs={'class', 'test'})  # set instead of dict
예제 #7
0
def trivial_table():
    trivial_table = HtmlTable()
    trivial_table.column("Test")
    trivial_table.row((1, ))
    return trivial_table
예제 #8
0
def test_header():
    table = (HtmlTable().column("Col 1",
                                data_sortable_type="alpha").column("Col 2"))
    assert table._format_header() == '<table class="pure-table"><thead>' \
                                     '<th data-sortable-type="alpha">Col 1</th>' \
                                     '<th>Col 2</th></thead><tbody>'