From 6a31b0fa19cb5684b144a2f3e5ba1d59b4fd7913 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Thu, 2 Jan 2014 12:53:13 +0100 Subject: Issue #18829: Add tests for the csv module for invalid characters (delimiter, escapechar, quotechar) --- Lib/test/test_csv.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Lib/test/test_csv.py b/Lib/test/test_csv.py index f1d14b9..83f8cb3 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 = """\ -- cgit v0.12