diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2022-09-16 09:09:35 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2022-09-16 09:09:35 +0000 |
commit | 0dfe1c9e2780469e3a4696e8fb3e6f717a7ebeb7 (patch) | |
tree | a0b651b55ea02e3b00bbc5eedba566fdd6bd7c08 /tests/test_base_table/test_horizontal_border.py | |
parent | Initial commit. (diff) | |
download | terminaltables-0dfe1c9e2780469e3a4696e8fb3e6f717a7ebeb7.tar.xz terminaltables-0dfe1c9e2780469e3a4696e8fb3e6f717a7ebeb7.zip |
Adding upstream version 3.1.0.upstream/3.1.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/test_base_table/test_horizontal_border.py')
-rw-r--r-- | tests/test_base_table/test_horizontal_border.py | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/tests/test_base_table/test_horizontal_border.py b/tests/test_base_table/test_horizontal_border.py new file mode 100644 index 0000000..e162261 --- /dev/null +++ b/tests/test_base_table/test_horizontal_border.py @@ -0,0 +1,98 @@ +"""Test method in BaseTable class.""" + +import pytest + +from terminaltables.base_table import BaseTable +from terminaltables.width_and_alignment import max_dimensions + +SINGLE_LINE = ( + ('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']) +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.inner_column_border = inner_column_border + 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 = '+---------+-------+-----------+' + else: + expected = '+---------------------------+' + + # Test. + 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']) +def test_heading_footing(inner_column_border, outer_border, style): + """Test heading and footing borders. + + :param bool inner_column_border: Passed to table class. + :param bool outer_border: Passed to table class. + :param str style: Passed to method. + """ + 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] + + # 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 '+---------------------------+' + else: + expected = '---------+-------+-----------' if inner_column_border else '---------------------------' + + # Test. + 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]) +def test_row(inner_column_border, outer_border): + """Test inner borders. + + :param bool inner_column_border: Passed to table class. + :param bool outer_border: Passed to table class. + """ + 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] + + # Determine expected. + if inner_column_border and outer_border: + expected = '+---------+-------+-----------+' + elif inner_column_border: + expected = '---------+-------+-----------' + elif outer_border: + expected = '+---------------------------+' + else: + expected = '---------------------------' + + # Test. + actual = ''.join(table.horizontal_border('row', outer_widths)) + assert actual == expected |