diff --git a/Lib/test/test_csv.py b/Lib/test/test_csv.py index f1d14b9191c..83f8cb3cb7a 100644 --- a/Lib/test/test_csv.py +++ b/Lib/test/test_csv.py @@ -828,6 +828,19 @@ class TestDialectValidity(unittest.TestCase): self.assertEqual(str(cm.exception), '"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): sample1 = """\