summaryrefslogtreecommitdiff
path: root/Lib/test
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2011-06-03 17:50:59 -0500
committerBenjamin Peterson <benjamin@python.org>2011-06-03 17:50:59 -0500
commit0ba18e6c0243282b5cfbbbba4a94395fd38eee8f (patch)
tree55da8faed05b12d7c3df226ec39ee13908d3dde2 /Lib/test
parentdbea271885eccda0db2e5248fd932cc56ec8a495 (diff)
parentb12df4e8246224fa71200fc8ee1ac0e917e38e39 (diff)
downloadcpython-0ba18e6c0243282b5cfbbbba4a94395fd38eee8f.tar.gz
merge heads
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_multibytecodec_support.py36
1 files changed, 33 insertions, 3 deletions
diff --git a/Lib/test/test_multibytecodec_support.py b/Lib/test/test_multibytecodec_support.py
index 7735976615..ef63b6934d 100644
--- a/Lib/test/test_multibytecodec_support.py
+++ b/Lib/test/test_multibytecodec_support.py
@@ -58,11 +58,16 @@ class TestBase:
result = func(source, scheme)[0]
if func is self.decode:
self.assertTrue(type(result) is str, type(result))
+ self.assertEqual(result, expected,
+ '%a.decode(%r, %r)=%a != %a'
+ % (source, self.encoding, scheme, result,
+ expected))
else:
self.assertTrue(type(result) is bytes, type(result))
- self.assertEqual(result, expected,
- '%a.decode(%r)=%a != %a'
- % (source, self.encoding, result, expected))
+ self.assertEqual(result, expected,
+ '%a.encode(%r, %r)=%a != %a'
+ % (source, self.encoding, scheme, result,
+ expected))
else:
self.assertRaises(UnicodeError, func, source, scheme)
@@ -279,6 +284,7 @@ class TestBase_Mapping(unittest.TestCase):
pass_enctest = []
pass_dectest = []
supmaps = []
+ codectests = []
def __init__(self, *args, **kw):
unittest.TestCase.__init__(self, *args, **kw)
@@ -348,6 +354,30 @@ class TestBase_Mapping(unittest.TestCase):
if (csetch, unich) not in self.pass_dectest:
self.assertEqual(str(csetch, self.encoding), unich)
+ 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 str, type(result))
+ self.assertEqual(result, expected,
+ '%a.decode(%r, %r)=%a != %a'
+ % (source, self.encoding, scheme, result,
+ expected))
+ else:
+ result = func(self.encoding, scheme)
+ self.assertTrue(type(result) is bytes, type(result))
+ self.assertEqual(result, expected,
+ '%a.encode(%r, %r)=%a != %a'
+ % (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: