Skip to content

Commit 186faad

Browse files
author
Stefan Sullivan
committed
inline assert_in and cleanup print
1 parent ccce663 commit 186faad

File tree

4 files changed

+10
-33
lines changed

4 files changed

+10
-33
lines changed

test/common.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,6 @@
33
import warnings
44

55

6-
def assert_in(result, expected_set):
7-
nums = range(1, len(expected_set) + 1)
8-
for i, expected in zip(nums, expected_set):
9-
print("Expected %d:\n%s\n" % (i, expected))
10-
print("Got:\n%s\n" % result)
11-
assert result in expected_set
12-
13-
146
def cols_to_pipe_str(cols):
157
return "|".join([str(col) for col in cols])
168

test/test_api.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@
1414

1515

1616
def test_tabulate_formats():
17-
"API: tabulate_formats is a list of strings" ""
17+
"API: tabulate_formats is a list of strings"
1818
supported = tabulate_formats
19-
print("tabulate_formats = %r" % supported)
2019
assert type(supported) is list
2120
for fmt in supported:
2221
assert type(fmt) is str # noqa
@@ -26,7 +25,6 @@ def _check_signature(function, expected_sig):
2625
if not signature:
2726
skip("")
2827
actual_sig = signature(function)
29-
print(f"expected: {expected_sig}\nactual: {str(actual_sig)}\n")
3028

3129
assert len(actual_sig.parameters) == len(expected_sig)
3230

test/test_input.py

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
"""Test support of the various forms of tabular data."""
22

33
from tabulate import tabulate
4-
from common import assert_in, raises, skip
4+
from common import raises, skip
55

6-
try:
7-
from collections import UserDict
8-
except ImportError:
9-
# Python2
10-
from UserDict import UserDict
6+
from collections import UserDict
117

128

139
def test_iterable_of_iterables():
@@ -103,8 +99,7 @@ def test_dict_like():
10399
[" b a", "--- ---", "101 0", "102 1", "103 2", "104"]
104100
)
105101
result = tabulate(dd, "keys")
106-
print("Keys' order: %s" % dd.keys())
107-
assert_in(result, [expected1, expected2])
102+
assert result in [expected1, expected2]
108103

109104

110105
def test_numpy_2d():
@@ -377,7 +372,7 @@ def test_list_of_dicts():
377372
expected1 = "\n".join(["- -", "1 2", "3 4", "- -"])
378373
expected2 = "\n".join(["- -", "2 1", "4 3", "- -"])
379374
result = tabulate(lod)
380-
assert_in(result, [expected1, expected2])
375+
assert result in [expected1, expected2]
381376

382377

383378
def test_list_of_userdicts():
@@ -386,7 +381,7 @@ def test_list_of_userdicts():
386381
expected1 = "\n".join(["- -", "1 2", "3 4", "- -"])
387382
expected2 = "\n".join(["- -", "2 1", "4 3", "- -"])
388383
result = tabulate(lod)
389-
assert_in(result, [expected1, expected2])
384+
assert result in [expected1, expected2]
390385

391386

392387
def test_list_of_dicts_keys():
@@ -399,7 +394,7 @@ def test_list_of_dicts_keys():
399394
[" bar foo", "----- -----", " 2 1", " 4 3"]
400395
)
401396
result = tabulate(lod, headers="keys")
402-
assert_in(result, [expected1, expected2])
397+
assert result in [expected1, expected2]
403398

404399

405400
def test_list_of_userdicts_keys():
@@ -412,7 +407,7 @@ def test_list_of_userdicts_keys():
412407
[" bar foo", "----- -----", " 2 1", " 4 3"]
413408
)
414409
result = tabulate(lod, headers="keys")
415-
assert_in(result, [expected1, expected2])
410+
assert result in [expected1, expected2]
416411

417412

418413
def test_list_of_dicts_with_missing_keys():
@@ -442,7 +437,7 @@ def test_list_of_dicts_firstrow():
442437
[" BAR FOO baz", "----- ----- -----", " 4 3 5"]
443438
)
444439
result = tabulate(lod, headers="firstrow")
445-
assert_in(result, [expected1, expected2])
440+
assert result in [expected1, expected2]
446441

447442

448443
def test_list_of_dicts_with_dict_of_headers():
@@ -456,7 +451,7 @@ def test_list_of_dicts_with_dict_of_headers():
456451
["LETTERS DIGITS", "--------- --------", "ABCDE 12345"]
457452
)
458453
result = tabulate(table, headers=headers)
459-
assert_in(result, [expected1, expected2])
454+
assert result in [expected1, expected2]
460455

461456

462457
def test_list_of_dicts_with_list_of_headers():

test/test_regression.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ def test_ansi_color_in_table_cells():
1616
"| test | \x1b[31mtest\x1b[0m | \x1b[32mtest\x1b[0m |",
1717
]
1818
)
19-
print(f"expected: {expected!r}\n\ngot: {formatted!r}\n")
2019
assert expected == formatted
2120

2221

@@ -39,7 +38,6 @@ def test_alignment_of_colored_cells():
3938
"+--------+--------+--------+",
4039
]
4140
)
42-
print(f"expected: {expected!r}\n\ngot: {formatted!r}\n")
4341
assert expected == formatted
4442

4543

@@ -62,7 +60,6 @@ def test_alignment_of_link_cells():
6260
"+--------+--------+--------+",
6361
]
6462
)
65-
print(f"expected: {expected!r}\n\ngot: {formatted!r}\n")
6663
assert expected == formatted
6764

6865

@@ -85,7 +82,6 @@ def test_alignment_of_link_text_cells():
8582
"+--------+----------+--------+",
8683
]
8784
)
88-
print(f"expected: {expected!r}\n\ngot: {formatted!r}\n")
8985
assert expected == formatted
9086

9187

@@ -112,7 +108,6 @@ def mk_headers():
112108
" 0 1 2",
113109
]
114110
)
115-
print(f"expected: {expected!r}\n\ngot: {formatted!r}\n")
116111
assert expected == formatted
117112

118113

@@ -131,7 +126,6 @@ def test_datetime_values():
131126
"------------------- ---------- --------",
132127
]
133128
)
134-
print(f"expected: {expected!r}\n\ngot: {formatted!r}\n")
135129
assert expected == formatted
136130

137131

@@ -142,7 +136,6 @@ def test_simple_separated_format():
142136
fmt = simple_separated_format("!")
143137
expected = "spam!eggs"
144138
formatted = tabulate([["spam", "eggs"]], tablefmt=fmt)
145-
print(f"expected: {expected!r}\n\ngot: {formatted!r}\n")
146139
assert expected == formatted
147140

148141

@@ -200,7 +193,6 @@ def test_88_256_ANSI_color_codes():
200193
"| \x1b[48;5;196mred\x1b[49m | \x1b[38;5;196mred\x1b[39m |",
201194
]
202195
)
203-
print(f"expected: {expected!r}\n\ngot: {formatted!r}\n")
204196
assert expected == formatted
205197

206198

0 commit comments

Comments
 (0)