When using QUOTE_NONNUMERIC, we now test for "numericness" with
PyNumber_Check, rather than trying to convert to a float. Reimplemented
writer - now raises exceptions when it sees a quotechar but neither
doublequote or escapechar are set. Doublequote results are now more
consistent (eg, single quote should generate """", rather than "",
which is ambiguous).
diff --git a/Lib/test/test_csv.py b/Lib/test/test_csv.py
index be1147d..a3c0843 100644
--- a/Lib/test/test_csv.py
+++ b/Lib/test/test_csv.py
@@ -152,25 +152,35 @@
(bigstring, bigstring))
def test_write_quoting(self):
- self._write_test(['a','1','p,q'], 'a,1,"p,q"')
+ self._write_test(['a',1,'p,q'], 'a,1,"p,q"')
self.assertRaises(csv.Error,
self._write_test,
- ['a','1','p,q'], 'a,1,"p,q"',
+ ['a',1,'p,q'], 'a,1,p,q',
quoting = csv.QUOTE_NONE)
- self._write_test(['a','1','p,q'], 'a,1,"p,q"',
+ self._write_test(['a',1,'p,q'], 'a,1,"p,q"',
quoting = csv.QUOTE_MINIMAL)
- self._write_test(['a','1','p,q'], '"a",1,"p,q"',
+ self._write_test(['a',1,'p,q'], '"a",1,"p,q"',
quoting = csv.QUOTE_NONNUMERIC)
- self._write_test(['a','1','p,q'], '"a","1","p,q"',
+ self._write_test(['a',1,'p,q'], '"a","1","p,q"',
quoting = csv.QUOTE_ALL)
def test_write_escape(self):
- self._write_test(['a','1','p,q'], 'a,1,"p,q"',
+ self._write_test(['a',1,'p,q'], 'a,1,"p,q"',
escapechar='\\')
-# FAILED - needs to be fixed [am]:
-# self._write_test(['a','1','p,"q"'], 'a,1,"p,\\"q\\"',
-# escapechar='\\', doublequote = 0)
- self._write_test(['a','1','p,q'], 'a,1,p\\,q',
+ self.assertRaises(csv.Error,
+ self._write_test,
+ ['a',1,'p,"q"'], 'a,1,"p,\\"q\\""',
+ escapechar=None, doublequote=False)
+ self._write_test(['a',1,'p,"q"'], 'a,1,"p,\\"q\\""',
+ escapechar='\\', doublequote = False)
+ self._write_test(['"'], '""""',
+ escapechar='\\', quoting = csv.QUOTE_MINIMAL)
+ self._write_test(['"'], '\\"',
+ escapechar='\\', quoting = csv.QUOTE_MINIMAL,
+ doublequote = False)
+ self._write_test(['"'], '\\"',
+ escapechar='\\', quoting = csv.QUOTE_NONE)
+ self._write_test(['a',1,'p,q'], 'a,1,p\\,q',
escapechar='\\', quoting = csv.QUOTE_NONE)
def test_writerows(self):