mirror of
https://github.com/kennethreitz/tablib.git
synced 2026-06-05 15:00:19 +00:00
Merge pull request #228 from tomchristie/print-dataset-with-no-headers
Fixed textual representation for Dataset with no headers
This commit is contained in:
+4
-2
@@ -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))
|
||||
|
||||
|
||||
@@ -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."""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user