diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2017-12-12 10:56:40 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2017-12-12 10:56:40 (GMT) |
commit | ce5a3cd9b15c9379753aefabd696bff11495cbbb (patch) | |
tree | 00853192072af43d64be4aca732f2fca9298c6c4 /Lib/test | |
parent | 82adaf5ffe425f3d3360e972df03ff15584b4035 (diff) | |
download | cpython-ce5a3cd9b15c9379753aefabd696bff11495cbbb.zip cpython-ce5a3cd9b15c9379753aefabd696bff11495cbbb.tar.gz cpython-ce5a3cd9b15c9379753aefabd696bff11495cbbb.tar.bz2 |
bpo-32255: Always quote a single empty field when write into a CSV file. (GH-4769) (#4810)
This allows to distinguish an empty row from a row consisting of a single empty field.
(cherry picked from commit 2001900b0c02a397d8cf1d776a7cc7fcb2a463e3)
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_csv.py | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/Lib/test/test_csv.py b/Lib/test/test_csv.py index 03ab184..fe24801 100644 --- a/Lib/test/test_csv.py +++ b/Lib/test/test_csv.py @@ -207,10 +207,29 @@ class Test_Csv(unittest.TestCase): with TemporaryFile("w+", newline='') as fileobj: writer = csv.writer(fileobj) self.assertRaises(TypeError, writer.writerows, None) - writer.writerows([['a','b'],['c','d']]) + writer.writerows([['a', 'b'], ['c', 'd']]) fileobj.seek(0) self.assertEqual(fileobj.read(), "a,b\r\nc,d\r\n") + def test_writerows_with_none(self): + with TemporaryFile("w+", newline='') as fileobj: + writer = csv.writer(fileobj) + writer.writerows([['a', None], [None, 'd']]) + fileobj.seek(0) + self.assertEqual(fileobj.read(), "a,\r\n,d\r\n") + + with TemporaryFile("w+", newline='') as fileobj: + writer = csv.writer(fileobj) + writer.writerows([[None], ['a']]) + fileobj.seek(0) + self.assertEqual(fileobj.read(), '""\r\na\r\n') + + with TemporaryFile("w+", newline='') as fileobj: + writer = csv.writer(fileobj) + writer.writerows([['a'], [None]]) + fileobj.seek(0) + self.assertEqual(fileobj.read(), 'a\r\n""\r\n') + @support.cpython_only def test_writerows_legacy_strings(self): import _testcapi |