Skip to content

Commit f615afc

Browse files
committed
Validate fields in constructor
1 parent 0d03c87 commit f615afc

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

table2ascii/__init__.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,17 @@ class TableToAscii:
1111
"""Class used to convert a 2D Python table to ASCII text"""
1212

1313
def __init__(self, header_row: List, body: List[List], footer_row: List):
14+
"""Validate arguments and initialize fields"""
15+
# check that values are valid
16+
if len(header_row) != len(footer_row):
17+
raise ValueError("header row and footer row must have the same length")
18+
if len(header_row) != len(body[0]):
19+
raise ValueError("header row and body rows must have the same length")
20+
for row in body[1:]:
21+
if len(body[0]) != len(row):
22+
raise ValueError("all rows in body must have the same length")
23+
24+
# initialize fields
1425
self.__header_row = header_row
1526
self.__body = body
1627
self.__footer_row = footer_row

0 commit comments

Comments
 (0)