summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_multibytecodec_support.py
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@haypocalc.com>2011-06-03 21:44:39 (GMT)
committerVictor Stinner <victor.stinner@haypocalc.com>2011-06-03 21:44:39 (GMT)
commitf5048a40752b8a0197ef9e4b6ace8dab75479fd7 (patch)
tree4be13e44f9de1a3779b3e5cc9a6f2360da4035bc /Lib/test/test_multibytecodec_support.py
parent5dfe3bb2d9416ab3e77834bd65b6f575cbb49009 (diff)
downloadcpython-f5048a40752b8a0197ef9e4b6ace8dab75479fd7.zip
cpython-f5048a40752b8a0197ef9e4b6ace8dab75479fd7.tar.gz
cpython-f5048a40752b8a0197ef9e4b6ace8dab75479fd7.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.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 7735976..ef63b69 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: