Issue #18727: improve test coverage of the csv module by testing for DictWriter.writerows.

Patch by Muhammad Jehanzeb.
This commit is contained in:
Antoine Pitrou 2014-04-29 01:58:06 +02:00
parent 63aeb71909
commit 05da1ef40a
2 changed files with 11 additions and 0 deletions

View File

@ -575,6 +575,16 @@ class TestDictFields(unittest.TestCase):
fileobj.readline() # header
self.assertEqual(fileobj.read(), "10,,abc\r\n")
def test_write_multiple_dict_rows(self):
fileobj = StringIO()
writer = csv.DictWriter(fileobj, fieldnames=["f1", "f2", "f3"])
writer.writeheader()
self.assertEqual(fileobj.getvalue(), "f1,f2,f3\r\n")
writer.writerows([{"f1": 1, "f2": "abc", "f3": "f"},
{"f1": 2, "f2": 5, "f3": "xyz"}])
self.assertEqual(fileobj.getvalue(),
"f1,f2,f3\r\n1,abc,f\r\n2,5,xyz\r\n")
def test_write_no_fields(self):
fileobj = StringIO()
self.assertRaises(TypeError, csv.DictWriter, fileobj)

View File

@ -613,6 +613,7 @@ Juhana Jauhiainen
Rajagopalasarma Jayakrishnan
Zbigniew Jędrzejewski-Szmek
Julien Jehannet
Muhammad Jehanzeb
Drew Jenkins
Flemming Kjær Jensen
Philip H. Jensen