Skip to content

Commit 04f25a9

Browse files
committed
check column widths too small compared to min
1 parent 209ad8d commit 04f25a9

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

table2ascii/table_to_ascii.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,22 @@ def __init__(self, header: List, body: List[List], footer: List, options: Option
3333
)
3434

3535
# calculate or use given column widths
36-
self.__column_widths = options.column_widths or self.__auto_column_widths()
37-
38-
# check if column widths specified have a different number of columns
39-
if options.column_widths and len(options.column_widths) != self.__columns:
40-
raise ValueError(
41-
"Length of `column_widths` list must equal the number of columns"
42-
)
43-
# check if column widths are not all at least 2
44-
if options.column_widths and min(options.column_widths) < 2:
45-
raise ValueError(
46-
"All values in `column_widths` must be greater than or equal to 2"
47-
)
36+
self.__column_widths = self.__auto_column_widths()
37+
if options.column_widths:
38+
# check that the right number of columns were specified
39+
if len(options.column_widths) != self.__columns:
40+
raise ValueError(
41+
"Length of `column_widths` list must equal the number of columns"
42+
)
43+
# check that each column is at least as large as the minimum size
44+
for i in range(len(options.column_widths)):
45+
option = options.column_widths[i]
46+
minimum = self.__column_widths[i]
47+
if option < minimum:
48+
raise ValueError(
49+
f"The value at index {i} of `column_widths` is {option} which is less than the minimum {minimum}."
50+
)
51+
self.__column_widths = options.column_widths
4852

4953
self.__alignments = options.alignments or [Alignment.CENTER] * self.__columns
5054

0 commit comments

Comments
 (0)