Skip to content

Commit a342997

Browse files
committed
test tabulate CLI: -f, --format options
1 parent 2c9cd69 commit a342997

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

test/test_cli.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,20 @@
3333
'Mars 3390 641.85'])
3434

3535

36+
SAMPLE_GRID_FORMAT_WITH_HEADERS = "\n".join(
37+
['+----------+----------+---------------+',
38+
'| Planet | Radius | Mass |',
39+
'+==========+==========+===============+',
40+
'| Sun | 696000 | 1.9891e+09 |',
41+
'+----------+----------+---------------+',
42+
'| Earth | 6371 | 5973.6 |',
43+
'+----------+----------+---------------+',
44+
'| Moon | 1737 | 73.5 |',
45+
'+----------+----------+---------------+',
46+
'| Mars | 3390 | 641.85 |',
47+
'+----------+----------+---------------+'])
48+
49+
3650
def sample_input(sep=' ', with_headers=False):
3751
headers = sep.join(['Planet', 'Radius', 'Mass'])
3852
rows = [sep.join(['Sun', '696000', '1.9891e9']),
@@ -136,3 +150,16 @@ def test_script_sep_option():
136150
print("got: ",repr(out))
137151
print("expected:",repr(expected))
138152
assert_equal(out.splitlines(), expected.splitlines())
153+
154+
155+
def test_script_format_option():
156+
"""Command line utility: -f, --format option"""
157+
for option in ["-f", "--format"]:
158+
cmd = ["python", "tabulate.py", "-1", option, "grid"]
159+
raw_table = sample_input(with_headers=True)
160+
out = run_and_capture_stdout(cmd, input=raw_table)
161+
expected = SAMPLE_GRID_FORMAT_WITH_HEADERS
162+
print(out)
163+
print("got: ",repr(out))
164+
print("expected:",repr(expected))
165+
assert_equal(out.splitlines(), expected.splitlines())

0 commit comments

Comments
 (0)