Fixed __unicode__/__str__ for dataset with no headers

This commit is contained in:
Tom Christie
2016-02-25 13:28:29 +00:00
parent ee9666a146
commit d720beadac
2 changed files with 14 additions and 2 deletions
+4 -2
View File
@@ -223,7 +223,8 @@ class Dataset(object):
result = []
# Add unicode representation of headers.
result.append([unicode(h) for h in self.__headers])
if self.__headers:
result.append([unicode(h) for h in self.__headers])
# Add unicode representation of rows.
result.extend(list(map(unicode, row)) for row in self._data)
@@ -232,7 +233,8 @@ class Dataset(object):
field_lens = list(map(max, zip(*lens)))
# delimiter between header and data
result.insert(1, ['-' * length for length in field_lens])
if self.__headers:
result.insert(1, ['-' * length for length in field_lens])
format_string = '|'.join('{%s:%s}' % item for item in enumerate(field_lens))
+10
View File
@@ -351,6 +351,16 @@ class TablibTestCase(unittest.TestCase):
self.assertFalse('^' in output)
self.assertTrue('textasciicircum' in output)
def test_str_no_columns(self):
d = tablib.Dataset(['a', 1], ['b', 2], ['c', 3])
output = '%s' % d
self.assertEqual(output.splitlines(), [
'a|1',
'b|2',
'c|3'
])
def test_unicode_append(self):
"""Passes in a single unicode character and exports."""