diff options
Diffstat (limited to 'tests/test_base_table')
-rw-r--r-- | tests/test_base_table/__init__.py | 0 | ||||
-rw-r--r-- | tests/test_base_table/test_gen_row_lines.py | 34 | ||||
-rw-r--r-- | tests/test_base_table/test_gen_table.py | 224 | ||||
-rw-r--r-- | tests/test_base_table/test_horizontal_border.py | 98 | ||||
-rw-r--r-- | tests/test_base_table/test_table.py | 162 |
5 files changed, 268 insertions, 250 deletions
diff --git a/tests/test_base_table/__init__.py b/tests/test_base_table/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/tests/test_base_table/__init__.py diff --git a/tests/test_base_table/test_gen_row_lines.py b/tests/test_base_table/test_gen_row_lines.py index 0d0f43c..da47349 100644 --- a/tests/test_base_table/test_gen_row_lines.py +++ b/tests/test_base_table/test_gen_row_lines.py @@ -2,47 +2,47 @@ import pytest -from terminaltables.base_table import BaseTable +from terminaltables3.base_table import BaseTable -@pytest.mark.parametrize('style', ['heading', 'footing', 'row']) +@pytest.mark.parametrize("style", ["heading", "footing", "row"]) def test_single_line(style): """Test with single-line row. :param str style: Passed to method. """ - row = ['Row One Column One', 'Two', 'Three'] + row = ["Row One Column One", "Two", "Three"] table = BaseTable([row]) actual = [tuple(i) for i in table.gen_row_lines(row, style, [18, 3, 5], 1)] expected = [ - ('|', ' Row One Column One ', '|', ' Two ', '|', ' Three ', '|'), + ("|", " Row One Column One ", "|", " Two ", "|", " Three ", "|"), ] assert actual == expected -@pytest.mark.parametrize('style', ['heading', 'footing', 'row']) +@pytest.mark.parametrize("style", ["heading", "footing", "row"]) def test_multi_line(style): """Test with multi-line row. :param str style: Passed to method. """ - row = ['Row One\nColumn One', 'Two', 'Three'] + row = ["Row One\nColumn One", "Two", "Three"] table = BaseTable([row]) actual = [tuple(i) for i in table.gen_row_lines(row, style, [10, 3, 5], 2)] expected = [ - ('|', ' Row One ', '|', ' Two ', '|', ' Three ', '|'), - ('|', ' Column One ', '|', ' ', '|', ' ', '|'), + ("|", " Row One ", "|", " Two ", "|", " Three ", "|"), + ("|", " Column One ", "|", " ", "|", " ", "|"), ] assert actual == expected -@pytest.mark.parametrize('style', ['heading', 'footing', 'row']) +@pytest.mark.parametrize("style", ["heading", "footing", "row"]) def test_no_padding_no_borders(style): """Test without padding or borders. :param str style: Passed to method. """ - row = ['Row One\nColumn One', 'Two', 'Three'] + row = ["Row One\nColumn One", "Two", "Three"] table = BaseTable([row]) table.inner_column_border = False table.outer_border = False @@ -50,28 +50,28 @@ def test_no_padding_no_borders(style): table.padding_right = 0 actual = [tuple(i) for i in table.gen_row_lines(row, style, [10, 3, 5], 2)] expected = [ - ('Row One ', 'Two', 'Three'), - ('Column One', ' ', ' '), + ("Row One ", "Two", "Three"), + ("Column One", " ", " "), ] assert actual == expected -@pytest.mark.parametrize('style', ['heading', 'footing', 'row']) +@pytest.mark.parametrize("style", ["heading", "footing", "row"]) def test_uneven(style): """Test with row missing cells. :param str style: Passed to method. """ - row = ['Row One Column One'] + row = ["Row One Column One"] table = BaseTable([row]) actual = [tuple(i) for i in table.gen_row_lines(row, style, [18, 3, 5], 1)] expected = [ - ('|', ' Row One Column One ', '|', ' ', '|', ' ', '|'), + ("|", " Row One Column One ", "|", " ", "|", " ", "|"), ] assert actual == expected -@pytest.mark.parametrize('style', ['heading', 'footing', 'row']) +@pytest.mark.parametrize("style", ["heading", "footing", "row"]) def test_empty_table(style): """Test empty table. @@ -81,6 +81,6 @@ def test_empty_table(style): table = BaseTable([row]) actual = [tuple(i) for i in table.gen_row_lines(row, style, [], 0)] expected = [ - ('|', '|'), + ("|", "|"), ] assert actual == expected diff --git a/tests/test_base_table/test_gen_table.py b/tests/test_base_table/test_gen_table.py index 54d5fe1..d7ee997 100644 --- a/tests/test_base_table/test_gen_table.py +++ b/tests/test_base_table/test_gen_table.py @@ -2,15 +2,17 @@ import pytest -from terminaltables.base_table import BaseTable -from terminaltables.build import flatten -from terminaltables.width_and_alignment import max_dimensions +from terminaltables3.base_table import BaseTable +from terminaltables3.build import flatten +from terminaltables3.width_and_alignment import max_dimensions -@pytest.mark.parametrize('inner_heading_row_border', [True, False]) -@pytest.mark.parametrize('inner_footing_row_border', [True, False]) -@pytest.mark.parametrize('inner_row_border', [True, False]) -def test_inner_row_borders(inner_heading_row_border, inner_footing_row_border, inner_row_border): +@pytest.mark.parametrize("inner_heading_row_border", [True, False]) +@pytest.mark.parametrize("inner_footing_row_border", [True, False]) +@pytest.mark.parametrize("inner_row_border", [True, False]) +def test_inner_row_borders( + inner_heading_row_border, inner_footing_row_border, inner_row_border +): """Test heading/footing/row borders. :param bool inner_heading_row_border: Passed to table. @@ -18,142 +20,145 @@ def test_inner_row_borders(inner_heading_row_border, inner_footing_row_border, i :param bool inner_row_border: Passed to table. """ table_data = [ - ['Name', 'Color', 'Type'], - ['Avocado', 'green', 'nut'], - ['Tomato', 'red', 'fruit'], - ['Lettuce', 'green', 'vegetable'], + ["Name", "Color", "Type"], + ["Avocado", "green", "nut"], + ["Tomato", "red", "fruit"], + ["Lettuce", "green", "vegetable"], ] table = BaseTable(table_data) table.inner_heading_row_border = inner_heading_row_border table.inner_footing_row_border = inner_footing_row_border table.inner_row_border = inner_row_border - inner_widths, inner_heights, outer_widths = max_dimensions(table_data, table.padding_left, table.padding_right)[:3] + inner_widths, inner_heights, outer_widths = max_dimensions( + table_data, table.padding_left, table.padding_right + )[:3] actual = flatten(table.gen_table(inner_widths, inner_heights, outer_widths)) # Determine expected. if inner_row_border: expected = ( - '+---------+-------+-----------+\n' - '| Name | Color | Type |\n' - '+---------+-------+-----------+\n' - '| Avocado | green | nut |\n' - '+---------+-------+-----------+\n' - '| Tomato | red | fruit |\n' - '+---------+-------+-----------+\n' - '| Lettuce | green | vegetable |\n' - '+---------+-------+-----------+' + "+---------+-------+-----------+\n" + "| Name | Color | Type |\n" + "+---------+-------+-----------+\n" + "| Avocado | green | nut |\n" + "+---------+-------+-----------+\n" + "| Tomato | red | fruit |\n" + "+---------+-------+-----------+\n" + "| Lettuce | green | vegetable |\n" + "+---------+-------+-----------+" ) elif inner_heading_row_border and inner_footing_row_border: expected = ( - '+---------+-------+-----------+\n' - '| Name | Color | Type |\n' - '+---------+-------+-----------+\n' - '| Avocado | green | nut |\n' - '| Tomato | red | fruit |\n' - '+---------+-------+-----------+\n' - '| Lettuce | green | vegetable |\n' - '+---------+-------+-----------+' + "+---------+-------+-----------+\n" + "| Name | Color | Type |\n" + "+---------+-------+-----------+\n" + "| Avocado | green | nut |\n" + "| Tomato | red | fruit |\n" + "+---------+-------+-----------+\n" + "| Lettuce | green | vegetable |\n" + "+---------+-------+-----------+" ) elif inner_heading_row_border: expected = ( - '+---------+-------+-----------+\n' - '| Name | Color | Type |\n' - '+---------+-------+-----------+\n' - '| Avocado | green | nut |\n' - '| Tomato | red | fruit |\n' - '| Lettuce | green | vegetable |\n' - '+---------+-------+-----------+' + "+---------+-------+-----------+\n" + "| Name | Color | Type |\n" + "+---------+-------+-----------+\n" + "| Avocado | green | nut |\n" + "| Tomato | red | fruit |\n" + "| Lettuce | green | vegetable |\n" + "+---------+-------+-----------+" ) elif inner_footing_row_border: expected = ( - '+---------+-------+-----------+\n' - '| Name | Color | Type |\n' - '| Avocado | green | nut |\n' - '| Tomato | red | fruit |\n' - '+---------+-------+-----------+\n' - '| Lettuce | green | vegetable |\n' - '+---------+-------+-----------+' + "+---------+-------+-----------+\n" + "| Name | Color | Type |\n" + "| Avocado | green | nut |\n" + "| Tomato | red | fruit |\n" + "+---------+-------+-----------+\n" + "| Lettuce | green | vegetable |\n" + "+---------+-------+-----------+" ) else: expected = ( - '+---------+-------+-----------+\n' - '| Name | Color | Type |\n' - '| Avocado | green | nut |\n' - '| Tomato | red | fruit |\n' - '| Lettuce | green | vegetable |\n' - '+---------+-------+-----------+' + "+---------+-------+-----------+\n" + "| Name | Color | Type |\n" + "| Avocado | green | nut |\n" + "| Tomato | red | fruit |\n" + "| Lettuce | green | vegetable |\n" + "+---------+-------+-----------+" ) assert actual == expected -@pytest.mark.parametrize('outer_border', [True, False]) +@pytest.mark.parametrize("outer_border", [True, False]) def test_outer_borders(outer_border): """Test left/right/top/bottom table borders. :param bool outer_border: Passed to table. """ table_data = [ - ['Name', 'Color', 'Type'], - ['Avocado', 'green', 'nut'], - ['Tomato', 'red', 'fruit'], - ['Lettuce', 'green', 'vegetable'], + ["Name", "Color", "Type"], + ["Avocado", "green", "nut"], + ["Tomato", "red", "fruit"], + ["Lettuce", "green", "vegetable"], ] - table = BaseTable(table_data, 'Example Table') + table = BaseTable(table_data, "Example Table") table.outer_border = outer_border - inner_widths, inner_heights, outer_widths = max_dimensions(table_data, table.padding_left, table.padding_right)[:3] + inner_widths, inner_heights, outer_widths = max_dimensions( + table_data, table.padding_left, table.padding_right + )[:3] actual = flatten(table.gen_table(inner_widths, inner_heights, outer_widths)) # Determine expected. if outer_border: expected = ( - '+Example Table----+-----------+\n' - '| Name | Color | Type |\n' - '+---------+-------+-----------+\n' - '| Avocado | green | nut |\n' - '| Tomato | red | fruit |\n' - '| Lettuce | green | vegetable |\n' - '+---------+-------+-----------+' + "+Example Table----+-----------+\n" + "| Name | Color | Type |\n" + "+---------+-------+-----------+\n" + "| Avocado | green | nut |\n" + "| Tomato | red | fruit |\n" + "| Lettuce | green | vegetable |\n" + "+---------+-------+-----------+" ) else: expected = ( - ' Name | Color | Type \n' - '---------+-------+-----------\n' - ' Avocado | green | nut \n' - ' Tomato | red | fruit \n' - ' Lettuce | green | vegetable ' + " Name | Color | Type \n" + "---------+-------+-----------\n" + " Avocado | green | nut \n" + " Tomato | red | fruit \n" + " Lettuce | green | vegetable " ) assert actual == expected -@pytest.mark.parametrize('mode', ['row', 'one', 'blank', 'empty', 'none']) -@pytest.mark.parametrize('bare', [False, True]) +@pytest.mark.parametrize("mode", ["row", "one", "blank", "empty", "none"]) +@pytest.mark.parametrize("bare", [False, True]) def test_one_no_rows(mode, bare): """Test with one or no rows. :param str mode: Type of table contents to test. :param bool bare: Disable padding/borders. """ - if mode == 'row': + if mode == "row": table_data = [ - ['Avocado', 'green', 'nut'], + ["Avocado", "green", "nut"], ] - elif mode == 'one': + elif mode == "one": table_data = [ - ['Avocado'], + ["Avocado"], ] - elif mode == 'blank': + elif mode == "blank": table_data = [ - [''], + [""], ] - elif mode == 'empty': + elif mode == "empty": table_data = [ [], ] else: - table_data = [ - ] + table_data = [] table = BaseTable(table_data) if bare: table.inner_column_border = False @@ -163,63 +168,40 @@ def test_one_no_rows(mode, bare): table.outer_border = False table.padding_left = 0 table.padding_right = 0 - inner_widths, inner_heights, outer_widths = max_dimensions(table_data, table.padding_left, table.padding_right)[:3] + inner_widths, inner_heights, outer_widths = max_dimensions( + table_data, table.padding_left, table.padding_right + )[:3] actual = flatten(table.gen_table(inner_widths, inner_heights, outer_widths)) # Determine expected. - if mode == 'row': + if mode == "row": if bare: - expected = ( - 'Avocadogreennut' - ) + expected = "Avocadogreennut" else: expected = ( - '+---------+-------+-----+\n' - '| Avocado | green | nut |\n' - '+---------+-------+-----+' + "+---------+-------+-----+\n" + "| Avocado | green | nut |\n" + "+---------+-------+-----+" ) - elif mode == 'one': + elif mode == "one": if bare: - expected = ( - 'Avocado' - ) + expected = "Avocado" else: - expected = ( - '+---------+\n' - '| Avocado |\n' - '+---------+' - ) - elif mode == 'blank': # Remember there's still padding. + expected = "+---------+\n" "| Avocado |\n" "+---------+" + elif mode == "blank": # Remember there's still padding. if bare: - expected = ( - '' - ) + expected = "" else: - expected = ( - '+--+\n' - '| |\n' - '+--+' - ) - elif mode == 'empty': + expected = "+--+\n" "| |\n" "+--+" + elif mode == "empty": if bare: - expected = ( - '' - ) + expected = "" else: - expected = ( - '++\n' - '||\n' - '++' - ) + expected = "++\n" "||\n" "++" else: if bare: - expected = ( - '' - ) + expected = "" else: - expected = ( - '++\n' - '++' - ) + expected = "++\n" "++" assert actual == expected diff --git a/tests/test_base_table/test_horizontal_border.py b/tests/test_base_table/test_horizontal_border.py index e162261..59ae29a 100644 --- a/tests/test_base_table/test_horizontal_border.py +++ b/tests/test_base_table/test_horizontal_border.py @@ -2,47 +2,49 @@ import pytest -from terminaltables.base_table import BaseTable -from terminaltables.width_and_alignment import max_dimensions +from terminaltables3.base_table import BaseTable +from terminaltables3.width_and_alignment import max_dimensions SINGLE_LINE = ( - ('Name', 'Color', 'Type'), - ('Avocado', 'green', 'nut'), - ('Tomato', 'red', 'fruit'), - ('Lettuce', 'green', 'vegetable'), + ("Name", "Color", "Type"), + ("Avocado", "green", "nut"), + ("Tomato", "red", "fruit"), + ("Lettuce", "green", "vegetable"), ) -@pytest.mark.parametrize('inner_column_border', [True, False]) -@pytest.mark.parametrize('style', ['top', 'bottom']) +@pytest.mark.parametrize("inner_column_border", [True, False]) +@pytest.mark.parametrize("style", ["top", "bottom"]) def test_top_bottom(inner_column_border, style): """Test top and bottom borders. :param bool inner_column_border: Passed to table class. :param str style: Passed to method. """ - table = BaseTable(SINGLE_LINE, 'Example') + table = BaseTable(SINGLE_LINE, "Example") table.inner_column_border = inner_column_border - outer_widths = max_dimensions(table.table_data, table.padding_left, table.padding_right)[2] + outer_widths = max_dimensions( + table.table_data, table.padding_left, table.padding_right + )[2] # Determine expected. - if style == 'top' and inner_column_border: - expected = '+Example--+-------+-----------+' - elif style == 'top': - expected = '+Example--------------------+' - elif style == 'bottom' and inner_column_border: - expected = '+---------+-------+-----------+' + if style == "top" and inner_column_border: + expected = "+Example--+-------+-----------+" + elif style == "top": + expected = "+Example--------------------+" + elif style == "bottom" and inner_column_border: + expected = "+---------+-------+-----------+" else: - expected = '+---------------------------+' + expected = "+---------------------------+" # Test. - actual = ''.join(table.horizontal_border(style, outer_widths)) + actual = "".join(table.horizontal_border(style, outer_widths)) assert actual == expected -@pytest.mark.parametrize('inner_column_border', [True, False]) -@pytest.mark.parametrize('outer_border', [True, False]) -@pytest.mark.parametrize('style', ['heading', 'footing']) +@pytest.mark.parametrize("inner_column_border", [True, False]) +@pytest.mark.parametrize("outer_border", [True, False]) +@pytest.mark.parametrize("style", ["heading", "footing"]) def test_heading_footing(inner_column_border, outer_border, style): """Test heading and footing borders. @@ -53,25 +55,43 @@ def test_heading_footing(inner_column_border, outer_border, style): table = BaseTable(SINGLE_LINE) table.inner_column_border = inner_column_border table.outer_border = outer_border - outer_widths = max_dimensions(table.table_data, table.padding_left, table.padding_right)[2] + outer_widths = max_dimensions( + table.table_data, table.padding_left, table.padding_right + )[2] # Determine expected. - if style == 'heading' and outer_border: - expected = '+---------+-------+-----------+' if inner_column_border else '+---------------------------+' - elif style == 'heading': - expected = '---------+-------+-----------' if inner_column_border else '---------------------------' - elif style == 'footing' and outer_border: - expected = '+---------+-------+-----------+' if inner_column_border else '+---------------------------+' + if style == "heading" and outer_border: + expected = ( + "+---------+-------+-----------+" + if inner_column_border + else "+---------------------------+" + ) + elif style == "heading": + expected = ( + "---------+-------+-----------" + if inner_column_border + else "---------------------------" + ) + elif style == "footing" and outer_border: + expected = ( + "+---------+-------+-----------+" + if inner_column_border + else "+---------------------------+" + ) else: - expected = '---------+-------+-----------' if inner_column_border else '---------------------------' + expected = ( + "---------+-------+-----------" + if inner_column_border + else "---------------------------" + ) # Test. - actual = ''.join(table.horizontal_border(style, outer_widths)) + actual = "".join(table.horizontal_border(style, outer_widths)) assert actual == expected -@pytest.mark.parametrize('inner_column_border', [True, False]) -@pytest.mark.parametrize('outer_border', [True, False]) +@pytest.mark.parametrize("inner_column_border", [True, False]) +@pytest.mark.parametrize("outer_border", [True, False]) def test_row(inner_column_border, outer_border): """Test inner borders. @@ -81,18 +101,20 @@ def test_row(inner_column_border, outer_border): table = BaseTable(SINGLE_LINE) table.inner_column_border = inner_column_border table.outer_border = outer_border - outer_widths = max_dimensions(table.table_data, table.padding_left, table.padding_right)[2] + outer_widths = max_dimensions( + table.table_data, table.padding_left, table.padding_right + )[2] # Determine expected. if inner_column_border and outer_border: - expected = '+---------+-------+-----------+' + expected = "+---------+-------+-----------+" elif inner_column_border: - expected = '---------+-------+-----------' + expected = "---------+-------+-----------" elif outer_border: - expected = '+---------------------------+' + expected = "+---------------------------+" else: - expected = '---------------------------' + expected = "---------------------------" # Test. - actual = ''.join(table.horizontal_border('row', outer_widths)) + actual = "".join(table.horizontal_border("row", outer_widths)) assert actual == expected diff --git a/tests/test_base_table/test_table.py b/tests/test_base_table/test_table.py index c5b5a89..7487308 100644 --- a/tests/test_base_table/test_table.py +++ b/tests/test_base_table/test_table.py @@ -1,32 +1,31 @@ -# coding: utf-8 """Test property in BaseTable class.""" from colorama import Fore from colorclass import Color from termcolor import colored -from terminaltables.base_table import BaseTable +from terminaltables3.base_table import BaseTable def test_ascii(): """Test with ASCII characters.""" table_data = [ - ['Name', 'Color', 'Type'], - ['Avocado', 'green', 'nut'], - ['Tomato', 'red', 'fruit'], - ['Lettuce', 'green', 'vegetable'], + ["Name", "Color", "Type"], + ["Avocado", "green", "nut"], + ["Tomato", "red", "fruit"], + ["Lettuce", "green", "vegetable"], ] table = BaseTable(table_data) actual = table.table expected = ( - '+---------+-------+-----------+\n' - '| Name | Color | Type |\n' - '+---------+-------+-----------+\n' - '| Avocado | green | nut |\n' - '| Tomato | red | fruit |\n' - '| Lettuce | green | vegetable |\n' - '+---------+-------+-----------+' + "+---------+-------+-----------+\n" + "| Name | Color | Type |\n" + "+---------+-------+-----------+\n" + "| Avocado | green | nut |\n" + "| Tomato | red | fruit |\n" + "| Lettuce | green | vegetable |\n" + "+---------+-------+-----------+" ) assert actual == expected @@ -44,13 +43,13 @@ def test_int(): actual = table.table expected = ( - '+1234567890+---+\n' - '| 100 | 10 | 1 |\n' - '+-----+----+---+\n' - '| 0 | 3 | 6 |\n' - '| 1 | 4 | 7 |\n' - '| 2 | 5 | 8 |\n' - '+-----+----+---+' + "+1234567890+---+\n" + "| 100 | 10 | 1 |\n" + "+-----+----+---+\n" + "| 0 | 3 | 6 |\n" + "| 1 | 4 | 7 |\n" + "| 2 | 5 | 8 |\n" + "+-----+----+---+" ) assert actual == expected @@ -68,13 +67,13 @@ def test_float(): actual = table.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' - '+-----+------+-------+' + "+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 @@ -92,13 +91,13 @@ def test_bool_none(): actual = table.table expected = ( - '+True---+-------+-------+\n' - '| True | False | None |\n' - '+-------+-------+-------+\n' - '| True | False | None |\n' - '| False | None | True |\n' - '| None | True | False |\n' - '+-------+-------+-------+' + "+True---+-------+-------+\n" + "| True | False | None |\n" + "+-------+-------+-------+\n" + "| True | False | None |\n" + "| False | None | True |\n" + "| None | True | False |\n" + "+-------+-------+-------+" ) assert actual == expected @@ -107,20 +106,20 @@ def test_bool_none(): def test_cjk(): """Test with CJK characters.""" table_data = [ - ['CJK'], - ['蓝色'], - ['世界你好'], + ["CJK"], + ["蓝色"], + ["世界你好"], ] table = BaseTable(table_data) actual = table.table expected = ( - '+----------+\n' - '| CJK |\n' - '+----------+\n' - '| 蓝色 |\n' - '| 世界你好 |\n' - '+----------+' + "+----------+\n" + "| CJK |\n" + "+----------+\n" + "| 蓝色 |\n" + "| 世界你好 |\n" + "+----------+" ) assert actual == expected @@ -129,20 +128,15 @@ def test_cjk(): def test_rtl(): """Test with RTL characters.""" table_data = [ - ['RTL'], - ['שלום'], - ['معرب'], + ["RTL"], + ["שלום"], + ["معرب"], ] table = BaseTable(table_data) actual = table.table expected = ( - '+------+\n' - '| RTL |\n' - '+------+\n' - '| שלום |\n' - '| معرب |\n' - '+------+' + "+------+\n" "| RTL |\n" "+------+\n" "| שלום |\n" "| معرب |\n" "+------+" ) assert actual == expected @@ -151,22 +145,22 @@ def test_rtl(): def test_rtl_large(): """Test large table of RTL characters.""" table_data = [ - ['اكتب', 'اللون', 'اسم'], - ['البندق', 'أخضر', 'أفوكادو'], - ['ثمرة', 'أحمر', 'بندورة'], - ['الخضروات', 'أخضر', 'الخس'], + ["اكتب", "اللون", "اسم"], + ["البندق", "أخضر", "أفوكادو"], + ["ثمرة", "أحمر", "بندورة"], + ["الخضروات", "أخضر", "الخس"], ] - table = BaseTable(table_data, 'جوجل المترجم') + table = BaseTable(table_data, "جوجل المترجم") actual = table.table expected = ( - '+جوجل المترجم------+---------+\n' - '| اكتب | اللون | اسم |\n' - '+----------+-------+---------+\n' - '| البندق | أخضر | أفوكادو |\n' - '| ثمرة | أحمر | بندورة |\n' - '| الخضروات | أخضر | الخس |\n' - '+----------+-------+---------+' + "+جوجل المترجم------+---------+\n" + "| اكتب | اللون | اسم |\n" + "+----------+-------+---------+\n" + "| البندق | أخضر | أفوكادو |\n" + "| ثمرة | أحمر | بندورة |\n" + "| الخضروات | أخضر | الخس |\n" + "+----------+-------+---------+" ) assert actual == expected @@ -175,22 +169,42 @@ def test_rtl_large(): def test_color(): """Test with color characters.""" table_data = [ - ['ansi', '\033[31mRed\033[39m', '\033[32mGreen\033[39m', '\033[34mBlue\033[39m'], - ['colorclass', Color('{red}Red{/red}'), Color('{green}Green{/green}'), Color('{blue}Blue{/blue}')], - ['colorama', Fore.RED + 'Red' + Fore.RESET, Fore.GREEN + 'Green' + Fore.RESET, Fore.BLUE + 'Blue' + Fore.RESET], - ['termcolor', colored('Red', 'red'), colored('Green', 'green'), colored('Blue', 'blue')], + [ + "ansi", + "\033[31mRed\033[39m", + "\033[32mGreen\033[39m", + "\033[34mBlue\033[39m", + ], + [ + "colorclass", + Color("{red}Red{/red}"), + Color("{green}Green{/green}"), + Color("{blue}Blue{/blue}"), + ], + [ + "colorama", + Fore.RED + "Red" + Fore.RESET, + Fore.GREEN + "Green" + Fore.RESET, + Fore.BLUE + "Blue" + Fore.RESET, + ], + [ + "termcolor", + colored("Red", "red"), + colored("Green", "green"), + colored("Blue", "blue"), + ], ] table = BaseTable(table_data) table.inner_heading_row_border = False actual = table.table expected = ( - u'+------------+-----+-------+------+\n' - u'| ansi | \033[31mRed\033[39m | \033[32mGreen\033[39m | \033[34mBlue\033[39m |\n' - u'| colorclass | \033[31mRed\033[39m | \033[32mGreen\033[39m | \033[34mBlue\033[39m |\n' - u'| colorama | \033[31mRed\033[39m | \033[32mGreen\033[39m | \033[34mBlue\033[39m |\n' - u'| termcolor | \033[31mRed\033[0m | \033[32mGreen\033[0m | \033[34mBlue\033[0m |\n' - u'+------------+-----+-------+------+' + "+------------+-----+-------+------+\n" + "| ansi | \033[31mRed\033[39m | \033[32mGreen\033[39m | \033[34mBlue\033[39m |\n" + "| colorclass | \033[31mRed\033[39m | \033[32mGreen\033[39m | \033[34mBlue\033[39m |\n" + "| colorama | \033[31mRed\033[39m | \033[32mGreen\033[39m | \033[34mBlue\033[39m |\n" + "| termcolor | \033[31mRed\033[0m | \033[32mGreen\033[0m | \033[34mBlue\033[0m |\n" + "+------------+-----+-------+------+" ) assert actual == expected |