Skip to content

Commit ee0472e

Browse files
authored
Merge pull request #331 from cdar/bugfix/322-328/separating-lines
Fix support for separating lines
2 parents 520ed0e + 0655054 commit ee0472e

2 files changed

Lines changed: 36 additions & 3 deletions

File tree

tabulate/__init__.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2419,6 +2419,8 @@ def _expand_iterable(original, num_desired, default):
24192419

24202420
def _pad_row(cells, padding):
24212421
if cells:
2422+
if cells == SEPARATING_LINE:
2423+
return SEPARATING_LINE
24222424
pad = " " * padding
24232425
padded_cells = [pad + cell + pad for cell in cells]
24242426
return padded_cells
@@ -2544,9 +2546,10 @@ def _format_table(
25442546
if padded_rows and fmt.linebetweenrows and "linebetweenrows" not in hidden:
25452547
# initial rows with a line below
25462548
for row, ralign in zip(padded_rows[:-1], rowaligns):
2547-
append_row(
2548-
lines, row, padded_widths, colaligns, fmt.datarow, rowalign=ralign
2549-
)
2549+
if row != SEPARATING_LINE:
2550+
append_row(
2551+
lines, row, padded_widths, colaligns, fmt.datarow, rowalign=ralign
2552+
)
25502553
_append_line(lines, padded_widths, colaligns, fmt.linebetweenrows)
25512554
# the last row without a line below
25522555
append_row(

test/test_output.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,36 @@ def test_simple_headerless_with_sep_line():
339339
assert_equal(expected, result)
340340

341341

342+
def test_simple_headerless_with_sep_line_with_padding_in_tablefmt():
343+
"Output: simple without headers with sep line with padding in tablefmt"
344+
expected = "\n".join(
345+
[
346+
"|------|----------|",
347+
"| spam | 41.9999 |",
348+
"|------|----------|",
349+
"| eggs | 451 |",
350+
]
351+
)
352+
result = tabulate(_test_table_with_sep_line, tablefmt="github")
353+
assert_equal(expected, result)
354+
355+
356+
def test_simple_headerless_with_sep_line_with_linebetweenrows_in_tablefmt():
357+
"Output: simple without headers with sep line with linebetweenrows in tablefmt"
358+
expected = "\n".join(
359+
[
360+
"+------+----------+",
361+
"| spam | 41.9999 |",
362+
"+------+----------+",
363+
"+------+----------+",
364+
"| eggs | 451 |",
365+
"+------+----------+",
366+
]
367+
)
368+
result = tabulate(_test_table_with_sep_line, tablefmt="grid")
369+
assert_equal(expected, result)
370+
371+
342372
def test_simple_multiline_headerless():
343373
"Output: simple with multiline cells without headers"
344374
table = [["foo bar\nbaz\nbau", "hello"], ["", "multiline\nworld"]]

0 commit comments

Comments
 (0)