Repository: pri22296/beautifultable

Issue:
Incorrect calculation of column width
Minimal example:
```py
table = beautifultable.BeautifulTable(max_width=150)
table.column_headers = ['t', 'u', 'v', 'w', 'x', 'y', 'z']
table.append_row(['q123456789012345678', 'a', 'b', 'c', 'd', 'e', 'f'])
print(table)
```

Output:
```
+----------------------------------------------------------------------------------------------------------------------------+---+---+---+---+---+---+
|                                                             t                                                              | u | v | w | x | y | z |
+----------------------------------------------------------------------------------------------------------------------------+---+---+---+---+---+---+
|                                                    q123456789012345678                                                     | a | b | c | d | e | f |
+----------------------------------------------------------------------------------------------------------------------------+---+---+---+---+---+---+
```

The first column is too wide. If I omit the last character, it works as expected:
```py
table.append_row(['q12345678901234567', 'a', 'b', 'c', 'd', 'e', 'f'])
```
```
+--------------------+---+---+---+---+---+---+
|         t          | u | v | w | x | y | z |
+--------------------+---+---+---+---+---+---+
| q12345678901234567 | a | b | c | d | e | f |
+--------------------+---+---+---+---+---+---+
```

It also seems to work as expected if I change the `max_width`, or if I use fewer columns.


Discussion:
coveralls: 
[![Coverage Status](https://coveralls.io/builds/19388578/badge)](https://coveralls.io/builds/19388578)

Coverage increased (+0.1%) to 78.662% when pulling **978717442ecec309e869354ad98254032368ca67 on Sideboard:master** into **d3e55f597be47dbfb245768d23a0176c1b059f1e on pri22296:master**.

coveralls: 
[![Coverage Status](https://coveralls.io/builds/19388578/badge)](https://coveralls.io/builds/19388578)

Coverage increased (+0.1%) to 78.662% when pulling **978717442ecec309e869354ad98254032368ca67 on Sideboard:master** into **d3e55f597be47dbfb245768d23a0176c1b059f1e on pri22296:master**.

coveralls: 
[![Coverage Status](https://coveralls.io/builds/19388578/badge)](https://coveralls.io/builds/19388578)

Coverage increased (+0.1%) to 78.662% when pulling **978717442ecec309e869354ad98254032368ca67 on Sideboard:master** into **d3e55f597be47dbfb245768d23a0176c1b059f1e on pri22296:master**.

coveralls: 
[![Coverage Status](https://coveralls.io/builds/19388578/badge)](https://coveralls.io/builds/19388578)

Coverage increased (+0.1%) to 78.662% when pulling **978717442ecec309e869354ad98254032368ca67 on Sideboard:master** into **d3e55f597be47dbfb245768d23a0176c1b059f1e on pri22296:master**.

coveralls: 
[![Coverage Status](https://coveralls.io/builds/19388578/badge)](https://coveralls.io/builds/19388578)

Coverage increased (+0.1%) to 78.662% when pulling **978717442ecec309e869354ad98254032368ca67 on Sideboard:master** into **d3e55f597be47dbfb245768d23a0176c1b059f1e on pri22296:master**.

pri22296: Thanks for the Pull Request. Can you just squash the 2 commits into a single one? Other than that this looks good to me.

Patch:
diff --git a/beautifultable/beautifultable.py b/beautifultable/beautifultable.py
index 0835eca..804e7a6 100644
--- a/beautifultable/beautifultable.py
+++ b/beautifultable/beautifultable.py
@@ -622,7 +622,8 @@ class BeautifulTable(object):
         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):


Test patch:
diff --git a/test.py b/test.py
index a02b6bc..edc0c45 100644
--- a/test.py
+++ b/test.py
@@ -371,6 +371,18 @@ class TableOperationsTestCase(unittest.TestCase):
         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()