diff options
author | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2021-01-28 16:13:28 -0500 |
---|---|---|
committer | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2021-01-28 16:13:28 -0500 |
commit | da203d25dff1f05511af43b4f73fd537678d6e03 (patch) | |
tree | 39706ba9c3178594b46f3eaf611f2de3e6e5a81a /tests/test_table_creator.py | |
parent | 44eb9d4e1946a3cc9a10fe85ccb617b6076f627c (diff) | |
download | cmd2-git-da203d25dff1f05511af43b4f73fd537678d6e03.tar.gz |
Fixed width calculation when table column headers had tabs
Diffstat (limited to 'tests/test_table_creator.py')
-rw-r--r-- | tests/test_table_creator.py | 42 |
1 files changed, 30 insertions, 12 deletions
diff --git a/tests/test_table_creator.py b/tests/test_table_creator.py index 58dd6fdf..0a0e712d 100644 --- a/tests/test_table_creator.py +++ b/tests/test_table_creator.py @@ -20,18 +20,6 @@ from cmd2.table_creator import ( def test_column_creation(): - # No width specified, blank label - c = Column("") - assert c.width == 1 - - # No width specified, label isn't blank but has no width - c = Column(ansi.style('', fg=ansi.fg.green)) - assert c.width == 1 - - # No width specified, label has width - c = Column("short\nreally long") - assert c.width == ansi.style_aware_wcswidth("really long") - # Width less than 1 with pytest.raises(ValueError) as excinfo: Column("Column 1", width=0) @@ -46,6 +34,36 @@ def test_column_creation(): Column("Column 1", max_data_lines=0) assert "Max data lines cannot be less than 1" in str(excinfo.value) + # No width specified, blank label + c = Column("") + assert c.width is None + tc = TableCreator([c]) + assert tc.cols[0].width == 1 + + # No width specified, label isn't blank but has no width + c = Column(ansi.style('', fg=ansi.fg.green)) + assert c.width is None + tc = TableCreator([c]) + assert tc.cols[0].width == 1 + + # No width specified, label has width + c = Column("a line") + assert c.width is None + tc = TableCreator([c]) + assert tc.cols[0].width == ansi.style_aware_wcswidth("a line") + + # No width specified, label has width and multiple lines + c = Column("short\nreally long") + assert c.width is None + tc = TableCreator([c]) + assert tc.cols[0].width == ansi.style_aware_wcswidth("really long") + + # No width specified, label has tabs + c = Column("line\twith\ttabs") + assert c.width is None + tc = TableCreator([c]) + assert tc.cols[0].width == ansi.style_aware_wcswidth("line with tabs") + def test_column_alignment(): column_1 = Column("Col 1", width=10, |