diff --git a/tabulate/__init__.py b/tabulate/__init__.py index 12a2950..cf449e6 100644 --- a/tabulate/__init__.py +++ b/tabulate/__init__.py @@ -2488,7 +2488,7 @@ def _expand_iterable(original, num_desired, default): length `num_desired` completely populated with `default will be returned """ if isinstance(original, Iterable) and not isinstance(original, str): - return original + [default] * (num_desired - len(original)) + return list(original) + [default] * (num_desired - len(original)) else: return [default] * num_desired diff --git a/test/test_internal.py b/test/test_internal.py index 49ae0ba..b08aea4 100644 --- a/test/test_internal.py +++ b/test/test_internal.py @@ -355,3 +355,8 @@ def test__reinsert_separating_lines(): expected = rows_to_pipe_table_str(with_rows) assert_equal(expected, rows_to_pipe_table_str(sans_rows)) + +def test_expand_iterable_accepts_tuple(): + "Internal: _expand_iterable pads tuples the same way as lists (issue #434)" + assert_equal(["top", "bottom"], T._expand_iterable(("top", "bottom"), 2, "top")) + assert_equal(["left", "left", "left"], T._expand_iterable(("left",), 3, "left")) diff --git a/test/test_regression.py b/test/test_regression.py index 9555676..7f44fde 100644 --- a/test/test_regression.py +++ b/test/test_regression.py @@ -598,3 +598,9 @@ def test_github_escape_pipe_character(): result = tabulate([["foo|bar"]], headers=("spam|eggs",), tablefmt="github") expected = "| spam\\|eggs |\n|:------------|\n| foo\\|bar |" assert_equal(expected, result) + +def test_rowalign_tuple(): + "Regression: rowalign (and other sequence kwargs) accept tuples (issue #434)" + result = tabulate([[1, 2], [3, 4]], rowalign=("top", "bottom")) + expected = tabulate([[1, 2], [3, 4]], rowalign=["top", "bottom"]) + assert_equal(expected, result)