summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_csv.py
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2014-04-28 23:58:06 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2014-04-28 23:58:06 (GMT)
commit05da1ef40a4285ee859836d67bced63504dd89b2 (patch)
tree84c2043a4b0cda01169507556a72c1629bafffb5 /Lib/test/test_csv.py
parent63aeb71909f3058ee69f6e39478f541a045c2fbd (diff)
downloadcpython-05da1ef40a4285ee859836d67bced63504dd89b2.zip
cpython-05da1ef40a4285ee859836d67bced63504dd89b2.tar.gz
cpython-05da1ef40a4285ee859836d67bced63504dd89b2.tar.bz2
Issue #18727: improve test coverage of the csv module by testing for DictWriter.writerows.
Patch by Muhammad Jehanzeb.
Diffstat (limited to 'Lib/test/test_csv.py')
-rw-r--r--Lib/test/test_csv.py10
1 files changed, 10 insertions, 0 deletions
diff --git a/Lib/test/test_csv.py b/Lib/test/test_csv.py
index 7e2485f..7c31ac7 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)