def test_list_of_lists_with_index_firstrow(): "Output: a table with a running index and header='firstrow'" dd = zip(*[["a"] + list(range(3)), ["b"] + list(range(101, 104))]) expected = "\n".join([ " a b", "-- --- ---", " 0 0 101", " 1 1 102", " 2 2 103" ]) result = tabulate(dd, headers="firstrow", showindex=True) assert_equal(result, expected) # TODO: make it a separate test case # the index must be as long as the number of rows with raises(ValueError): tabulate(dd, headers="firstrow", showindex=[1, 2])
def test_list_of_lists_with_supplied_index(): "Output: a table with a supplied index" dd = zip(*[list(range(3)), list(range(101, 104))]) expected = "\n".join([ " a b", "-- --- ---", " 1 0 101", " 2 1 102", " 3 2 103" ]) result = tabulate(dd, headers=["a", "b"], showindex=[1, 2, 3]) assert_equal(result, expected) # TODO: make it a separate test case # the index must be as long as the number of rows with raises(ValueError): tabulate(dd, headers=["a", "b"], showindex=[1, 2])
def test_list_of_dicts_with_list_of_headers(): "Input: ValueError on a list of headers with a list of dicts (issue #23)" table = [{"letters": "ABCDE", "digits": 12345}] headers = ["DIGITS", "LETTERS"] with raises(ValueError): tabulate(table, headers=headers)