1818 VerticalAlignment ,
1919)
2020
21+ # Turn off black formatting for entire file so multiline strings
22+ # can be visually aligned to match the tables being tested.
23+ # fmt: off
24+
2125
2226def test_column_creation ():
2327 # Width less than 1
@@ -119,19 +123,37 @@ def test_column_alignment():
119123 )
120124
121125
126+ def test_blank_last_line ():
127+ """This tests that an empty line is inserted when the last data line is blank"""
128+ column_1 = Column ("Col 1" , width = 10 )
129+ tc = TableCreator ([column_1 ])
130+
131+ row_data = ['my line\n \n ' ]
132+ row = tc .generate_row (row_data = row_data )
133+ assert row == ('my line \n '
134+ ' ' )
135+
136+
122137def test_wrap_text ():
123138 column_1 = Column ("Col 1" , width = 10 )
124139 tc = TableCreator ([column_1 ])
125140
126141 # Test normal wrapping
127142 row_data = ['Some text to wrap\n A new line that will wrap\n Not wrap\n 1 2 3' ]
128143 row = tc .generate_row (row_data = row_data )
129- assert row == ('Some text \n ' 'to wrap \n ' 'A new line\n ' 'that will \n ' 'wrap \n ' 'Not wrap \n ' ' 1 2 3 ' )
144+ assert row == ('Some text \n '
145+ 'to wrap \n '
146+ 'A new line\n '
147+ 'that will \n '
148+ 'wrap \n '
149+ 'Not wrap \n '
150+ ' 1 2 3 ' )
130151
131152 # Test preserving a multiple space sequence across a line break
132153 row_data = ['First last one' ]
133154 row = tc .generate_row (row_data = row_data )
134- assert row == ('First \n ' ' last one ' )
155+ assert row == ('First \n '
156+ ' last one ' )
135157
136158
137159def test_wrap_text_max_lines ():
@@ -141,27 +163,32 @@ def test_wrap_text_max_lines():
141163 # Test not needing to truncate the final line
142164 row_data = ['First line last line' ]
143165 row = tc .generate_row (row_data = row_data )
144- assert row == ('First line\n ' 'last line ' )
166+ assert row == ('First line\n '
167+ 'last line ' )
145168
146169 # Test having to truncate the last word because it's too long for the final line
147170 row_data = ['First line last lineextratext' ]
148171 row = tc .generate_row (row_data = row_data )
149- assert row == ('First line\n ' 'last line…' )
172+ assert row == ('First line\n '
173+ 'last line…' )
150174
151175 # Test having to truncate the last word because it fits the final line but there is more text not being included
152176 row_data = ['First line thistxtfit extra' ]
153177 row = tc .generate_row (row_data = row_data )
154- assert row == ('First line\n ' 'thistxtfi…' )
178+ assert row == ('First line\n '
179+ 'thistxtfi…' )
155180
156181 # Test having to truncate the last word because it fits the final line but there are more lines not being included
157182 row_data = ['First line thistxtfit\n extra' ]
158183 row = tc .generate_row (row_data = row_data )
159- assert row == ('First line\n ' 'thistxtfi…' )
184+ assert row == ('First line\n '
185+ 'thistxtfi…' )
160186
161187 # Test having space left on the final line and adding an ellipsis because there are more lines not being included
162188 row_data = ['First line last line\n extra line' ]
163189 row = tc .generate_row (row_data = row_data )
164- assert row == ('First line\n ' 'last line…' )
190+ assert row == ('First line\n '
191+ 'last line…' )
165192
166193
167194def test_wrap_long_word ():
@@ -174,7 +201,8 @@ def test_wrap_long_word():
174201
175202 # Test header row
176203 header = tc .generate_row ()
177- assert header == ('LongColumn \n ' 'Name Col 2 ' )
204+ assert header == ('LongColumn \n '
205+ 'Name Col 2 ' )
178206
179207 # Test data row
180208 row_data = list ()
@@ -230,7 +258,8 @@ def test_wrap_long_word_max_data_lines():
230258 row_data .append ("A LongerThan10RunsOverLast" )
231259
232260 row = tc .generate_row (row_data = row_data )
233- assert row == ('LongerThan LongerThan LongerThan A LongerT…\n ' '10FitsLast 10FitsLas… 10RunsOve… ' )
261+ assert row == ('LongerThan LongerThan LongerThan A LongerT…\n '
262+ '10FitsLast 10FitsLas… 10RunsOve… ' )
234263
235264
236265def test_wrap_long_char_wider_than_max_width ():
@@ -318,7 +347,10 @@ def test_simple_table_creation():
318347 table = st .generate_table (row_data )
319348
320349 assert table == (
321- 'Col 1 Col 2 \n ' 'Col 1 Row 1 Col 2 Row 1 \n ' '\n ' 'Col 1 Row 2 Col 2 Row 2 '
350+ 'Col 1 Col 2 \n '
351+ 'Col 1 Row 1 Col 2 Row 1 \n '
352+ '\n '
353+ 'Col 1 Row 2 Col 2 Row 2 '
322354 )
323355
324356 # No row spacing
@@ -335,7 +367,9 @@ def test_simple_table_creation():
335367 st = SimpleTable ([column_1 , column_2 ])
336368 table = st .generate_table (row_data , include_header = False )
337369
338- assert table == ('Col 1 Row 1 Col 2 Row 1 \n ' '\n ' 'Col 1 Row 2 Col 2 Row 2 ' )
370+ assert table == ('Col 1 Row 1 Col 2 Row 1 \n '
371+ '\n '
372+ 'Col 1 Row 2 Col 2 Row 2 ' )
339373
340374 # Wide custom divider (divider needs no padding)
341375 st = SimpleTable ([column_1 , column_2 ], divider_char = '深' )
0 commit comments