diff options
author | R. David Murray <rdmurray@bitdance.com> | 2009-04-01 22:37:58 (GMT) |
---|---|---|
committer | R. David Murray <rdmurray@bitdance.com> | 2009-04-01 22:37:58 (GMT) |
commit | cde68cfc14e5b381916528056c26dcb6df95ceb4 (patch) | |
tree | c58660f539a5f93cdff292f2703d70dcf7e02f3d /Lib | |
parent | 0e4caf4bd2e5a964c916a06fff64d5cadbe623b6 (diff) | |
download | cpython-cde68cfc14e5b381916528056c26dcb6df95ceb4.zip cpython-cde68cfc14e5b381916528056c26dcb6df95ceb4.tar.gz cpython-cde68cfc14e5b381916528056c26dcb6df95ceb4.tar.bz2 |
Merged revisions 70997 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r70997 | r.david.murray | 2009-04-01 17:26:18 -0400 (Wed, 01 Apr 2009) | 3 lines
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 | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/Lib/test/test_csv.py b/Lib/test/test_csv.py index 9c9840b..c24c55f 100644 --- a/Lib/test/test_csv.py +++ b/Lib/test/test_csv.py @@ -162,6 +162,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"', @@ -241,6 +243,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) @@ -276,6 +279,16 @@ class Test_Csv(unittest.TestCase): self.assertRaises(StopIteration, next, r) self.assertEqual(r.line_num, 3) + def test_roundtrip_quoteed_newlines(self): + with TemporaryFile("w+", newline='') as fileobj: + 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]) + class TestDialectRegistry(unittest.TestCase): def test_registry_badargs(self): self.assertRaises(TypeError, csv.list_dialects, None) |