Skip to content

Commit

Permalink
Merge pull request #37 from Sideboard/master
Browse files Browse the repository at this point in the history
Fix #28: correct width for wide columns
  • Loading branch information
pri22296 committed Oct 8, 2018
2 parents d3e55f5 + 7794a61 commit b9cd55c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
3 changes: 2 additions & 1 deletion beautifultable/beautifultable.py
Expand Up @@ -622,7 +622,8 @@ def auto_calculate_width(self):
actual_space = sum_ - temp_sum
for i, _ in enumerate(widths):
if not flag[i]:
widths[i] = int(round(widths[i] * avail_space / actual_space))
new_width = int(round(widths[i] * avail_space / actual_space))
widths[i] = min(widths[i], new_width)
self.column_widths = widths

def set_padding_widths(self, pad_width):
Expand Down
12 changes: 12 additions & 0 deletions test.py
Expand Up @@ -371,6 +371,18 @@ def test_table_width_zero(self):
width = self.table.get_table_width()
self.assertEqual(width, 0)

def test_table_auto_width(self):
row_list = ['abcdefghijklmopqrstuvwxyz', 1234, 'none']

self.create_table(200)
self.table.append_row(row_list)
len_for_max_width_200 = len(str(self.table))

self.create_table(80)
self.table.append_row(row_list)
len_for_max_width_80 = len(str(self.table))

self.assertEqual(len_for_max_width_80, len_for_max_width_200)

if __name__ == '__main__':
unittest.main()

0 comments on commit b9cd55c

Please sign in to comment.