Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion Lib/test/test_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -918,6 +918,13 @@ def test_dict_reader_fieldnames_accepts_list(self):
reader = csv.DictReader(f, fieldnames)
self.assertEqual(reader.fieldnames, fieldnames)

def test_dict_reader_set_fieldnames(self):
fieldnames = ["a", "b", "c"]
f = StringIO()
reader = csv.DictReader(f)
reader.fieldnames = fieldnames
self.assertEqual(reader.fieldnames, fieldnames)
Comment thread
JanEricNitschke marked this conversation as resolved.

def test_dict_writer_fieldnames_rejects_iter(self):
fieldnames = ["a", "b", "c"]
f = StringIO()
Expand All @@ -933,6 +940,7 @@ def test_dict_writer_fieldnames_accepts_list(self):
def test_dict_reader_fieldnames_is_optional(self):
f = StringIO()
reader = csv.DictReader(f, fieldnames=None)
self.assertEqual(reader.fieldnames, None)
Comment thread
JanEricNitschke marked this conversation as resolved.
Outdated

def test_read_dict_fields(self):
with TemporaryFile("w+", encoding="utf-8") as fileobj:
Expand All @@ -951,7 +959,7 @@ def test_read_dict_no_fieldnames(self):
self.assertEqual(reader.fieldnames, ["f1", "f2", "f3"])

# Two test cases to make sure existing ways of implicitly setting
# fieldnames continue to work. Both arise from discussion in issue3436.
# fieldnames continue to work. Both arise from discussion in issue3436.
Comment thread
JanEricNitschke marked this conversation as resolved.
Outdated
def test_read_dict_fieldnames_from_file(self):
with TemporaryFile("w+", encoding="utf-8") as fileobj:
fileobj.write("f1,f2,f3\r\n1,2,abc\r\n")
Expand Down Expand Up @@ -1353,6 +1361,9 @@ class TestSniffer(unittest.TestCase):
ghi\0jkl
"""

sample15 = "\n\n\n"
sample16 = "abc\ndef\nghi"

def test_issue43625(self):
sniffer = csv.Sniffer()
self.assertTrue(sniffer.has_header(self.sample12))
Expand Down Expand Up @@ -1423,6 +1434,11 @@ def test_delimiters(self):
self.assertEqual(dialect.quotechar, "'")
dialect = sniffer.sniff(self.sample14)
self.assertEqual(dialect.delimiter, '\0')
self.assertRaisesRegex(csv.Error, "Could not determine delimiter",
sniffer.sniff, self.sample15)
self.assertRaisesRegex(csv.Error, "Could not determine delimiter",
sniffer.sniff, self.sample16)

Comment thread
JanEricNitschke marked this conversation as resolved.

def test_doublequote(self):
sniffer = csv.Sniffer()
Expand Down
Loading