[Python-checkins] r81382 - in python/branches/release26-maint: Lib/test/test_csv.py
r.david.murray
python-checkins at python.org
Thu May 20 22:53:34 CEST 2010
Author: r.david.murray
Date: Thu May 20 22:53:34 2010
New Revision: 81382
Log:
Unblocked and 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.
........
Modified:
python/branches/release26-maint/ (props changed)
python/branches/release26-maint/Lib/test/test_csv.py
Modified: python/branches/release26-maint/Lib/test/test_csv.py
==============================================================================
--- python/branches/release26-maint/Lib/test/test_csv.py (original)
+++ python/branches/release26-maint/Lib/test/test_csv.py Thu May 20 22:53:34 2010
@@ -166,6 +166,8 @@
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 @@
# 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 @@
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)
More information about the Python-checkins
mailing list