summaryrefslogtreecommitdiff
path: root/tests/test_table_creator.py
diff options
context:
space:
mode:
authorKevin Van Brunt <kmvanbrunt@gmail.com>2021-11-24 10:43:17 -0500
committerKevin Van Brunt <kmvanbrunt@gmail.com>2021-11-24 10:53:36 -0500
commit3065233bbd6d79ad3d5404a82f2400d9a837b8da (patch)
tree1fe2f6585c70cbad5cc9107c3d3d48e1f4c134ea /tests/test_table_creator.py
parent8e9a21c02bc317ba927d758075c8562d0c0b2474 (diff)
downloadcmd2-git-3065233bbd6d79ad3d5404a82f2400d9a837b8da.tar.gz
Added clearer exception handling to BorderedTable and SimpleTable
Diffstat (limited to 'tests/test_table_creator.py')
-rw-r--r--tests/test_table_creator.py24
1 files changed, 23 insertions, 1 deletions
diff --git a/tests/test_table_creator.py b/tests/test_table_creator.py
index 52c4da8b..585ed62a 100644
--- a/tests/test_table_creator.py
+++ b/tests/test_table_creator.py
@@ -316,7 +316,7 @@ def test_generate_row_exceptions():
tc.generate_row(row_data=row_data, is_header=False, **kwargs)
assert "{} contains an unprintable character".format(arg) in str(excinfo.value)
- # data with too many columns
+ # Data with too many columns
row_data = ['Data 1', 'Extra Column']
with pytest.raises(ValueError) as excinfo:
tc.generate_row(row_data=row_data, is_header=False)
@@ -504,6 +504,17 @@ def test_simple_table_width():
assert st.total_width() == 34
+def test_simple_generate_data_row_exceptions():
+ column_1 = Column("Col 1")
+ tc = SimpleTable([column_1])
+
+ # Data with too many columns
+ row_data = ['Data 1', 'Extra Column']
+ with pytest.raises(ValueError) as excinfo:
+ tc.generate_data_row(row_data=row_data)
+ assert "Length of row_data must match length of cols" in str(excinfo.value)
+
+
def test_bordered_table_creation():
column_1 = Column("Col 1", width=15)
column_2 = Column("Col 2", width=15)
@@ -635,6 +646,17 @@ def test_bordered_table_width():
assert bt.total_width() == 37
+def test_bordered_generate_data_row_exceptions():
+ column_1 = Column("Col 1")
+ tc = BorderedTable([column_1])
+
+ # Data with too many columns
+ row_data = ['Data 1', 'Extra Column']
+ with pytest.raises(ValueError) as excinfo:
+ tc.generate_data_row(row_data=row_data)
+ assert "Length of row_data must match length of cols" in str(excinfo.value)
+
+
def test_alternating_table_creation():
column_1 = Column("Col 1", width=15)
column_2 = Column("Col 2", width=15)