diff options
author | Victor Stinner <victor.stinner@haypocalc.com> | 2011-06-03 21:56:43 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@haypocalc.com> | 2011-06-03 21:56:43 (GMT) |
commit | e3826c77745a251b4f2cdd82f9e1b352f3b13bec (patch) | |
tree | 523baed630f71b1faba6eaf232cbb256095595b3 /Lib/test/test_multibytecodec_support.py | |
parent | 9a1662c2f0a409472d6ef3d4e8b5c61320315f87 (diff) | |
download | cpython-e3826c77745a251b4f2cdd82f9e1b352f3b13bec.zip cpython-e3826c77745a251b4f2cdd82f9e1b352f3b13bec.tar.gz cpython-e3826c77745a251b4f2cdd82f9e1b352f3b13bec.tar.bz2 |
Issue #12016: Add test_errorhandle() to TestBase_Mapping of
test_multibytecodec_support. Improve also error message of the
test_errorhandle() of TestBase.
Diffstat (limited to 'Lib/test/test_multibytecodec_support.py')
-rw-r--r-- | Lib/test/test_multibytecodec_support.py | 42 |
1 files changed, 38 insertions, 4 deletions
diff --git a/Lib/test/test_multibytecodec_support.py b/Lib/test/test_multibytecodec_support.py index 7d3159d..52a2e50 100644 --- a/Lib/test/test_multibytecodec_support.py +++ b/Lib/test/test_multibytecodec_support.py @@ -44,15 +44,24 @@ class TestBase: def test_errorhandle(self): for source, scheme, expected in self.codectests: - if type(source) == type(''): + if isinstance(source, bytes): func = self.decode else: func = self.encode if expected: result = func(source, scheme)[0] - self.assertEqual(result, expected, - '%r.decode(%r)=%r != %r' - % (source, self.encoding, result, expected)) + if func is self.decode: + self.assertTrue(type(result) is unicode, type(result)) + self.assertEqual(result, expected, + '%r.decode(%r, %r)=%r != %r' + % (source, self.encoding, scheme, result, + expected)) + else: + self.assertTrue(type(result) is bytes, type(result)) + self.assertEqual(result, expected, + '%r.encode(%r, %r)=%r != %r' + % (source, self.encoding, scheme, result, + expected)) else: self.assertRaises(UnicodeError, func, source, scheme) @@ -253,6 +262,7 @@ class TestBase_Mapping(unittest.TestCase): pass_enctest = [] pass_dectest = [] supmaps = [] + codectests = [] def __init__(self, *args, **kw): unittest.TestCase.__init__(self, *args, **kw) @@ -331,6 +341,30 @@ class TestBase_Mapping(unittest.TestCase): self.fail('Decoding failed while testing %s -> %s: %s' % ( repr(csetch), repr(unich), exc.reason)) + def test_errorhandle(self): + for source, scheme, expected in self.codectests: + if isinstance(source, bytes): + func = source.decode + else: + func = source.encode + if expected: + if isinstance(source, bytes): + result = func(self.encoding, scheme) + self.assertTrue(type(result) is unicode, type(result)) + self.assertEqual(result, expected, + '%r.decode(%r, %r)=%r != %r' + % (source, self.encoding, scheme, result, + expected)) + else: + result = func(self.encoding, scheme) + self.assertTrue(type(result) is bytes, type(result)) + self.assertEqual(result, expected, + '%r.encode(%r, %r)=%r != %r' + % (source, self.encoding, scheme, result, + expected)) + else: + self.assertRaises(UnicodeError, func, self.encoding, scheme) + def load_teststring(name): dir = os.path.join(os.path.dirname(__file__), 'cjkencodings') with open(os.path.join(dir, name + '.txt'), 'rb') as f: |