Skip to content

Commit

Permalink
TST #31 first column now OK, cols 5, 6, & 9 are 5 short
Browse files Browse the repository at this point in the history
  • Loading branch information
prjemian committed Jul 23, 2019
1 parent 815ca45 commit 5f1eb15
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
15 changes: 12 additions & 3 deletions src/pyRestTable/rest_table.py
Expand Up @@ -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

4 changes: 2 additions & 2 deletions tests/test_results.py
Expand Up @@ -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)


Expand Down

0 comments on commit 5f1eb15

Please sign in to comment.