diff options
author | R. David Murray <rdmurray@bitdance.com> | 2009-04-01 21:26:18 (GMT) |
---|---|---|
committer | R. David Murray <rdmurray@bitdance.com> | 2009-04-01 21:26:18 (GMT) |
commit | 3864459196cc8d5f9477d6e635736cc2372f257e (patch) | |
tree | fc0c0902f3a9494028bdfed1103b4b25c25543cb /Lib | |
parent | cafc225f5463a720d3e9da252371995be61b127f (diff) | |
download | cpython-3864459196cc8d5f9477d6e635736cc2372f257e.zip cpython-3864459196cc8d5f9477d6e635736cc2372f257e.tar.gz cpython-3864459196cc8d5f9477d6e635736cc2372f257e.tar.bz2 |
Add tests checking the CSV module's ability to handle
embedded newlines in quoted field values.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_csv.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/Lib/test/test_csv.py b/Lib/test/test_csv.py index b239f75..5544904 100644 --- a/Lib/test/test_csv.py +++ b/Lib/test/test_csv.py @@ -166,6 +166,8 @@ class Test_Csv(unittest.TestCase): quoting = csv.QUOTE_NONNUMERIC) self._write_test(['a',1,'p,q'], '"a","1","p,q"', quoting = csv.QUOTE_ALL) + self._write_test(['a\nb',1], '"a\nb","1"', + quoting = csv.QUOTE_ALL) def test_write_escape(self): self._write_test(['a',1,'p,q'], 'a,1,"p,q"', @@ -245,6 +247,7 @@ class Test_Csv(unittest.TestCase): # will this fail where locale uses comma for decimals? self._read_test([',3,"5",7.3, 9'], [['', 3, '5', 7.3, 9]], quoting=csv.QUOTE_NONNUMERIC) + self._read_test(['"a\nb", 7'], [['a\nb', ' 7']]) self.assertRaises(ValueError, self._read_test, ['abc,3'], [[]], quoting=csv.QUOTE_NONNUMERIC) @@ -282,6 +285,21 @@ class Test_Csv(unittest.TestCase): self.assertRaises(StopIteration, r.next) self.assertEqual(r.line_num, 3) + def test_roundtrip_quoteed_newlines(self): + fd, name = tempfile.mkstemp() + fileobj = os.fdopen(fd, "w+b") + try: + writer = csv.writer(fileobj) + self.assertRaises(TypeError, writer.writerows, None) + rows = [['a\nb','b'],['c','x\r\nd']] + writer.writerows(rows) + fileobj.seek(0) + for i, row in enumerate(csv.reader(fileobj)): + self.assertEqual(row, rows[i]) + finally: + fileobj.close() + os.unlink(name) + class TestDialectRegistry(unittest.TestCase): def test_registry_badargs(self): self.assertRaises(TypeError, csv.list_dialects, None) |