|
33 | 33 | 'Mars 3390 641.85'])
|
34 | 34 |
|
35 | 35 |
|
| 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 | + |
36 | 50 | def sample_input(sep=' ', with_headers=False):
|
37 | 51 | headers = sep.join(['Planet', 'Radius', 'Mass'])
|
38 | 52 | rows = [sep.join(['Sun', '696000', '1.9891e9']),
|
@@ -136,3 +150,16 @@ def test_script_sep_option():
|
136 | 150 | print("got: ",repr(out))
|
137 | 151 | print("expected:",repr(expected))
|
138 | 152 | 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