Commit 93bd0d60 authored by Serhiy Storchaka's avatar Serhiy Storchaka

Use non-zero and non-last positions in error handler tests.

parent e8cfe521
...@@ -467,16 +467,19 @@ class CodecCallbackTest(unittest.TestCase): ...@@ -467,16 +467,19 @@ class CodecCallbackTest(unittest.TestCase):
) )
# If the correct exception is passed in, "ignore" returns an empty replacement # If the correct exception is passed in, "ignore" returns an empty replacement
self.assertEqual( self.assertEqual(
codecs.ignore_errors(UnicodeEncodeError("ascii", u"\u3042", 0, 1, "ouch")), codecs.ignore_errors(
(u"", 1) UnicodeEncodeError("ascii", u"a\u3042b", 1, 2, "ouch")),
(u"", 2)
) )
self.assertEqual( self.assertEqual(
codecs.ignore_errors(UnicodeDecodeError("ascii", "\xff", 0, 1, "ouch")), codecs.ignore_errors(
(u"", 1) UnicodeDecodeError("ascii", "a\xffb", 1, 2, "ouch")),
(u"", 2)
) )
self.assertEqual( self.assertEqual(
codecs.ignore_errors(UnicodeTranslateError(u"\u3042", 0, 1, "ouch")), codecs.ignore_errors(
(u"", 1) UnicodeTranslateError(u"a\u3042b", 1, 2, "ouch")),
(u"", 2)
) )
def test_badandgoodreplaceexceptions(self): def test_badandgoodreplaceexceptions(self):
...@@ -504,16 +507,19 @@ class CodecCallbackTest(unittest.TestCase): ...@@ -504,16 +507,19 @@ class CodecCallbackTest(unittest.TestCase):
) )
# With the correct exception, "replace" returns an "?" or u"\ufffd" replacement # With the correct exception, "replace" returns an "?" or u"\ufffd" replacement
self.assertEqual( self.assertEqual(
codecs.replace_errors(UnicodeEncodeError("ascii", u"\u3042", 0, 1, "ouch")), codecs.replace_errors(
(u"?", 1) UnicodeEncodeError("ascii", u"a\u3042b", 1, 2, "ouch")),
(u"?", 2)
) )
self.assertEqual( self.assertEqual(
codecs.replace_errors(UnicodeDecodeError("ascii", "\xff", 0, 1, "ouch")), codecs.replace_errors(
(u"\ufffd", 1) UnicodeDecodeError("ascii", "a\xffb", 1, 2, "ouch")),
(u"\ufffd", 2)
) )
self.assertEqual( self.assertEqual(
codecs.replace_errors(UnicodeTranslateError(u"\u3042", 0, 1, "ouch")), codecs.replace_errors(
(u"\ufffd", 1) UnicodeTranslateError(u"a\u3042b", 1, 2, "ouch")),
(u"\ufffd", 2)
) )
def test_badandgoodxmlcharrefreplaceexceptions(self): def test_badandgoodxmlcharrefreplaceexceptions(self):
...@@ -548,9 +554,10 @@ class CodecCallbackTest(unittest.TestCase): ...@@ -548,9 +554,10 @@ class CodecCallbackTest(unittest.TestCase):
cs += (99999, 100000, 999999, 1000000) cs += (99999, 100000, 999999, 1000000)
self.assertEqual( self.assertEqual(
codecs.xmlcharrefreplace_errors( codecs.xmlcharrefreplace_errors(
UnicodeEncodeError("ascii", s, 0, len(s), "ouch") UnicodeEncodeError("ascii", u"a" + s + u"b",
1, 1 + len(s), "ouch")
), ),
(u"".join(u"&#%d;" % c for c in cs), len(s)) (u"".join(u"&#%d;" % c for c in cs), 1 + len(s))
) )
def test_badandgoodbackslashreplaceexceptions(self): def test_badandgoodbackslashreplaceexceptions(self):
...@@ -603,8 +610,9 @@ class CodecCallbackTest(unittest.TestCase): ...@@ -603,8 +610,9 @@ class CodecCallbackTest(unittest.TestCase):
for s, r in tests: for s, r in tests:
self.assertEqual( self.assertEqual(
codecs.backslashreplace_errors( codecs.backslashreplace_errors(
UnicodeEncodeError("ascii", s, 0, len(s), "ouch")), UnicodeEncodeError("ascii", u"a" + s + u"b",
(r, len(s)) 1, 1 + len(s), "ouch")),
(r, 1 + len(s))
) )
def test_badhandlerresults(self): def test_badhandlerresults(self):
......
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