diff options
Diffstat (limited to 'tests/test_build')
-rw-r--r-- | tests/test_build/__init__.py | 0 | ||||
-rw-r--r-- | tests/test_build/test_build_border.py | 463 | ||||
-rw-r--r-- | tests/test_build/test_build_row.py | 74 | ||||
-rw-r--r-- | tests/test_build/test_combine.py | 24 | ||||
-rw-r--r-- | tests/test_build/test_flatten.py | 13 |
5 files changed, 297 insertions, 277 deletions
diff --git a/tests/test_build/__init__.py b/tests/test_build/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/tests/test_build/__init__.py diff --git a/tests/test_build/test_build_border.py b/tests/test_build/test_build_border.py index 9c410fd..1ac2d0a 100644 --- a/tests/test_build/test_build_border.py +++ b/tests/test_build/test_build_border.py @@ -1,4 +1,3 @@ -# coding: utf-8 """Test function in module.""" import pytest @@ -6,16 +5,19 @@ from colorama import Fore, Style from colorclass import Color from termcolor import colored -from terminaltables.build import build_border +from terminaltables3.build import build_border -@pytest.mark.parametrize('outer_widths,horizontal,left,intersect,right,expected', [ - ([5, 6, 7], '-', '<', '+', '>', '<-----+------+------->'), - ([1, 1, 1], '-', '', '', '', '---'), - ([1, 1, 1], '', '', '', '', ''), - ([1], '-', '<', '+', '>', '<->'), - ([], '-', '<', '+', '>', '<>'), -]) +@pytest.mark.parametrize( + "outer_widths,horizontal,left,intersect,right,expected", + [ + ([5, 6, 7], "-", "<", "+", ">", "<-----+------+------->"), + ([1, 1, 1], "-", "", "", "", "---"), + ([1, 1, 1], "", "", "", "", ""), + ([1], "-", "<", "+", ">", "<->"), + ([], "-", "<", "+", ">", "<>"), + ], +) def test_no_title(outer_widths, horizontal, left, intersect, right, expected): """Test without title. @@ -27,26 +29,25 @@ def test_no_title(outer_widths, horizontal, left, intersect, right, expected): :param str expected: Expected output. """ actual = build_border(outer_widths, horizontal, left, intersect, right) - assert ''.join(actual) == expected - - -@pytest.mark.parametrize('outer_widths,intersect,expected', [ - ([20], '+', 'Applications--------'), - ([20], '', 'Applications--------'), - - ([15, 5], '+', 'Applications---+-----'), - ([15, 5], '', 'Applications--------'), - - ([12], '+', 'Applications'), - ([12], '', 'Applications'), - - ([12, 1], '+', 'Applications+-'), - ([12, 1], '', 'Applications-'), - - ([12, 0], '+', 'Applications+'), - ([12, 0], '', 'Applications'), -]) -@pytest.mark.parametrize('left,right', [('', ''), ('<', '>')]) + assert "".join(actual) == expected + + +@pytest.mark.parametrize( + "outer_widths,intersect,expected", + [ + ([20], "+", "Applications--------"), + ([20], "", "Applications--------"), + ([15, 5], "+", "Applications---+-----"), + ([15, 5], "", "Applications--------"), + ([12], "+", "Applications"), + ([12], "", "Applications"), + ([12, 1], "+", "Applications+-"), + ([12, 1], "", "Applications-"), + ([12, 0], "+", "Applications+"), + ([12, 0], "", "Applications"), + ], +) +@pytest.mark.parametrize("left,right", [("", ""), ("<", ">")]) def test_first_column_fit(outer_widths, left, intersect, right, expected): """Test with title that fits in the first column. @@ -58,23 +59,28 @@ def test_first_column_fit(outer_widths, left, intersect, right, expected): """ if left and right: expected = left + expected + right - actual = build_border(outer_widths, '-', left, intersect, right, title='Applications') - assert ''.join(actual) == expected - - -@pytest.mark.parametrize('outer_widths,expected', [ - ([20], 'Applications--------'), - ([10, 10], 'Applications--------'), - ([5, 5, 5, 5], 'Applications--------'), - ([3, 2, 3, 2, 3, 2, 3, 2], 'Applications--------'), - ([1] * 20, 'Applications--------'), - ([10, 5], 'Applications---'), - ([9, 5], 'Applications--'), - ([8, 5], 'Applications-'), - ([7, 5], 'Applications'), - ([6, 5], '-----------'), -]) -@pytest.mark.parametrize('left,right', [('', ''), ('<', '>')]) + actual = build_border( + outer_widths, "-", left, intersect, right, title="Applications" + ) + assert "".join(actual) == expected + + +@pytest.mark.parametrize( + "outer_widths,expected", + [ + ([20], "Applications--------"), + ([10, 10], "Applications--------"), + ([5, 5, 5, 5], "Applications--------"), + ([3, 2, 3, 2, 3, 2, 3, 2], "Applications--------"), + ([1] * 20, "Applications--------"), + ([10, 5], "Applications---"), + ([9, 5], "Applications--"), + ([8, 5], "Applications-"), + ([7, 5], "Applications"), + ([6, 5], "-----------"), + ], +) +@pytest.mark.parametrize("left,right", [("", ""), ("<", ">")]) def test_no_intersect(outer_widths, left, right, expected): """Test with no column dividers. @@ -85,37 +91,39 @@ def test_no_intersect(outer_widths, left, right, expected): """ if left and right: expected = left + expected + right - actual = build_border(outer_widths, '-', left, '', right, title='Applications') - assert ''.join(actual) == expected - - -@pytest.mark.parametrize('outer_widths,expected', [ - ([20], 'Applications--------'), - ([0, 20], 'Applications---------'), - ([20, 0], 'Applications--------+'), - ([0, 0, 20], 'Applications----------'), - ([20, 0, 0], 'Applications--------++'), - - ([10, 10], 'Applications---------'), - ([11, 9], 'Applications---------'), - ([12, 8], 'Applications+--------'), - ([13, 7], 'Applications-+-------'), - - ([5, 5, 5, 5], 'Applications-----+-----'), - ([4, 4, 6, 6], 'Applications----+------'), - ([3, 3, 7, 7], 'Applications---+-------'), - ([2, 2, 7, 9], 'Applications-+---------'), - ([1, 1, 9, 9], 'Applications-+---------'), - - ([2, 2, 2, 2, 2, 2, 2], 'Applications--+--+--'), - ([1, 1, 1, 1, 1, 1, 1, 1, 1, 1], 'Applications-+-+-+-'), - ([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], 'Applications++++++++'), - - ([2, 2, 2, 2], '--+--+--+--'), - ([1, 1, 1, 1, 1], '-+-+-+-+-'), - ([0, 0, 0, 0, 0, 0, 0, 0, 0, 0], '+++++++++'), -]) -@pytest.mark.parametrize('left,right', [('', ''), ('<', '>')]) + actual = build_border(outer_widths, "-", left, "", right, title="Applications") + assert "".join(actual) == expected + + +@pytest.mark.parametrize( + "outer_widths,expected", + [ + ([20], "Applications--------"), + ([0, 20], "Applications---------"), + ([20, 0], "Applications--------+"), + ([0, 0, 20], "Applications----------"), + ([20, 0, 0], "Applications--------++"), + ([10, 10], "Applications---------"), + ([11, 9], "Applications---------"), + ([12, 8], "Applications+--------"), + ([13, 7], "Applications-+-------"), + ([5, 5, 5, 5], "Applications-----+-----"), + ([4, 4, 6, 6], "Applications----+------"), + ([3, 3, 7, 7], "Applications---+-------"), + ([2, 2, 7, 9], "Applications-+---------"), + ([1, 1, 9, 9], "Applications-+---------"), + ([2, 2, 2, 2, 2, 2, 2], "Applications--+--+--"), + ([1, 1, 1, 1, 1, 1, 1, 1, 1, 1], "Applications-+-+-+-"), + ( + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + "Applications++++++++", + ), + ([2, 2, 2, 2], "--+--+--+--"), + ([1, 1, 1, 1, 1], "-+-+-+-+-"), + ([0, 0, 0, 0, 0, 0, 0, 0, 0, 0], "+++++++++"), + ], +) +@pytest.mark.parametrize("left,right", [("", ""), ("<", ">")]) def test_intersect(outer_widths, left, right, expected): """Test with column dividers. @@ -126,48 +134,51 @@ def test_intersect(outer_widths, left, right, expected): """ if left and right: expected = left + expected + right - actual = build_border(outer_widths, '-', left, '+', right, title='Applications') - assert ''.join(actual) == expected - - -@pytest.mark.parametrize('outer_widths,intersect,expected', [ - ([12], '+', u'蓝色--------'), - ([12], '', u'蓝色--------'), - ([7, 5], '+', u'蓝色---+-----'), - ([7, 5], '', u'蓝色--------'), - ([4], '+', u'蓝色'), - ([4], '', u'蓝色'), - ([4, 1], '+', u'蓝色+-'), - ([4, 1], '', u'蓝色-'), - ([4, 0], '+', u'蓝色+'), - ([4, 0], '', u'蓝色'), - ([12], '', u'蓝色--------'), - ([6, 6], '', u'蓝色--------'), - ([3, 3, 3, 3], '', u'蓝色--------'), - ([2, 1, 2, 1, 2, 1, 2, 1], '', u'蓝色--------'), - ([1] * 12, '', u'蓝色--------'), - ([2, 4], '', u'蓝色--'), - ([1, 4], '', u'蓝色-'), - ([1, 3], '', u'蓝色'), - ([1, 2], '', u'---'), - ([2], '', u'--'), - ([12], '+', u'蓝色--------'), - ([0, 12], '+', u'蓝色---------'), - ([12, 0], '+', u'蓝色--------+'), - ([0, 0, 12], '+', u'蓝色----------'), - ([12, 0, 0], '+', u'蓝色--------++'), - ([3, 3], '+', u'蓝色---'), - ([4, 2], '+', u'蓝色+--'), - ([5, 1], '+', u'蓝色-+-'), - ([3, 3, 3, 3], '+', u'蓝色---+---+---'), - ([2, 2, 4, 4], '+', u'蓝色-+----+----'), - ([1, 1, 5, 5], '+', u'蓝色-----+-----'), - ([2, 2, 2, 2], '+', u'蓝色-+--+--'), - ([1, 1, 1, 1, 1], '+', u'蓝色-+-+-'), - ([0, 0, 0, 0, 0, 0, 0], '+', u'蓝色++'), - ([1, 1], '+', u'-+-'), -]) -@pytest.mark.parametrize('left,right', [('', ''), ('<', '>')]) + actual = build_border(outer_widths, "-", left, "+", right, title="Applications") + assert "".join(actual) == expected + + +@pytest.mark.parametrize( + "outer_widths,intersect,expected", + [ + ([12], "+", "蓝色--------"), + ([12], "", "蓝色--------"), + ([7, 5], "+", "蓝色---+-----"), + ([7, 5], "", "蓝色--------"), + ([4], "+", "蓝色"), + ([4], "", "蓝色"), + ([4, 1], "+", "蓝色+-"), + ([4, 1], "", "蓝色-"), + ([4, 0], "+", "蓝色+"), + ([4, 0], "", "蓝色"), + ([12], "", "蓝色--------"), + ([6, 6], "", "蓝色--------"), + ([3, 3, 3, 3], "", "蓝色--------"), + ([2, 1, 2, 1, 2, 1, 2, 1], "", "蓝色--------"), + ([1] * 12, "", "蓝色--------"), + ([2, 4], "", "蓝色--"), + ([1, 4], "", "蓝色-"), + ([1, 3], "", "蓝色"), + ([1, 2], "", "---"), + ([2], "", "--"), + ([12], "+", "蓝色--------"), + ([0, 12], "+", "蓝色---------"), + ([12, 0], "+", "蓝色--------+"), + ([0, 0, 12], "+", "蓝色----------"), + ([12, 0, 0], "+", "蓝色--------++"), + ([3, 3], "+", "蓝色---"), + ([4, 2], "+", "蓝色+--"), + ([5, 1], "+", "蓝色-+-"), + ([3, 3, 3, 3], "+", "蓝色---+---+---"), + ([2, 2, 4, 4], "+", "蓝色-+----+----"), + ([1, 1, 5, 5], "+", "蓝色-----+-----"), + ([2, 2, 2, 2], "+", "蓝色-+--+--"), + ([1, 1, 1, 1, 1], "+", "蓝色-+-+-"), + ([0, 0, 0, 0, 0, 0, 0], "+", "蓝色++"), + ([1, 1], "+", "-+-"), + ], +) +@pytest.mark.parametrize("left,right", [("", ""), ("<", ">")]) def test_cjk(outer_widths, left, intersect, right, expected): """Test with CJK characters in title. @@ -179,48 +190,51 @@ def test_cjk(outer_widths, left, intersect, right, expected): """ if left and right: expected = left + expected + right - actual = build_border(outer_widths, '-', left, intersect, right, title=u'蓝色') - assert ''.join(actual) == expected - - -@pytest.mark.parametrize('outer_widths,intersect,expected', [ - ([12], '+', u'معرب--------'), - ([12], '', u'معرب--------'), - ([7, 5], '+', u'معرب---+-----'), - ([7, 5], '', u'معرب--------'), - ([4], '+', u'معرب'), - ([4], '', u'معرب'), - ([4, 1], '+', u'معرب+-'), - ([4, 1], '', u'معرب-'), - ([4, 0], '+', u'معرب+'), - ([4, 0], '', u'معرب'), - ([12], '', u'معرب--------'), - ([6, 6], '', u'معرب--------'), - ([3, 3, 3, 3], '', u'معرب--------'), - ([2, 1, 2, 1, 2, 1, 2, 1], '', u'معرب--------'), - ([1] * 12, '', u'معرب--------'), - ([2, 4], '', u'معرب--'), - ([1, 4], '', u'معرب-'), - ([1, 3], '', u'معرب'), - ([1, 2], '', u'---'), - ([2], '', u'--'), - ([12], '+', u'معرب--------'), - ([0, 12], '+', u'معرب---------'), - ([12, 0], '+', u'معرب--------+'), - ([0, 0, 12], '+', u'معرب----------'), - ([12, 0, 0], '+', u'معرب--------++'), - ([3, 3], '+', u'معرب---'), - ([4, 2], '+', u'معرب+--'), - ([5, 1], '+', u'معرب-+-'), - ([3, 3, 3, 3], '+', u'معرب---+---+---'), - ([2, 2, 4, 4], '+', u'معرب-+----+----'), - ([1, 1, 5, 5], '+', u'معرب-----+-----'), - ([2, 2, 2, 2], '+', u'معرب-+--+--'), - ([1, 1, 1, 1, 1], '+', u'معرب-+-+-'), - ([0, 0, 0, 0, 0, 0, 0], '+', u'معرب++'), - ([1, 1], '+', u'-+-'), -]) -@pytest.mark.parametrize('left,right', [('', ''), ('<', '>')]) + actual = build_border(outer_widths, "-", left, intersect, right, title="蓝色") + assert "".join(actual) == expected + + +@pytest.mark.parametrize( + "outer_widths,intersect,expected", + [ + ([12], "+", "معرب--------"), + ([12], "", "معرب--------"), + ([7, 5], "+", "معرب---+-----"), + ([7, 5], "", "معرب--------"), + ([4], "+", "معرب"), + ([4], "", "معرب"), + ([4, 1], "+", "معرب+-"), + ([4, 1], "", "معرب-"), + ([4, 0], "+", "معرب+"), + ([4, 0], "", "معرب"), + ([12], "", "معرب--------"), + ([6, 6], "", "معرب--------"), + ([3, 3, 3, 3], "", "معرب--------"), + ([2, 1, 2, 1, 2, 1, 2, 1], "", "معرب--------"), + ([1] * 12, "", "معرب--------"), + ([2, 4], "", "معرب--"), + ([1, 4], "", "معرب-"), + ([1, 3], "", "معرب"), + ([1, 2], "", "---"), + ([2], "", "--"), + ([12], "+", "معرب--------"), + ([0, 12], "+", "معرب---------"), + ([12, 0], "+", "معرب--------+"), + ([0, 0, 12], "+", "معرب----------"), + ([12, 0, 0], "+", "معرب--------++"), + ([3, 3], "+", "معرب---"), + ([4, 2], "+", "معرب+--"), + ([5, 1], "+", "معرب-+-"), + ([3, 3, 3, 3], "+", "معرب---+---+---"), + ([2, 2, 4, 4], "+", "معرب-+----+----"), + ([1, 1, 5, 5], "+", "معرب-----+-----"), + ([2, 2, 2, 2], "+", "معرب-+--+--"), + ([1, 1, 1, 1, 1], "+", "معرب-+-+-"), + ([0, 0, 0, 0, 0, 0, 0], "+", "معرب++"), + ([1, 1], "+", "-+-"), + ], +) +@pytest.mark.parametrize("left,right", [("", ""), ("<", ">")]) def test_rtl(outer_widths, left, intersect, right, expected): """Test with RTL characters in title. @@ -232,53 +246,59 @@ def test_rtl(outer_widths, left, intersect, right, expected): """ if left and right: expected = left + expected + right - actual = build_border(outer_widths, '-', left, intersect, right, title=u'معرب') - assert ''.join(actual) == expected - - -@pytest.mark.parametrize('outer_widths,intersect,expected', [ - ([12], '+', '\x1b[34mTEST\x1b[0m--------'), - ([12], '', '\x1b[34mTEST\x1b[0m--------'), - ([7, 5], '+', '\x1b[34mTEST\x1b[0m---+-----'), - ([7, 5], '', '\x1b[34mTEST\x1b[0m--------'), - ([4], '+', '\x1b[34mTEST\x1b[0m'), - ([4], '', '\x1b[34mTEST\x1b[0m'), - ([4, 1], '+', '\x1b[34mTEST\x1b[0m+-'), - ([4, 1], '', '\x1b[34mTEST\x1b[0m-'), - ([4, 0], '+', '\x1b[34mTEST\x1b[0m+'), - ([4, 0], '', '\x1b[34mTEST\x1b[0m'), - ([12], '', '\x1b[34mTEST\x1b[0m--------'), - ([6, 6], '', '\x1b[34mTEST\x1b[0m--------'), - ([3, 3, 3, 3], '', '\x1b[34mTEST\x1b[0m--------'), - ([2, 1, 2, 1, 2, 1, 2, 1], '', '\x1b[34mTEST\x1b[0m--------'), - ([1] * 12, '', '\x1b[34mTEST\x1b[0m--------'), - ([2, 4], '', '\x1b[34mTEST\x1b[0m--'), - ([1, 4], '', '\x1b[34mTEST\x1b[0m-'), - ([1, 3], '', '\x1b[34mTEST\x1b[0m'), - ([1, 2], '', '---'), - ([12], '+', '\x1b[34mTEST\x1b[0m--------'), - ([0, 12], '+', '\x1b[34mTEST\x1b[0m---------'), - ([12, 0], '+', '\x1b[34mTEST\x1b[0m--------+'), - ([0, 0, 12], '+', '\x1b[34mTEST\x1b[0m----------'), - ([12, 0, 0], '+', '\x1b[34mTEST\x1b[0m--------++'), - ([3, 3], '+', '\x1b[34mTEST\x1b[0m---'), - ([4, 2], '+', '\x1b[34mTEST\x1b[0m+--'), - ([5, 1], '+', '\x1b[34mTEST\x1b[0m-+-'), - ([3, 3, 3, 3], '+', '\x1b[34mTEST\x1b[0m---+---+---'), - ([2, 2, 4, 4], '+', '\x1b[34mTEST\x1b[0m-+----+----'), - ([1, 1, 5, 5], '+', '\x1b[34mTEST\x1b[0m-----+-----'), - ([2, 2, 2, 2], '+', '\x1b[34mTEST\x1b[0m-+--+--'), - ([1, 1, 1, 1, 1], '+', '\x1b[34mTEST\x1b[0m-+-+-'), - ([0, 0, 0, 0, 0, 0, 0], '+', '\x1b[34mTEST\x1b[0m++'), - ([1, 1], '+', '-+-'), -]) -@pytest.mark.parametrize('left,right', [('', ''), ('<', '>')]) -@pytest.mark.parametrize('title', [ - '\x1b[34mTEST\x1b[0m', - Color('{blue}TEST{/all}'), - Fore.BLUE + 'TEST' + Style.RESET_ALL, - colored('TEST', 'blue'), -]) + actual = build_border(outer_widths, "-", left, intersect, right, title="معرب") + assert "".join(actual) == expected + + +@pytest.mark.parametrize( + "outer_widths,intersect,expected", + [ + ([12], "+", "\x1b[34mTEST\x1b[0m--------"), + ([12], "", "\x1b[34mTEST\x1b[0m--------"), + ([7, 5], "+", "\x1b[34mTEST\x1b[0m---+-----"), + ([7, 5], "", "\x1b[34mTEST\x1b[0m--------"), + ([4], "+", "\x1b[34mTEST\x1b[0m"), + ([4], "", "\x1b[34mTEST\x1b[0m"), + ([4, 1], "+", "\x1b[34mTEST\x1b[0m+-"), + ([4, 1], "", "\x1b[34mTEST\x1b[0m-"), + ([4, 0], "+", "\x1b[34mTEST\x1b[0m+"), + ([4, 0], "", "\x1b[34mTEST\x1b[0m"), + ([12], "", "\x1b[34mTEST\x1b[0m--------"), + ([6, 6], "", "\x1b[34mTEST\x1b[0m--------"), + ([3, 3, 3, 3], "", "\x1b[34mTEST\x1b[0m--------"), + ([2, 1, 2, 1, 2, 1, 2, 1], "", "\x1b[34mTEST\x1b[0m--------"), + ([1] * 12, "", "\x1b[34mTEST\x1b[0m--------"), + ([2, 4], "", "\x1b[34mTEST\x1b[0m--"), + ([1, 4], "", "\x1b[34mTEST\x1b[0m-"), + ([1, 3], "", "\x1b[34mTEST\x1b[0m"), + ([1, 2], "", "---"), + ([12], "+", "\x1b[34mTEST\x1b[0m--------"), + ([0, 12], "+", "\x1b[34mTEST\x1b[0m---------"), + ([12, 0], "+", "\x1b[34mTEST\x1b[0m--------+"), + ([0, 0, 12], "+", "\x1b[34mTEST\x1b[0m----------"), + ([12, 0, 0], "+", "\x1b[34mTEST\x1b[0m--------++"), + ([3, 3], "+", "\x1b[34mTEST\x1b[0m---"), + ([4, 2], "+", "\x1b[34mTEST\x1b[0m+--"), + ([5, 1], "+", "\x1b[34mTEST\x1b[0m-+-"), + ([3, 3, 3, 3], "+", "\x1b[34mTEST\x1b[0m---+---+---"), + ([2, 2, 4, 4], "+", "\x1b[34mTEST\x1b[0m-+----+----"), + ([1, 1, 5, 5], "+", "\x1b[34mTEST\x1b[0m-----+-----"), + ([2, 2, 2, 2], "+", "\x1b[34mTEST\x1b[0m-+--+--"), + ([1, 1, 1, 1, 1], "+", "\x1b[34mTEST\x1b[0m-+-+-"), + ([0, 0, 0, 0, 0, 0, 0], "+", "\x1b[34mTEST\x1b[0m++"), + ([1, 1], "+", "-+-"), + ], +) +@pytest.mark.parametrize("left,right", [("", ""), ("<", ">")]) +@pytest.mark.parametrize( + "title", + [ + "\x1b[34mTEST\x1b[0m", + Color("{blue}TEST{/all}"), + Fore.BLUE + "TEST" + Style.RESET_ALL, + colored("TEST", "blue"), + ], +) def test_colors(outer_widths, left, intersect, right, title, expected): """Test with color title characters. @@ -291,16 +311,19 @@ def test_colors(outer_widths, left, intersect, right, title, expected): """ if left and right: expected = left + expected + right - actual = build_border(outer_widths, '-', left, intersect, right, title=title) - assert ''.join(actual) == expected - - -@pytest.mark.parametrize('outer_widths,title,expected', [ - ([3, 3, 3], 123, '<123+---+--->'), - ([3, 3, 3], 0.9, '<0.9+---+--->'), - ([3, 3, 3], True, '<True---+--->'), - ([3, 3, 3], False, '<False--+--->'), -]) + actual = build_border(outer_widths, "-", left, intersect, right, title=title) + assert "".join(actual) == expected + + +@pytest.mark.parametrize( + "outer_widths,title,expected", + [ + ([3, 3, 3], 123, "<123+---+--->"), + ([3, 3, 3], 0.9, "<0.9+---+--->"), + ([3, 3, 3], True, "<True---+--->"), + ([3, 3, 3], False, "<False--+--->"), + ], +) def test_non_string(outer_widths, title, expected): """Test with non-string values. @@ -308,5 +331,5 @@ def test_non_string(outer_widths, title, expected): :param title: Title in border. :param str expected: Expected output. """ - actual = build_border(outer_widths, '-', '<', '+', '>', title=title) - assert ''.join(actual) == expected + actual = build_border(outer_widths, "-", "<", "+", ">", title=title) + assert "".join(actual) == expected diff --git a/tests/test_build/test_build_row.py b/tests/test_build/test_build_row.py index ce55944..93aaf37 100644 --- a/tests/test_build/test_build_row.py +++ b/tests/test_build/test_build_row.py @@ -1,16 +1,18 @@ """Test function in module.""" -from terminaltables.build import build_row +from terminaltables3.build import build_row def test_one_line(): """Test with one line cells.""" row = [ - ['Left Cell'], ['Center Cell'], ['Right Cell'], + ["Left Cell"], + ["Center Cell"], + ["Right Cell"], ] - actual = [tuple(i) for i in build_row(row, '>', '|', '<')] + actual = [tuple(i) for i in build_row(row, ">", "|", "<")] expected = [ - ('>', 'Left Cell', '|', 'Center Cell', '|', 'Right Cell', '<'), + (">", "Left Cell", "|", "Center Cell", "|", "Right Cell", "<"), ] assert actual == expected @@ -19,24 +21,22 @@ def test_two_line(): """Test with two line cells.""" row = [ [ - 'Left ', - 'Cell1', + "Left ", + "Cell1", ], - [ - 'Center', - 'Cell2 ', + "Center", + "Cell2 ", ], - [ - 'Right', - 'Cell3', + "Right", + "Cell3", ], ] - actual = [tuple(i) for i in build_row(row, '>', '|', '<')] + actual = [tuple(i) for i in build_row(row, ">", "|", "<")] expected = [ - ('>', 'Left ', '|', 'Center', '|', 'Right', '<'), - ('>', 'Cell1', '|', 'Cell2 ', '|', 'Cell3', '<'), + (">", "Left ", "|", "Center", "|", "Right", "<"), + (">", "Cell1", "|", "Cell2 ", "|", "Cell3", "<"), ] assert actual == expected @@ -45,60 +45,58 @@ def test_three_line(): """Test with three line cells.""" row = [ [ - 'Left ', - 'Cell1', - ' ', + "Left ", + "Cell1", + " ", ], - [ - 'Center', - 'Cell2 ', - ' ', + "Center", + "Cell2 ", + " ", ], - [ - 'Right', - 'Cell3', - ' ', + "Right", + "Cell3", + " ", ], ] - actual = [tuple(i) for i in build_row(row, '>', '|', '<')] + actual = [tuple(i) for i in build_row(row, ">", "|", "<")] expected = [ - ('>', 'Left ', '|', 'Center', '|', 'Right', '<'), - ('>', 'Cell1', '|', 'Cell2 ', '|', 'Cell3', '<'), - ('>', ' ', '|', ' ', '|', ' ', '<'), + (">", "Left ", "|", "Center", "|", "Right", "<"), + (">", "Cell1", "|", "Cell2 ", "|", "Cell3", "<"), + (">", " ", "|", " ", "|", " ", "<"), ] assert actual == expected def test_single(): """Test with single cell.""" - actual = [tuple(i) for i in build_row([['Cell']], '>', '|', '<')] + actual = [tuple(i) for i in build_row([["Cell"]], ">", "|", "<")] expected = [ - ('>', 'Cell', '<'), + (">", "Cell", "<"), ] assert actual == expected def test_empty(): """Test with empty cell.""" - actual = [tuple(i) for i in build_row([['']], '>', '|', '<')] + actual = [tuple(i) for i in build_row([[""]], ">", "|", "<")] expected = [ - ('>', '', '<'), + (">", "", "<"), ] assert actual == expected def test_no_cells(): """Test with no cells.""" - actual = [tuple(i) for i in build_row([[]], '>', '|', '<')] + actual = [tuple(i) for i in build_row([[]], ">", "|", "<")] expected = [ - ('>', '<'), + (">", "<"), ] assert actual == expected - actual = [tuple(i) for i in build_row([], '>', '|', '<')] + actual = [tuple(i) for i in build_row([], ">", "|", "<")] expected = [ - ('>', '<'), + (">", "<"), ] assert actual == expected diff --git a/tests/test_build/test_combine.py b/tests/test_build/test_combine.py index b296ffd..a96d302 100644 --- a/tests/test_build/test_combine.py +++ b/tests/test_build/test_combine.py @@ -2,36 +2,36 @@ import pytest -from terminaltables.build import combine +from terminaltables3.build import combine -@pytest.mark.parametrize('generator', [False, True]) +@pytest.mark.parametrize("generator", [False, True]) def test_borders(generator): """Test with borders. :param bool generator: Test with generator instead of list. """ - line = ['One', 'Two', 'Three'] - actual = list(combine(iter(line) if generator else line, '>', '|', '<')) - assert actual == ['>', 'One', '|', 'Two', '|', 'Three', '<'] + line = ["One", "Two", "Three"] + actual = list(combine(iter(line) if generator else line, ">", "|", "<")) + assert actual == [">", "One", "|", "Two", "|", "Three", "<"] -@pytest.mark.parametrize('generator', [False, True]) +@pytest.mark.parametrize("generator", [False, True]) def test_no_border(generator): """Test without borders. :param bool generator: Test with generator instead of list. """ - line = ['One', 'Two', 'Three'] - actual = list(combine(iter(line) if generator else line, '', '', '')) - assert actual == ['One', 'Two', 'Three'] + line = ["One", "Two", "Three"] + actual = list(combine(iter(line) if generator else line, "", "", "")) + assert actual == ["One", "Two", "Three"] -@pytest.mark.parametrize('generator', [False, True]) +@pytest.mark.parametrize("generator", [False, True]) def test_no_items(generator): """Test with empty list. :param bool generator: Test with generator instead of list. """ - actual = list(combine(iter([]) if generator else [], '>', '|', '<')) - assert actual == ['>', '<'] + actual = list(combine(iter([]) if generator else [], ">", "|", "<")) + assert actual == [">", "<"] diff --git a/tests/test_build/test_flatten.py b/tests/test_build/test_flatten.py index aacfdbd..44e1e18 100644 --- a/tests/test_build/test_flatten.py +++ b/tests/test_build/test_flatten.py @@ -1,25 +1,24 @@ """Test function in module.""" -from terminaltables.build import flatten +from terminaltables3.build import flatten def test_one_line(): """Test with one line cells.""" table = [ - ['>', 'Left Cell', '|', 'Center Cell', '|', 'Right Cell', '<'], + [">", "Left Cell", "|", "Center Cell", "|", "Right Cell", "<"], ] actual = flatten(table) - expected = '>Left Cell|Center Cell|Right Cell<' + expected = ">Left Cell|Center Cell|Right Cell<" assert actual == expected def test_two_line(): """Test with two line cells.""" table = [ - ['>', 'Left ', '|', 'Center', '|', 'Right', '<'], - ['>', 'Cell1', '|', 'Cell2 ', '|', 'Cell3', '<'], + [">", "Left ", "|", "Center", "|", "Right", "<"], + [">", "Cell1", "|", "Cell2 ", "|", "Cell3", "<"], ] actual = flatten(table) - expected = ('>Left |Center|Right<\n' - '>Cell1|Cell2 |Cell3<') + expected = ">Left |Center|Right<\n" ">Cell1|Cell2 |Cell3<" assert actual == expected |