[Python-checkins] cpython (3.4): Use non-zero and non-last positions in error handler tests.

serhiy.storchaka python-checkins at python.org
Mon Mar 16 07:32:18 CET 2015


https://hg.python.org/cpython/rev/d44a908b7ca0
changeset:   95005:d44a908b7ca0
branch:      3.4
parent:      95000:b64bacba1cee
user:        Serhiy Storchaka <storchaka at gmail.com>
date:        Mon Mar 16 08:29:47 2015 +0200
summary:
  Use non-zero and non-last positions in error handler tests.

files:
  Lib/test/test_codeccallbacks.py |  52 +++++++++++---------
  1 files changed, 28 insertions(+), 24 deletions(-)


diff --git a/Lib/test/test_codeccallbacks.py b/Lib/test/test_codeccallbacks.py
--- a/Lib/test/test_codeccallbacks.py
+++ b/Lib/test/test_codeccallbacks.py
@@ -446,18 +446,18 @@
         # If the correct exception is passed in, "ignore" returns an empty replacement
         self.assertEqual(
             codecs.ignore_errors(
-                UnicodeEncodeError("ascii", "\u3042", 0, 1, "ouch")),
-            ("", 1)
+                UnicodeEncodeError("ascii", "a\u3042b", 1, 2, "ouch")),
+            ("", 2)
         )
         self.assertEqual(
             codecs.ignore_errors(
-                UnicodeDecodeError("ascii", bytearray(b"\xff"), 0, 1, "ouch")),
-            ("", 1)
+                UnicodeDecodeError("ascii", bytearray(b"a\xffb"), 1, 2, "ouch")),
+            ("", 2)
         )
         self.assertEqual(
             codecs.ignore_errors(
-                UnicodeTranslateError("\u3042", 0, 1, "ouch")),
-            ("", 1)
+                UnicodeTranslateError("a\u3042b", 1, 2, "ouch")),
+            ("", 2)
         )
 
     def test_badandgoodreplaceexceptions(self):
@@ -486,18 +486,18 @@
         # With the correct exception, "replace" returns an "?" or "\ufffd" replacement
         self.assertEqual(
             codecs.replace_errors(
-                UnicodeEncodeError("ascii", "\u3042", 0, 1, "ouch")),
-            ("?", 1)
+                UnicodeEncodeError("ascii", "a\u3042b", 1, 2, "ouch")),
+            ("?", 2)
         )
         self.assertEqual(
             codecs.replace_errors(
-                UnicodeDecodeError("ascii", bytearray(b"\xff"), 0, 1, "ouch")),
-            ("\ufffd", 1)
+                UnicodeDecodeError("ascii", bytearray(b"a\xffb"), 1, 2, "ouch")),
+            ("\ufffd", 2)
         )
         self.assertEqual(
             codecs.replace_errors(
-                UnicodeTranslateError("\u3042", 0, 1, "ouch")),
-            ("\ufffd", 1)
+                UnicodeTranslateError("a\u3042b", 1, 2, "ouch")),
+            ("\ufffd", 2)
         )
 
     def test_badandgoodxmlcharrefreplaceexceptions(self):
@@ -531,9 +531,10 @@
         s = "".join(chr(c) for c in cs)
         self.assertEqual(
             codecs.xmlcharrefreplace_errors(
-                UnicodeEncodeError("ascii", s, 0, len(s), "ouch")
+                UnicodeEncodeError("ascii", "a" + s + "b",
+                                   1, 1 + len(s), "ouch")
             ),
-            ("".join("&#%d;" % c for c in cs), len(s))
+            ("".join("&#%d;" % c for c in cs), 1 + len(s))
         )
 
     def test_badandgoodbackslashreplaceexceptions(self):
@@ -580,8 +581,9 @@
             with self.subTest(str=s):
                 self.assertEqual(
                     codecs.backslashreplace_errors(
-                        UnicodeEncodeError("ascii", s, 0, len(s), "ouch")),
-                    (r, len(s))
+                        UnicodeEncodeError("ascii", "a" + s + "b",
+                                           1, 1 + len(s), "ouch")),
+                    (r, 1 + len(s))
                 )
 
     def test_badandgoodsurrogateescapeexceptions(self):
@@ -614,8 +616,8 @@
                 )
         self.assertEqual(
             surrogateescape_errors(
-                UnicodeEncodeError("ascii", "\udc80", 0, 1, "ouch")),
-            (b"\x80", 1)
+                UnicodeEncodeError("ascii", "a\udc80b", 1, 2, "ouch")),
+            (b"\x80", 2)
         )
         self.assertRaises(
             UnicodeDecodeError,
@@ -624,8 +626,8 @@
         )
         self.assertEqual(
             surrogateescape_errors(
-                UnicodeDecodeError("ascii", bytearray(b"\x80"), 0, 1, "ouch")),
-            ("\udc80", 1)
+                UnicodeDecodeError("ascii", bytearray(b"a\x80b"), 1, 2, "ouch")),
+            ("\udc80", 2)
         )
 
     def test_badandgoodsurrogatepassexceptions(self):
@@ -685,13 +687,15 @@
             with self.subTest(encoding=enc, str=s, bytes=b):
                 self.assertEqual(
                     surrogatepass_errors(
-                        UnicodeEncodeError(enc, s, 0, len(s), "ouch")),
-                    (b, len(s))
+                        UnicodeEncodeError(enc, "a" + s + "b",
+                                           1, 1 + len(s), "ouch")),
+                    (b, 1 + len(s))
                 )
                 self.assertEqual(
                     surrogatepass_errors(
-                        UnicodeDecodeError(enc, bytearray(b[:n]), 0, n, "ouch")),
-                    (s[:1], n)
+                        UnicodeDecodeError(enc, bytearray(b"a" + b[:n] + b"b"),
+                                           1, n, "ouch")),
+                    (s[:1], 1 + n)
                 )
 
     def test_badhandlerresults(self):

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list