mirror of
https://github.com/kennethreitz/tablib.git
synced 2026-06-05 06:56:13 +00:00
Fixes #368 - Avoid crashing when exporting empty string in ReST
This commit is contained in:
@@ -6,6 +6,10 @@
|
||||
|
||||
- Dropped Python 2 support
|
||||
|
||||
### Bugfixes
|
||||
|
||||
- Fixed a crash when exporting an empty string with the ReST format (#368)
|
||||
|
||||
## 0.14.0 (2019-10-19)
|
||||
|
||||
### Deprecations
|
||||
|
||||
@@ -34,7 +34,7 @@ def _max_word_len(text):
|
||||
8
|
||||
|
||||
"""
|
||||
return max((len(word) for word in text.split()))
|
||||
return max((len(word) for word in text.split())) if text else 0
|
||||
|
||||
|
||||
def _get_column_string_lengths(dataset):
|
||||
|
||||
+29
-11
@@ -486,17 +486,6 @@ class TablibTestCase(BaseTestCase):
|
||||
self.founders.append(('First\nSecond', 'Name', 42))
|
||||
self.founders.export('xlsx')
|
||||
|
||||
def test_rst_force_grid(self):
|
||||
data.append(self.john)
|
||||
data.append(self.george)
|
||||
data.headers = self.headers
|
||||
|
||||
simple = tablib.formats._rst.export_set(data)
|
||||
grid = tablib.formats._rst.export_set(data, force_grid=True)
|
||||
self.assertNotEqual(simple, grid)
|
||||
self.assertNotIn('+', simple)
|
||||
self.assertIn('+', grid)
|
||||
|
||||
|
||||
class HTMLTests(BaseTestCase):
|
||||
def test_html_export(self):
|
||||
@@ -538,6 +527,35 @@ class HTMLTests(BaseTestCase):
|
||||
self.assertEqual(html, d.html)
|
||||
|
||||
|
||||
class RSTTests(BaseTestCase):
|
||||
def test_rst_force_grid(self):
|
||||
data = tablib.Dataset()
|
||||
data.append(self.john)
|
||||
data.append(self.george)
|
||||
data.headers = self.headers
|
||||
|
||||
simple = tablib.formats._rst.export_set(data)
|
||||
grid = tablib.formats._rst.export_set(data, force_grid=True)
|
||||
self.assertNotEqual(simple, grid)
|
||||
self.assertNotIn('+', simple)
|
||||
self.assertIn('+', grid)
|
||||
|
||||
def test_empty_string(self):
|
||||
data = tablib.Dataset()
|
||||
data.headers = self.headers
|
||||
data.append(self.john)
|
||||
data.append(('Wendy', '', 43))
|
||||
self.assertEqual(
|
||||
data.export('rst'),
|
||||
'========== ========= ===\n'
|
||||
'first_name last_name gpa\n'
|
||||
'========== ========= ===\n'
|
||||
'John Adams 90 \n'
|
||||
'Wendy 43 \n'
|
||||
'========== ========= ==='
|
||||
)
|
||||
|
||||
|
||||
class CSVTests(BaseTestCase):
|
||||
def test_csv_format_detect(self):
|
||||
"""Test CSV format detection."""
|
||||
|
||||
Reference in New Issue
Block a user