MCPcopy Index your code
hub / github.com/python/cpython / test_write_fields_not_in_fieldnames

Method test_write_fields_not_in_fieldnames

Lib/test/test_csv.py:871–881  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

869 self.assertRaises(TypeError, csv.DictWriter, fileobj)
870
871 def test_write_fields_not_in_fieldnames(self):
872 with TemporaryFile("w+", encoding="utf-8", newline='') as fileobj:
873 writer = csv.DictWriter(fileobj, fieldnames = ["f1", "f2", "f3"])
874 # Of special note is the non-string key (issue 19449)
875 with self.assertRaises(ValueError) as cx:
876 writer.writerow({"f4": 10, "f2": "spam", 1: "abc"})
877 exception = str(cx.exception)
878 self.assertIn("fieldnames", exception)
879 self.assertIn("'f4'", exception)
880 self.assertNotIn("'f2'", exception)
881 self.assertIn("1", exception)
882
883 def test_typo_in_extrasaction_raises_error(self):
884 fileobj = StringIO()

Callers

nothing calls this directly

Calls 6

writerowMethod · 0.95
TemporaryFileFunction · 0.90
strFunction · 0.85
assertInMethod · 0.80
assertNotInMethod · 0.80
assertRaisesMethod · 0.45

Tested by

no test coverage detected