diff options
author | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2020-04-22 01:54:33 -0400 |
---|---|---|
committer | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2020-04-22 01:54:33 -0400 |
commit | f261f0df4d3831d47d5f38b12cc0d7bc747cd89d (patch) | |
tree | a969df2f09c2ae1baadbe27a913371d858165882 /tests/test_table_creator.py | |
parent | ba5d7befdc7fe5ec95437a840ca83a612f041a93 (diff) | |
download | cmd2-git-f261f0df4d3831d47d5f38b12cc0d7bc747cd89d.tar.gz |
Added unit tests for padding
Diffstat (limited to 'tests/test_table_creator.py')
-rw-r--r-- | tests/test_table_creator.py | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/tests/test_table_creator.py b/tests/test_table_creator.py index a85ab214..917ba5cc 100644 --- a/tests/test_table_creator.py +++ b/tests/test_table_creator.py @@ -332,6 +332,22 @@ def test_bordered_table(): '║ Col 1 Row 2 │ Col 2 Row 2 ║\n' '╚═════════════════╧═════════════════╝\n') + # Non-default padding + bt = BorderedTable([column_1, column_2], padding=2) + table = bt.generate_table(row_data) + assert table == ('╔═══════════════════╤═══════════════════╗\n' + '║ Col 1 │ Col 2 ║\n' + '╠═══════════════════╪═══════════════════╣\n' + '║ Col 1 Row 1 │ Col 2 Row 1 ║\n' + '╟───────────────────┼───────────────────╢\n' + '║ Col 1 Row 2 │ Col 2 Row 2 ║\n' + '╚═══════════════════╧═══════════════════╝\n') + + # Invalid padding + with pytest.raises(ValueError) as excinfo: + BorderedTable([column_1, column_2], padding=-1) + assert "Padding cannot be less than 0" in str(excinfo.value) + def test_alternating_table(): column_1 = Column("Col 1", width=15) @@ -378,3 +394,18 @@ def test_alternating_table(): '║ Col 1 Row 1 │ Col 2 Row 1 ║\n' '\x1b[100m║ \x1b[49m\x1b[0m\x1b[100mCol 1 Row 2\x1b[49m\x1b[0m\x1b[100m \x1b[49m\x1b[100m \x1b[49m\x1b[100m \x1b[49m\x1b[100m \x1b[49m\x1b[0m\x1b[100m │ \x1b[49m\x1b[0m\x1b[100mCol 2 Row 2\x1b[49m\x1b[0m\x1b[100m \x1b[49m\x1b[100m \x1b[49m\x1b[100m \x1b[49m\x1b[100m \x1b[49m\x1b[0m\x1b[100m ║\x1b[49m\n' '╚═════════════════╧═════════════════╝\n') + + # Non-default padding + at = AlternatingTable([column_1, column_2], padding=2) + table = at.generate_table(row_data) + assert table == ('╔═══════════════════╤═══════════════════╗\n' + '║ Col 1 │ Col 2 ║\n' + '╠═══════════════════╪═══════════════════╣\n' + '║ Col 1 Row 1 │ Col 2 Row 1 ║\n' + '\x1b[100m║ \x1b[49m\x1b[0m\x1b[100mCol 1 Row 2\x1b[49m\x1b[0m\x1b[100m \x1b[49m\x1b[100m \x1b[49m\x1b[100m \x1b[49m\x1b[100m \x1b[49m\x1b[0m\x1b[100m │ \x1b[49m\x1b[0m\x1b[100mCol 2 Row 2\x1b[49m\x1b[0m\x1b[100m \x1b[49m\x1b[100m \x1b[49m\x1b[100m \x1b[49m\x1b[100m \x1b[49m\x1b[0m\x1b[100m ║\x1b[49m\n' + '╚═══════════════════╧═══════════════════╝\n') + + # Invalid padding + with pytest.raises(ValueError) as excinfo: + AlternatingTable([column_1, column_2], padding=-1) + assert "Padding cannot be less than 0" in str(excinfo.value) |