mirror of
https://github.com/kennethreitz/tablib.git
synced 2026-06-05 23:10:17 +00:00
Merge pull request #150 from brad/csv-newlines
Allow csv fields to have multiple lines.
This commit is contained in:
@@ -35,9 +35,9 @@ def import_set(dset, in_stream, headers=True):
|
||||
dset.wipe()
|
||||
|
||||
if is_py3:
|
||||
rows = csv.reader(in_stream.splitlines())
|
||||
rows = csv.reader(StringIO(in_stream))
|
||||
else:
|
||||
rows = csv.reader(in_stream.splitlines(), encoding=DEFAULT_ENCODING)
|
||||
rows = csv.reader(StringIO(in_stream), encoding=DEFAULT_ENCODING)
|
||||
for i, row in enumerate(rows):
|
||||
|
||||
if (i == 0) and (headers):
|
||||
|
||||
@@ -421,6 +421,22 @@ class TablibTestCase(unittest.TestCase):
|
||||
self.assertEqual(_csv, data.csv)
|
||||
|
||||
|
||||
def test_csv_import_set_with_newlines(self):
|
||||
"""Generate and import CSV set serialization when row values have
|
||||
newlines."""
|
||||
data.append(('Markdown\n=======',
|
||||
'A cool language\n\nwith paragraphs'))
|
||||
data.append(('reStructedText\n==============',
|
||||
'Another cool language\n\nwith paragraphs'))
|
||||
data.headers = ('title', 'body')
|
||||
|
||||
_csv = data.csv
|
||||
|
||||
data.csv = _csv
|
||||
|
||||
self.assertEqual(_csv, data.csv)
|
||||
|
||||
|
||||
def test_tsv_import_set(self):
|
||||
"""Generate and import TSV set serialization."""
|
||||
data.append(self.john)
|
||||
|
||||
Reference in New Issue
Block a user