summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAlexander Artemenko <svetlyak.40wt@gmail.com>2016-05-08 01:23:59 +0300
committerkxxoling <kxxoling@gmail.com>2016-07-13 13:36:41 +0800
commit3d29afd679c95238c8857a499b06179e752bbcc3 (patch)
treea74e18d7a40dc04cff89a69dc8e0937bf363fbcc /tests
parentd0fda1050c8ac8c9df8bfe91ce711d13839271d6 (diff)
downloadpython-prettytable-ptable-3d29afd679c95238c8857a499b06179e752bbcc3.tar.gz
Now column scaling algorithm more strictly respects "max_table_width" setting.
Diffstat (limited to 'tests')
-rw-r--r--tests/test_prettytable.py47
1 files changed, 47 insertions, 0 deletions
diff --git a/tests/test_prettytable.py b/tests/test_prettytable.py
index b337088..09ea4b7 100644
--- a/tests/test_prettytable.py
+++ b/tests/test_prettytable.py
@@ -458,6 +458,53 @@ class BreakLineTests(unittest.TestCase):
""".strip()
+class MaxMaxWidthsTests(unittest.TestCase):
+ def testMaxTableWidthIsTheLaw(self):
+ max_width = 127
+ t = PrettyTable(max_table_width=max_width)
+ t.field_names = ['tag', 'versions']
+
+ versions = [
+ 'python/django-appconf:1.0.1',
+ 'python/django-braces:1.8.1',
+ 'python/django-compressor:2.0',
+ 'python/django-debug-toolbar:1.4',
+ 'python/django-extensions:1.6.1',
+ ]
+ t.add_row(['allmychanges.com', ', '.join(versions)])
+ result = t.get_string(hrules=ALL)
+ lines = result.strip().split('\n')
+
+ for line in lines:
+ line_length = len(line)
+ self.assertEqual(line_length, max_width)
+
+
+ def testMaxTableWidthIsTheLawWhenMinColumnWidthSetForSomeColumns(self):
+ max_width = 40
+ t = PrettyTable(max_table_width=max_width)
+ t.field_names = ['tag', 'versions']
+ versions = [
+ 'python/django-appconf:1.0.1',
+ 'python/django-braces:1.8.1',
+ 'python/django-compressor:2.0',
+ 'python/django-debug-toolbar:1.4',
+ 'python/django-extensions:1.6.1',
+ ]
+ t.add_row(['allmychanges.com', ', '.join(versions)])
+
+ # Now, we'll set min width for first column
+ # to not wrap it's content
+ t._min_width['tag'] = len('allmychanges.com')
+
+ result = t.get_string(hrules=ALL)
+ lines = result.strip().split('\n')
+
+ for line in lines:
+ line_length = len(line)
+ self.assertEqual(line_length, max_width)
+
+
class HtmlOutputTests(unittest.TestCase):
def testHtmlOutput(self):
t = PrettyTable(['Field 1', 'Field 2', 'Field 3'])