diff options
author | INADA Naoki <songofacandy@gmail.com> | 2016-10-21 10:47:57 (GMT) |
---|---|---|
committer | INADA Naoki <songofacandy@gmail.com> | 2016-10-21 10:47:57 (GMT) |
commit | 0a421a28f87f2a01566e443fc59203d0b7bcb3b8 (patch) | |
tree | fb304d99a0decc4b3beae18b0bbed1704628edf7 /Lib/test | |
parent | 4510e6de9d38987c5b00ce416da19fe9ffc2dde9 (diff) | |
download | cpython-0a421a28f87f2a01566e443fc59203d0b7bcb3b8.zip cpython-0a421a28f87f2a01566e443fc59203d0b7bcb3b8.tar.gz cpython-0a421a28f87f2a01566e443fc59203d0b7bcb3b8.tar.bz2 |
Issue #18219: Optimize csv.DictWriter for large number of columns.
Patch by Mariatta Wijaya.
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_csv.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/Lib/test/test_csv.py b/Lib/test/test_csv.py index 7dcea9c..03ab184 100644 --- a/Lib/test/test_csv.py +++ b/Lib/test/test_csv.py @@ -626,6 +626,24 @@ class TestDictFields(unittest.TestCase): self.assertNotIn("'f2'", exception) self.assertIn("1", exception) + def test_typo_in_extrasaction_raises_error(self): + fileobj = StringIO() + self.assertRaises(ValueError, csv.DictWriter, fileobj, ['f1', 'f2'], + extrasaction="raised") + + def test_write_field_not_in_field_names_raise(self): + fileobj = StringIO() + writer = csv.DictWriter(fileobj, ['f1', 'f2'], extrasaction="raise") + dictrow = {'f0': 0, 'f1': 1, 'f2': 2, 'f3': 3} + self.assertRaises(ValueError, csv.DictWriter.writerow, writer, dictrow) + + def test_write_field_not_in_field_names_ignore(self): + fileobj = StringIO() + writer = csv.DictWriter(fileobj, ['f1', 'f2'], extrasaction="ignore") + dictrow = {'f0': 0, 'f1': 1, 'f2': 2, 'f3': 3} + csv.DictWriter.writerow(writer, dictrow) + self.assertEqual(fileobj.getvalue(), "1,2\r\n") + def test_read_dict_fields(self): with TemporaryFile("w+") as fileobj: fileobj.write("1,2,abc\r\n") |