diff --git a/src/pyRestTable/rest_table.py b/src/pyRestTable/rest_table.py index 7c2055d..316996d 100644 --- a/src/pyRestTable/rest_table.py +++ b/src/pyRestTable/rest_table.py @@ -372,15 +372,24 @@ def find_widths(self): measure the maximum width of each column, considering possible line breaks in each cell """ + + def col_widths(columns): + result = [] + for s in columns: + # if multi-line, get width of biggest line + widths = [len(p) for p in str(s).split("\n")] + result.append(max(widths)) + return result + width = [] if len(self.labels) > 0: - width = [max(map(len, str(_).split("\n"))) for _ in self.labels] + width = col_widths(self.labels) for row in self.rows: - row_width = [max(map(len, str(_ or '').split("\n"))) for _ in row] + row_width = col_widths(row) if len(width) == 0: width = row_width - width = list(map( max, zip(width, row_width) )) + width = list(map(max, zip(width, row_width) )) return width diff --git a/tests/test_results.py b/tests/test_results.py index e361ff5..d573c30 100644 --- a/tests/test_results.py +++ b/tests/test_results.py @@ -395,8 +395,8 @@ def test_issue_31(self): ] for i in range(len(s)): msg = "row %d: " % (i+1) - msg += "\n received: %s" + s[i] - msg += "\n expected: %s" + expected[i] + msg += "\n received: " + s[i] + msg += "\n expected: " + expected[i] self.assertEqual(s[i], expected[i], msg)