]> granicus.if.org Git - python/commitdiff
(Merge 3.3) Issue #18829: Add tests for the csv module for invalid characters
authorVictor Stinner <victor.stinner@gmail.com>
Thu, 2 Jan 2014 11:53:50 +0000 (12:53 +0100)
committerVictor Stinner <victor.stinner@gmail.com>
Thu, 2 Jan 2014 11:53:50 +0000 (12:53 +0100)
(delimiter, escapechar, quotechar)

1  2 
Lib/test/test_csv.py

index cbde78145f1236de09631f4048084b3a5423beed,83f8cb3cb7a4583bdd690225ebea8d1071e0084d..7e2485f954fdd96b0c7679288318fa981b9647ef
@@@ -837,6 -828,19 +837,20 @@@ class TestDialectValidity(unittest.Test
          self.assertEqual(str(cm.exception),
                           '"lineterminator" must be a string')
  
 -            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)
+     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"):
++            with self.subTest(field_name=field_name):
++                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 = """\