Skip to content

Commit d354582

Browse files
authored
Test compliance
• Corrected `tabulate` signature in `test/test_api.py::test_tabulate_signature` • In `tabulate/__init__.py::_format_table`, corrected `linebelowheader` alignment to comply with `test/test_regression.py::test_empty_pipe_table_with_columns`. But now that headers' alignment can differ from column', maybe it would be preferable to decide that `linebelowheader` should be aligned with header instead of with column.
1 parent 15da626 commit d354582

File tree

2 files changed

+67
-64
lines changed

2 files changed

+67
-64
lines changed

tabulate/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2416,7 +2416,7 @@ def _format_table(fmt, headers, headersaligns, rows, colwidths, colaligns, is_mu
24162416
if padded_headers:
24172417
append_row(lines, padded_headers, padded_widths, headersaligns, headerrow)
24182418
if fmt.linebelowheader and "linebelowheader" not in hidden:
2419-
_append_line(lines, padded_widths, headersaligns, fmt.linebelowheader)
2419+
_append_line(lines, padded_widths, colaligns, fmt.linebelowheader)
24202420

24212421
if padded_rows and fmt.linebetweenrows and "linebetweenrows" not in hidden:
24222422
# initial rows with a line below

test/test_api.py

Lines changed: 66 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,66 @@
1-
"""API properties.
2-
3-
"""
4-
5-
from tabulate import tabulate, tabulate_formats, simple_separated_format
6-
from common import skip
7-
8-
9-
try:
10-
from inspect import signature, _empty
11-
except ImportError:
12-
signature = None
13-
_empty = None
14-
15-
16-
def test_tabulate_formats():
17-
"API: tabulate_formats is a list of strings" ""
18-
supported = tabulate_formats
19-
print("tabulate_formats = %r" % supported)
20-
assert type(supported) is list
21-
for fmt in supported:
22-
assert type(fmt) is str # noqa
23-
24-
25-
def _check_signature(function, expected_sig):
26-
if not signature:
27-
skip("")
28-
actual_sig = signature(function)
29-
print(f"expected: {expected_sig}\nactual: {str(actual_sig)}\n")
30-
31-
assert len(actual_sig.parameters) == len(expected_sig)
32-
33-
for (e, ev), (a, av) in zip(expected_sig, actual_sig.parameters.items()):
34-
assert e == a and ev == av.default
35-
36-
37-
def test_tabulate_signature():
38-
"API: tabulate() type signature is unchanged" ""
39-
assert type(tabulate) is type(lambda: None) # noqa
40-
expected_sig = [
41-
("tabular_data", _empty),
42-
("headers", ()),
43-
("tablefmt", "simple"),
44-
("floatfmt", "g"),
45-
("intfmt", ""),
46-
("numalign", "default"),
47-
("stralign", "default"),
48-
("missingval", ""),
49-
("showindex", "default"),
50-
("disable_numparse", False),
51-
("colalign", None),
52-
("maxcolwidths", None),
53-
("rowalign", None),
54-
("maxheadercolwidths", None),
55-
]
56-
_check_signature(tabulate, expected_sig)
57-
58-
59-
def test_simple_separated_format_signature():
60-
"API: simple_separated_format() type signature is unchanged" ""
61-
assert type(simple_separated_format) is type(lambda: None) # noqa
62-
expected_sig = [("separator", _empty)]
63-
_check_signature(simple_separated_format, expected_sig)
1+
"""API properties.
2+
3+
"""
4+
5+
from tabulate import tabulate, tabulate_formats, simple_separated_format
6+
from common import skip
7+
8+
9+
try:
10+
from inspect import signature, _empty
11+
except ImportError:
12+
signature = None
13+
_empty = None
14+
15+
16+
def test_tabulate_formats():
17+
"API: tabulate_formats is a list of strings" ""
18+
supported = tabulate_formats
19+
print("tabulate_formats = %r" % supported)
20+
assert type(supported) is list
21+
for fmt in supported:
22+
assert type(fmt) is str # noqa
23+
24+
25+
def _check_signature(function, expected_sig):
26+
if not signature:
27+
skip("")
28+
actual_sig = signature(function)
29+
print(f"expected: {expected_sig}\nactual: {str(actual_sig)}\n")
30+
31+
assert len(actual_sig.parameters) == len(expected_sig)
32+
33+
for (e, ev), (a, av) in zip(expected_sig, actual_sig.parameters.items()):
34+
assert e == a and ev == av.default
35+
36+
37+
def test_tabulate_signature():
38+
"API: tabulate() type signature is unchanged" ""
39+
assert type(tabulate) is type(lambda: None) # noqa
40+
expected_sig = [
41+
("tabular_data", _empty),
42+
("headers", ()),
43+
("tablefmt", "simple"),
44+
("floatfmt", "g"),
45+
("intfmt", ""),
46+
("numalign", "default"),
47+
("stralign", "default"),
48+
("missingval", ""),
49+
("showindex", "default"),
50+
("disable_numparse", False),
51+
("colglobalalign", None),
52+
("colalign", None),
53+
("maxcolwidths", None),
54+
("headersglobalalign", None),
55+
("headersalign", None),
56+
("rowalign", None),
57+
("maxheadercolwidths", None),
58+
]
59+
_check_signature(tabulate, expected_sig)
60+
61+
62+
def test_simple_separated_format_signature():
63+
"API: simple_separated_format() type signature is unchanged" ""
64+
assert type(simple_separated_format) is type(lambda: None) # noqa
65+
expected_sig = [("separator", _empty)]
66+
_check_signature(simple_separated_format, expected_sig)

0 commit comments

Comments
 (0)