Exemplo n.º 1
0
def test_alignment():
    table_l = plaintable.Table(data, align='l')
    table_c = plaintable.Table(data, align='c')
    table_r = plaintable.Table(data, align='r')
    assert str(table_l) == ('1     2     3     4\n'
                            '10    11    12    13\n'
                            'a     b     c     d\n'
                            '1.00  2.00  1.50  4.25')
    assert str(table_c) == ('  1     2     3     4   \n'
                            '  10    11    12    13  \n'
                            '  a     b     c     d   \n'
                            ' 1.00  2.00  1.50  4.25 ')
    assert str(table_r) == ('     1     2     3     4\n'
                            '    10    11    12    13\n'
                            '     a     b     c     d\n'
                            '  1.00  2.00  1.50  4.25')
Exemplo n.º 2
0
def test_data_insert():
    table = plaintable.Table(data)
    assert str(table) == ('1     2     3     4\n'
                          '10    11    12    13\n'
                          'a     b     c     d\n'
                          '1.00  2.00  1.50  4.25')
    assert len(table) == 4
    table.insert(0, [5, 10, 20, 40])
    assert len(table) == 5
    assert str(table) == ('5     10    20    40\n'
                          '1     2     3     4\n'
                          '10    11    12    13\n'
                          'a     b     c     d\n'
                          '1.00  2.00  1.50  4.25')
    table.insert(2, ['1', '22', '666666', '333'])
    assert len(table) == 6
    table.headline = headline
    assert str(table) == ('one   two   three   four\n'
                          '----  ----  ------  ----\n'
                          '5     10    20      40\n'
                          '1     2     3       4\n'
                          '1     22    666666  333\n'
                          '10    11    12      13\n'
                          'a     b     c       d\n'
                          '1.00  2.00  1.50    4.25')
    assert len(table) == 6
Exemplo n.º 3
0
def test_data_append():
    table = plaintable.Table(data)
    assert str(table) == ('1     2     3     4\n'
                          '10    11    12    13\n'
                          'a     b     c     d\n'
                          '1.00  2.00  1.50  4.25')
    assert len(table) == 4
    table.append([5, 10, 20, 40])
    assert len(table) == 5
    assert str(table) == ('1     2     3     4\n'
                          '10    11    12    13\n'
                          'a     b     c     d\n'
                          '1.00  2.00  1.50  4.25\n'
                          '5     10    20    40')
    table.append(['1', '22', '666666', '333'])
    assert len(table) == 6
    assert str(table) == ('1     2     3       4\n'
                          '10    11    12      13\n'
                          'a     b     c       d\n'
                          '1.00  2.00  1.50    4.25\n'
                          '5     10    20      40\n'
                          '1     22    666666  333')
    # note column size change
    table.headline = headline
    assert str(table) == ('one   two   three   four\n'
                          '----  ----  ------  ----\n'
                          '1     2     3       4\n'
                          '10    11    12      13\n'
                          'a     b     c       d\n'
                          '1.00  2.00  1.50    4.25\n'
                          '5     10    20      40\n'
                          '1     22    666666  333')
    assert len(table) == 6
Exemplo n.º 4
0
def test_header_padding():
    table = plaintable.Table(data, headline, header_padding=4)
    assert str(table) == (
        'one          two          three          four\n'
        '-----------  -----------  -------------  ------------\n'
        '1            2            3              4\n'
        '10           11           12             13\n'
        'a            b            c              d\n'
        '1.00         2.00         1.50           4.25')
Exemplo n.º 5
0
def test_incremental():

    table = plaintable.Table()
    for row in data:
        table.append(row)
    assert str(table) == ('1     2     3     4\n'
                          '10    11    12    13\n'
                          'a     b     c     d\n'
                          '1.00  2.00  1.50  4.25')
    table.headline = headline
    assert str(table) == ('one   two   three  four\n'
                          '----  ----  -----  ----\n'
                          '1     2     3      4\n'
                          '10    11    12     13\n'
                          'a     b     c      d\n'
                          '1.00  2.00  1.50   4.25')
Exemplo n.º 6
0
def test_padding():
    table = plaintable.Table(data, padding=4)
    assert str(table) == ('1       2       3       4\n'
                          '10      11      12      13\n'
                          'a       b       c       d\n'
                          '1.00    2.00    1.50    4.25')
Exemplo n.º 7
0
def test_float_precision():
    table = plaintable.Table(data, floatprec=4)
    assert str(table) == ('1       2       3       4\n'
                          '10      11      12      13\n'
                          'a       b       c       d\n'
                          '1.0000  2.0000  1.5000  4.2500')
Exemplo n.º 8
0
def test_dates_defaults():
    table = plaintable.Table(dates)
    assert str(table) == ('2000-01-01 00:00\n' '1960-02-02 00:00')
Exemplo n.º 9
0
def test_data_defaults():
    table = plaintable.Table(data)
    assert str(table) == ('1     2     3     4\n'
                          '10    11    12    13\n'
                          'a     b     c     d\n'
                          '1.00  2.00  1.50  4.25')
Exemplo n.º 10
0
def test_wrong_alignment():
    with pytest.raises(ValueError):
        table = plaintable.Table(data, align='fail')
        str(table)