Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion humanfriendly/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ def format_robust_table(data, column_names):
blocks.append(lines)
# Calculate the width of the row delimiter.
num_rows, num_columns = find_terminal_size()
longest_line = max(max(map(ansi_width, lines)) for lines in blocks)
longest_line = max([ansi_width(line) for lines in blocks for line in lines] or [0])
delimiter = u"\n%s\n" % ('-' * min(longest_line, num_columns))
# Force a delimiter at the start and end of the table.
blocks.insert(0, "")
Expand Down
7 changes: 7 additions & 0 deletions humanfriendly/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,13 @@ class HumanFriendlyTestCase(TestCase):

"""Container for the `humanfriendly` test suite."""

def test_empty_robust_table(self):
"""Empty query results produce no rows instead of raising ValueError."""
from humanfriendly.tables import format_robust_table
assert format_robust_table([], ['name', 'value']) == ''
assert format_robust_table(iter([]), ['name']) == ''
assert format_robust_table([[]], []) == ''

def test_case_insensitive_dict(self):
"""Test the CaseInsensitiveDict class."""
# Test support for the dict(iterable) signature.
Expand Down