From 1e58df6110389360cd7eed005120c1d3597ff3b8 Mon Sep 17 00:00:00 2001 From: matthewhegarty Date: Mon, 21 Feb 2022 15:55:19 +0000 Subject: [PATCH] added newline kwarg to StringIO (#517) --- src/tablib/utils.py | 2 +- tests/test_tablib.py | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/tablib/utils.py b/src/tablib/utils.py index 39de8ce4..97bae72e 100644 --- a/src/tablib/utils.py +++ b/src/tablib/utils.py @@ -7,7 +7,7 @@ def normalize_input(stream): file-like object. """ if isinstance(stream, str): - return StringIO(stream) + return StringIO(stream, newline='') elif isinstance(stream, bytes): return BytesIO(stream) return stream diff --git a/tests/test_tablib.py b/tests/test_tablib.py index 0ee4e86d..46e562db 100755 --- a/tests/test_tablib.py +++ b/tests/test_tablib.py @@ -824,6 +824,14 @@ def test_csv_import_set_skip_lines(self): dataset = tablib.import_set(csv_text, format="csv", skip_lines=2) self.assertEqual(dataset.headers, ['id', 'name','description']) + def test_csv_import_mac_os_lf(self): + csv_text = ( + 'id,name,description\r' + '12,Smith,rounded\r' + ) + dataset = tablib.import_set(csv_text, format="csv") + self.assertEqual(dataset.headers, ['id', 'name','description']) + def test_csv_export(self): """Verify exporting dataset object as CSV."""