예제 #1
0
def test_table():
    rows = [
        ['a', 'b', 'c'],
        ['d', 'e', Link('foo', '/foo')],
    ]
    table = Table(rows, headers=['1', '2', '3'], id='table')

    assert table.html() == textwrap.dedent("""
        <table>
        <thead>
        <tr>
        <th>1</th>
        <th>2</th>
        <th>3</th>
        </tr>
        </thead>
        <tbody>
        <tr>
        <td>a</td>
        <td>b</td>
        <td>c</td>
        </tr>
        <tr>
        <td>d</td>
        <td>e</td>
        <td><a href="/foo">foo</a></td>
        </tr>
        </tbody>
        </table>
    """).strip()

    # Add # characters to stop editors striping eol whitespace!
    assert table.text() == textwrap.dedent("""
        1  2  3   #
        ----------#
        a  b  c   #
        d  e  /foo#
        ----------#

    """).replace('#', '').lstrip()

    id, obj = table._json()
    assert id == 'table'
    assert obj == [
        {'1': 'a', '2': 'b', '3': 'c'},
        {'1': 'd', '2': 'e', '3': {'href': '/foo', 'text': 'foo'}},
    ]

    # special case in json for 2 column tables
    table2 = Table(list(dict(a=1, b=2).items()), id='table')
    assert table2._json() == ('table', {'a': 1, 'b': 2})
예제 #2
0
def test_table():
    rows = [
        ['a', 'b', 'c'],
        ['d', 'e', Link('foo', '/foo')],
    ]
    table = Table(rows, headers=['1', '2', '3'])

    assert table.html() == textwrap.dedent("""
        <table>
        <thead>
        <tr>
        <th>1</th>
        <th>2</th>
        <th>3</th>
        </tr>
        </thead>
        <tbody>
        <tr>
        <td>a</td>
        <td>b</td>
        <td>c</td>
        </tr>
        <tr>
        <td>d</td>
        <td>e</td>
        <td><a href="/foo">foo</a></td>
        </tr>
        </tbody>
        </table>
    """).strip()

    # Add # characters to stop editors striping eol whitespace!
    assert table.text() == textwrap.dedent("""
        1  2  3   #
        ----------#
        a  b  c   #
        d  e  /foo#
        ----------#

    """).replace('#', '').lstrip()
예제 #3
0
def test_table():
    rows = [
        ['a', 'b', 'c'],
        ['d', 'e', Link('foo', '/foo')],
    ]
    table = Table(rows, headers=['1', '2', '3'], id='table')

    assert table.html() == textwrap.dedent("""
        <table>
        <thead>
        <tr>
        <th>1</th>
        <th>2</th>
        <th>3</th>
        </tr>
        </thead>
        <tbody>
        <tr>
        <td>a</td>
        <td>b</td>
        <td>c</td>
        </tr>
        <tr>
        <td>d</td>
        <td>e</td>
        <td><a href="/foo">foo</a></td>
        </tr>
        </tbody>
        </table>
    """).strip()

    # Add # characters to stop editors striping eol whitespace!
    assert table.text() == textwrap.dedent("""
        1  2  3   #
        ----------#
        a  b  c   #
        d  e  /foo#
        ----------#

    """).replace('#', '').lstrip()

    id, obj = table._json()
    assert id == 'table'
    assert obj == [
        {
            '1': 'a',
            '2': 'b',
            '3': 'c'
        },
        {
            '1': 'd',
            '2': 'e',
            '3': {
                'href': '/foo',
                'text': 'foo'
            }
        },
    ]

    # special case in json for 2 column tables
    table2 = Table(list(dict(a=1, b=2).items()), id='table')
    assert table2._json() == ('table', {'a': 1, 'b': 2})