Skip to content

Commit 1fea8a0

Browse files
committed
Add rst/pandas index tests
1 parent c300cdf commit 1fea8a0

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

test/test_output.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,49 @@ def test_pandas_without_index():
455455
raise SkipTest() # this test is optional
456456

457457

458+
def test_pandas_rst_with_index():
459+
"Output: a pandas Dataframe with an index in ReStructuredText format"
460+
try:
461+
import pandas
462+
df = pandas.DataFrame([["one", 1], ["two", None]],
463+
columns=["string", "number"],
464+
index=["a", "b"])
465+
expected = "\n".join(
466+
['== ======== ========',
467+
'- string number',
468+
'== ======== ========',
469+
'a one 1',
470+
'b two nan',
471+
'== ======== ========'])
472+
result = tabulate(df, tablefmt="rst", headers="keys")
473+
assert_equal(expected, result)
474+
except ImportError:
475+
print("test_pandas_rst_with_index is skipped")
476+
raise SkipTest() # this test is optional
477+
478+
479+
def test_pandas_rst_with_named_index():
480+
"Output: a pandas Dataframe with a named index in ReStructuredText format"
481+
try:
482+
import pandas
483+
index = pandas.Index(["a", "b"], name='index')
484+
df = pandas.DataFrame([["one", 1], ["two", None]],
485+
columns=["string", "number"],
486+
index=index)
487+
expected = "\n".join(
488+
['====== ======== ========',
489+
'index string number',
490+
'====== ======== ========',
491+
'a one 1',
492+
'b two nan',
493+
'====== ======== ========'])
494+
result = tabulate(df, tablefmt="rst", headers="keys")
495+
assert_equal(expected, result)
496+
except ImportError:
497+
print("test_pandas_rst_with_index is skipped")
498+
raise SkipTest() # this test is optional
499+
500+
458501
def test_dict_like_with_index():
459502
"Output: a table with a running index"
460503
dd = {"b": range(101,104)}

0 commit comments

Comments
 (0)