mirror of
https://github.com/python/cpython.git
synced 2025-08-30 05:35:08 +00:00
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).
This commit is contained in:
parent
31d8896ee2
commit
c89f284df8
3 changed files with 81 additions and 92 deletions
|
@ -152,25 +152,35 @@ class Test_Csv(unittest.TestCase):
|
|||
(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):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue