Skip to content

Commit 0655054

Browse files
committed
Fix support for separating lines
1 parent 95ae5eb commit 0655054

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
@@ -2304,6 +2304,8 @@ def _expand_iterable(original, num_desired, default):
23042304

23052305
def _pad_row(cells, padding):
23062306
if cells:
2307+
if cells == SEPARATING_LINE:
2308+
return SEPARATING_LINE
23072309
pad = " " * padding
23082310
padded_cells = [pad + cell + pad for cell in cells]
23092311
return padded_cells
@@ -2427,9 +2429,10 @@ def _format_table(fmt, headers, headersaligns, rows, colwidths, colaligns, is_mu
24272429
if padded_rows and fmt.linebetweenrows and "linebetweenrows" not in hidden:
24282430
# initial rows with a line below
24292431
for row, ralign in zip(padded_rows[:-1], rowaligns):
2430-
append_row(
2431-
lines, row, padded_widths, colaligns, fmt.datarow, rowalign=ralign
2432-
)
2432+
if row != SEPARATING_LINE:
2433+
append_row(
2434+
lines, row, padded_widths, colaligns, fmt.datarow, rowalign=ralign
2435+
)
24332436
_append_line(lines, padded_widths, colaligns, fmt.linebetweenrows)
24342437
# the last row without a line below
24352438
append_row(

test/test_output.py

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

337337

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

0 commit comments

Comments
 (0)