From: Antoine Pitrou Date: Mon, 28 Apr 2014 23:58:06 +0000 (+0200) Subject: Issue #18727: improve test coverage of the csv module by testing for DictWriter.write... X-Git-Tag: v3.5.0a1~1774^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=05da1ef40a4285ee859836d67bced63504dd89b2;p=thirdparty%2FPython%2Fcpython.git Issue #18727: improve test coverage of the csv module by testing for DictWriter.writerows. Patch by Muhammad Jehanzeb. --- diff --git a/Lib/test/test_csv.py b/Lib/test/test_csv.py index 7e2485f954fd..7c31ac71f6e1 100644 --- a/Lib/test/test_csv.py +++ b/Lib/test/test_csv.py @@ -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) diff --git a/Misc/ACKS b/Misc/ACKS index 6e27c367d8c7..2aa087e9f33b 100644 --- a/Misc/ACKS +++ b/Misc/ACKS @@ -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