Exemplo n.º 1
0
def test_rtl():
    """Test with RTL characters."""
    table_data = [
        [u'RTL'],
        [u'שלום'],
        [u'معرب'],
    ]
    table = BaseTable(table_data)
    actual = table.unicode_table(encoding='utf-8')

    expected = ('+------+\n'
                '| RTL  |\n'
                '+------+\n'
                '| שלום |\n'
                '| معرب |\n'
                '+------+')

    assert actual == expected
Exemplo n.º 2
0
def test_cjk():
    """Test with CJK characters."""
    table_data = [
        [u'CJK'],
        [u'蓝色'],
        [u'世界你好'],
    ]
    table = BaseTable(table_data)
    actual = table.unicode_table(encoding='utf-8')

    expected = ('+----------+\n'
                '| CJK      |\n'
                '+----------+\n'
                '| 蓝色     |\n'
                '| 世界你好 |\n'
                '+----------+')

    assert actual == expected
Exemplo n.º 3
0
def test_bool_none():
    """Test with NoneType/boolean instead of strings."""
    table_data = [
        [True, False, None],
        [True, False, None],
        [False, None, True],
        [None, True, False],
    ]
    table = BaseTable(table_data, True)
    actual = table.unicode_table()

    expected = ('+True---+-------+-------+\n'
                '| True  | False | None  |\n'
                '+-------+-------+-------+\n'
                '| True  | False | None  |\n'
                '| False | None  | True  |\n'
                '| None  | True  | False |\n'
                '+-------+-------+-------+')

    assert actual == expected
Exemplo n.º 4
0
def test_float():
    """Test with floats instead of strings."""
    table_data = [
        [1.0, 22.0, 333.0],
        [0.1, 3.1, 6.1],
        [1.1, 4.1, 7.1],
        [2.1, 5.1, 8.1],
    ]
    table = BaseTable(table_data, 0.12345678)
    actual = table.unicode_table()

    expected = ('+0.12345678--+-------+\n'
                '| 1.0 | 22.0 | 333.0 |\n'
                '+-----+------+-------+\n'
                '| 0.1 | 3.1  | 6.1   |\n'
                '| 1.1 | 4.1  | 7.1   |\n'
                '| 2.1 | 5.1  | 8.1   |\n'
                '+-----+------+-------+')

    assert actual == expected
Exemplo n.º 5
0
def test_int():
    """Test with integers instead of strings."""
    table_data = [
        [100, 10, 1],
        [0, 3, 6],
        [1, 4, 7],
        [2, 5, 8],
    ]
    table = BaseTable(table_data, 1234567890)
    actual = table.unicode_table()

    expected = ('+1234567890+---+\n'
                '| 100 | 10 | 1 |\n'
                '+-----+----+---+\n'
                '| 0   | 3  | 6 |\n'
                '| 1   | 4  | 7 |\n'
                '| 2   | 5  | 8 |\n'
                '+-----+----+---+')

    assert actual == expected
Exemplo n.º 6
0
def test_rtl_large():
    """Test large table of RTL characters."""
    table_data = [
        [u'اكتب', u'اللون', u'اسم'],
        [u'البندق', u'أخضر', u'أفوكادو'],
        [u'ثمرة', u'أحمر', u'بندورة'],
        [u'الخضروات', u'أخضر', u'الخس'],
    ]
    table = BaseTable(table_data, u'جوجل المترجم')
    actual = table.unicode_table(encoding='utf-8')

    expected = ('+جوجل المترجم------+---------+\n'
                '| اكتب     | اللون | اسم     |\n'
                '+----------+-------+---------+\n'
                '| البندق   | أخضر  | أفوكادو |\n'
                '| ثمرة     | أحمر  | بندورة  |\n'
                '| الخضروات | أخضر  | الخس    |\n'
                '+----------+-------+---------+')

    assert actual == expected
Exemplo n.º 7
0
def test_ascii():
    """Test with ASCII characters."""
    table_data = [
        ['Name', 'Color', 'Type'],
        ['Avocado', 'green', 'nut'],
        ['Tomato', 'red', 'fruit'],
        ['Lettuce', 'green', 'vegetable'],
    ]
    table = BaseTable(table_data)
    actual = table.unicode_table()

    expected = ('+---------+-------+-----------+\n'
                '| Name    | Color | Type      |\n'
                '+---------+-------+-----------+\n'
                '| Avocado | green | nut       |\n'
                '| Tomato  | red   | fruit     |\n'
                '| Lettuce | green | vegetable |\n'
                '+---------+-------+-----------+')

    assert actual == expected