|
9 | 9 | import unittest, sys, string, codecs, new |
10 | 10 | from test import test_support, string_tests |
11 | 11 |
|
| 12 | +# Error handling (bad decoder return) |
| 13 | +def search_function(encoding): |
| 14 | + def decode1(input, errors="strict"): |
| 15 | + return 42 # not a tuple |
| 16 | + def encode1(input, errors="strict"): |
| 17 | + return 42 # not a tuple |
| 18 | + def encode2(input, errors="strict"): |
| 19 | + return (42, 42) # no unicode |
| 20 | + def decode2(input, errors="strict"): |
| 21 | + return (42, 42) # no unicode |
| 22 | + if encoding=="test.unicode1": |
| 23 | + return (encode1, decode1, None, None) |
| 24 | + elif encoding=="test.unicode2": |
| 25 | + return (encode2, decode2, None, None) |
| 26 | + else: |
| 27 | + return None |
| 28 | +codecs.register(search_function) |
| 29 | + |
12 | 30 | class UnicodeTest( |
13 | 31 | string_tests.CommonTest, |
14 | 32 | string_tests.MixinStrUnicodeUserStringTest, |
@@ -567,23 +585,6 @@ def test_codecs_errors(self): |
567 | 585 | # Error handling (truncated escape sequence) |
568 | 586 | self.assertRaises(UnicodeError, "\\".decode, "unicode-escape") |
569 | 587 |
|
570 | | - # Error handling (bad decoder return) |
571 | | - def search_function(encoding): |
572 | | - def decode1(input, errors="strict"): |
573 | | - return 42 # not a tuple |
574 | | - def encode1(input, errors="strict"): |
575 | | - return 42 # not a tuple |
576 | | - def encode2(input, errors="strict"): |
577 | | - return (42, 42) # no unicode |
578 | | - def decode2(input, errors="strict"): |
579 | | - return (42, 42) # no unicode |
580 | | - if encoding=="test.unicode1": |
581 | | - return (encode1, decode1, None, None) |
582 | | - elif encoding=="test.unicode2": |
583 | | - return (encode2, decode2, None, None) |
584 | | - else: |
585 | | - return None |
586 | | - codecs.register(search_function) |
587 | 588 | self.assertRaises(TypeError, "hello".decode, "test.unicode1") |
588 | 589 | self.assertRaises(TypeError, unicode, "hello", "test.unicode2") |
589 | 590 | self.assertRaises(TypeError, u"hello".encode, "test.unicode1") |
|
0 commit comments