diff --git a/tabulate/__init__.py b/tabulate/__init__.py index 12a2950..b510ce9 100644 --- a/tabulate/__init__.py +++ b/tabulate/__init__.py @@ -263,7 +263,9 @@ def make_header_line(is_header, colwidths, colaligns): alignment = {"left": "<", "right": ">", "center": "^", "decimal": ">"} # use the column widths generated by tabulate for the asciidoc column width specifiers - asciidoc_alignments = zip(colwidths, [alignment[colalign] for colalign in colaligns]) + asciidoc_alignments = zip( + colwidths, [alignment.get(colalign, "<") for colalign in colaligns] + ) asciidoc_column_specifiers = [f"{align}{width:d}" for width, align in asciidoc_alignments] header_list = ['cols="' + (",".join(asciidoc_column_specifiers)) + '"'] diff --git a/test/test_output.py b/test/test_output.py index ea3da87..ad42da5 100644 --- a/test/test_output.py +++ b/test/test_output.py @@ -2152,6 +2152,24 @@ def test_asciidoc_headerless(): assert_equal(expected, result) +def test_asciidoc_with_none_colalign(): + "Output: asciidoc with disabled column alignment" + expected = "\n".join( + [ + '[cols="<11,>11",options="header"]', + "|====", + "| strings | numbers", + "| spam | 41.9999", + "| eggs | 451", + "|====", + ] + ) + result = tabulate( + _test_table, _test_table_headers, tablefmt="asciidoc", colalign=(None, "right") + ) + assert_equal(expected, result) + + def test_psql(): "Output: psql with headers" expected = "\n".join(