Skip to content

Commit af40a32

Browse files
author
jerome provensal
committed
Fix bug/issue astanin#231: SEPARATING_LINE feature doesn't work when the requested format pads columns
1 parent 83fd4fb commit af40a32

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

tabulate/__init__.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,17 @@ def _is_file(f):
101101
)
102102

103103

104+
def _is_separating_line_value(value):
105+
return type(value) == str and value.strip() == SEPARATING_LINE
106+
107+
104108
def _is_separating_line(row):
105109
row_type = type(row)
106110
is_sl = (row_type == list or row_type == str) and (
107-
(len(row) >= 1 and row[0] == SEPARATING_LINE)
108-
or (len(row) >= 2 and row[1] == SEPARATING_LINE)
111+
(len(row) >= 1 and _is_separating_line_value(row[0]))
112+
or (len(row) >= 2 and _is_separating_line_value(row[1]))
109113
)
114+
110115
return is_sl
111116

112117

test/test_output.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2881,6 +2881,27 @@ def test_list_of_lists_with_index_with_sep_line():
28812881
assert_equal(expected, result)
28822882

28832883

2884+
def test_with_padded_columns_with_sep_line():
2885+
table = [
2886+
["1", "one"], # "1" as a str on purpose
2887+
[1_000, "one K"],
2888+
SEPARATING_LINE,
2889+
[1_000_000, "one M"],
2890+
]
2891+
expected = "\n".join(
2892+
[
2893+
"+---------+-------+",
2894+
"| 1 | one |",
2895+
"| 1000 | one K |",
2896+
"|---------+-------|",
2897+
"| 1000000 | one M |",
2898+
"+---------+-------+",
2899+
]
2900+
)
2901+
result = tabulate(table, tablefmt="psql")
2902+
assert_equal(expected, result)
2903+
2904+
28842905
def test_list_of_lists_with_supplied_index():
28852906
"Output: a table with a supplied index"
28862907
dd = zip(*[list(range(3)), list(range(101, 104))])

0 commit comments

Comments
 (0)