summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKane Blueriver <kxxoling@gmail.com>2016-07-13 12:28:15 +0800
committerGitHub <noreply@github.com>2016-07-13 12:28:15 +0800
commitda0f4a58b81baa89164b41fc33944bff3df89279 (patch)
tree69f5fe86b1657b3f7162c24c815603d389f1b28a
parent707487dd01a7315273f387e5e324fcc374b459ca (diff)
parent131bd6bb776f2f1e7036e4f9caa4282cda68fda1 (diff)
downloadpython-prettytable-ptable-da0f4a58b81baa89164b41fc33944bff3df89279.tar.gz
Merge pull request #2 from Sebelino/develop
Fix padding issue when ``padding_width == 0``
-rw-r--r--prettytable/prettytable.py5
-rw-r--r--tests/test_prettytable.py28
2 files changed, 32 insertions, 1 deletions
diff --git a/prettytable/prettytable.py b/prettytable/prettytable.py
index d2899a8..b556db4 100644
--- a/prettytable/prettytable.py
+++ b/prettytable/prettytable.py
@@ -129,7 +129,10 @@ class PrettyTable(object):
self._min_table_width = kwargs["min_table_width"] or None
self._max_table_width = kwargs["max_table_width"] or None
- self._padding_width = kwargs["padding_width"] or 1
+ if kwargs["padding_width"] is None:
+ self._padding_width = 1
+ else:
+ self._padding_width = kwargs["padding_width"]
self._left_padding_width = kwargs["left_padding_width"] or None
self._right_padding_width = kwargs["right_padding_width"] or None
diff --git a/tests/test_prettytable.py b/tests/test_prettytable.py
index b337088..d65fe0a 100644
--- a/tests/test_prettytable.py
+++ b/tests/test_prettytable.py
@@ -640,5 +640,33 @@ class PrintJapaneseTest(unittest.TestCase):
print(self.x)
+class UnpaddedTableTest(unittest.TestCase):
+ def setUp(self):
+ self.x = PrettyTable(header=False, padding_width=0)
+ self.x.add_row("abc")
+ self.x.add_row("def")
+ self.x.add_row("g..")
+
+ def testUnbordered(self):
+ self.x.border = False
+ result = self.x.get_string()
+ assert result.strip() == """
+abc
+def
+g..
+""".strip()
+
+ def testBordered(self):
+ self.x.border = True
+ result = self.x.get_string()
+ assert result.strip() == """
++-+-+-+
+|a|b|c|
+|d|e|f|
+|g|.|.|
++-+-+-+
+""".strip()
+
+
if __name__ == "__main__":
unittest.main()