Commit 6a31b0fa authored by Victor Stinner's avatar Victor Stinner

Issue #18829: Add tests for the csv module for invalid characters (delimiter,

escapechar, quotechar)
parent 5f8d4859
...@@ -828,6 +828,19 @@ class TestDialectValidity(unittest.TestCase): ...@@ -828,6 +828,19 @@ class TestDialectValidity(unittest.TestCase):
self.assertEqual(str(cm.exception), self.assertEqual(str(cm.exception),
'"lineterminator" must be a string') '"lineterminator" must be a string')
def test_invalid_chars(self):
def create_invalid(field_name, value):
class mydialect(csv.Dialect):
pass
setattr(mydialect, field_name, value)
d = mydialect()
for field_name in ("delimiter", "escapechar", "quotechar"):
self.assertRaises(csv.Error, create_invalid, field_name, "")
self.assertRaises(csv.Error, create_invalid, field_name, "abc")
self.assertRaises(csv.Error, create_invalid, field_name, b'x')
self.assertRaises(csv.Error, create_invalid, field_name, 5)
class TestSniffer(unittest.TestCase): class TestSniffer(unittest.TestCase):
sample1 = """\ sample1 = """\
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment