|
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