diff options
author | Todd Leonhardt <todd.leonhardt@gmail.com> | 2021-01-28 22:55:11 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-28 22:55:11 -0500 |
commit | 2055dfc9a601d6f2b78e44690aeff475c79369d3 (patch) | |
tree | b715094fcca02b75cd98780eac2b23e18ad3f2ec /tests/test_table_creator.py | |
parent | b329218f3c96398840776b48403323214d7b489b (diff) | |
parent | f8b2407b6079853fdfdd5878480c6883e2c18ded (diff) | |
download | cmd2-git-2055dfc9a601d6f2b78e44690aeff475c79369d3.tar.gz |
Merge pull request #1049 from python-cmd2/header_tabs
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, |