Skip to content

Commit 476e400

Browse files
author
Stefan Sullivan
committed
add support and tests for min_padding
1 parent 186faad commit 476e400

File tree

3 files changed

+30
-9
lines changed

3 files changed

+30
-9
lines changed

tabulate/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -813,7 +813,7 @@ def escape_empty(val):
813813
)
814814

815815

816-
def simple_separated_format(separator):
816+
def simple_separated_format(separator, **kwargs):
817817
"""Construct a simple TableFormat with columns separated by a separator.
818818
819819
>>> tsv = simple_separated_format("\\t") ; \
@@ -830,6 +830,7 @@ def simple_separated_format(separator):
830830
datarow=DataRow("", separator, ""),
831831
padding=0,
832832
with_header_hide=None,
833+
**kwargs
833834
)
834835

835836

test/test_api.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,12 @@ def _check_signature(function, expected_sig):
2525
if not signature:
2626
skip("")
2727
actual_sig = signature(function)
28-
29-
assert len(actual_sig.parameters) == len(expected_sig)
30-
31-
for (e, ev), (a, av) in zip(expected_sig, actual_sig.parameters.items()):
32-
assert e == a and ev == av.default
28+
actual_sig = [(k, v.default) for k, v in actual_sig.parameters.items()]
29+
assert actual_sig == expected_sig
3330

3431

3532
def test_tabulate_signature():
36-
"API: tabulate() type signature is unchanged" ""
33+
"API: tabulate() type signature is unchanged"
3734
assert type(tabulate) is type(lambda: None) # noqa
3835
expected_sig = [
3936
("tabular_data", _empty),
@@ -58,7 +55,10 @@ def test_tabulate_signature():
5855

5956

6057
def test_simple_separated_format_signature():
61-
"API: simple_separated_format() type signature is unchanged" ""
58+
"API: simple_separated_format() type signature is unchanged"
6259
assert type(simple_separated_format) is type(lambda: None) # noqa
63-
expected_sig = [("separator", _empty)]
60+
expected_sig = [
61+
("separator", _empty),
62+
("kwargs", _empty),
63+
]
6464
_check_signature(simple_separated_format, expected_sig)

test/test_output.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Test output of the various forms of tabular data."""
2+
import textwrap
23

34
import tabulate as tabulate_module
45
from common import raises, skip, check_warnings
@@ -242,6 +243,25 @@ def test_simple():
242243
assert expected == result
243244

244245

246+
def test_simple_with_zero_padding():
247+
""" Output custom simple table built with a new column separator """
248+
expected = textwrap.dedent("""\
249+
strings numbers
250+
eggs 451""")
251+
result = tabulate([_test_table[-1]], _test_table_headers, tablefmt=simple_separated_format(" ", min_padding=0))
252+
assert result == expected
253+
254+
255+
def test_simple_with_zero_padding_and_alignment():
256+
""" Output custom simple table built with a new column separator """
257+
expected = textwrap.dedent("""\
258+
strings numbers
259+
spam 41.9999
260+
eggs 451""")
261+
result = tabulate(_test_table, _test_table_headers, tablefmt=simple_separated_format(" ", min_padding=0))
262+
assert result == expected
263+
264+
245265
def test_simple_with_sep_line():
246266
"Output: simple with headers and separating line"
247267
expected = "\n".join(

0 commit comments

Comments
 (0)