diff options
-rw-r--r-- | cmd2/table_creator.py | 4 | ||||
-rw-r--r-- | tests/test_table_creator.py | 4 |
2 files changed, 8 insertions, 0 deletions
diff --git a/cmd2/table_creator.py b/cmd2/table_creator.py index 2579f3c6..5d6b444d 100644 --- a/cmd2/table_creator.py +++ b/cmd2/table_creator.py @@ -132,7 +132,11 @@ class TableCreator: :param cols: column definitions for this table :param tab_width: all tabs will be replaced with this many spaces. If a row's fill_char is a tab, then it will be converted to one space. + :raises: ValueError if tab_width is less than 1 """ + if tab_width < 1: + raise ValueError("Tab width cannot be less than 1") + self.cols = copy.copy(cols) self.tab_width = tab_width diff --git a/tests/test_table_creator.py b/tests/test_table_creator.py index 0a0e712d..649674a4 100644 --- a/tests/test_table_creator.py +++ b/tests/test_table_creator.py @@ -259,6 +259,10 @@ def test_tabs(): inter_cell='\t', post_line='\t') assert row == ' Col 1 Col 2 ' + with pytest.raises(ValueError) as excinfo: + TableCreator([column_1, column_2], tab_width=0) + assert "Tab width cannot be less than 1" in str(excinfo.value) + def test_simple_table_creation(): column_1 = Column("Col 1", width=16) |