Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ab5fcc0

Browse files
author
Victor Stinner
committed
(Merge 3.2) Issue #12016: Add test_errorhandle() to TestBase_Mapping of
test_multibytecodec_support. Improve also error message of the test_errorhandle() of TestBase.
2 parents 2bc6c2e + f5048a4 commit ab5fcc0

1 file changed

Lines changed: 33 additions & 3 deletions

File tree

Lib/test/test_multibytecodec_support.py

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,16 @@ def test_errorhandle(self):
5858
result = func(source, scheme)[0]
5959
if func is self.decode:
6060
self.assertTrue(type(result) is str, type(result))
61+
self.assertEqual(result, expected,
62+
'%a.decode(%r, %r)=%a != %a'
63+
% (source, self.encoding, scheme, result,
64+
expected))
6165
else:
6266
self.assertTrue(type(result) is bytes, type(result))
63-
self.assertEqual(result, expected,
64-
'%a.decode(%r)=%a != %a'
65-
% (source, self.encoding, result, expected))
67+
self.assertEqual(result, expected,
68+
'%a.encode(%r, %r)=%a != %a'
69+
% (source, self.encoding, scheme, result,
70+
expected))
6671
else:
6772
self.assertRaises(UnicodeError, func, source, scheme)
6873

@@ -279,6 +284,7 @@ class TestBase_Mapping(unittest.TestCase):
279284
pass_enctest = []
280285
pass_dectest = []
281286
supmaps = []
287+
codectests = []
282288

283289
def __init__(self, *args, **kw):
284290
unittest.TestCase.__init__(self, *args, **kw)
@@ -348,6 +354,30 @@ def _testpoint(self, csetch, unich):
348354
if (csetch, unich) not in self.pass_dectest:
349355
self.assertEqual(str(csetch, self.encoding), unich)
350356

357+
def test_errorhandle(self):
358+
for source, scheme, expected in self.codectests:
359+
if isinstance(source, bytes):
360+
func = source.decode
361+
else:
362+
func = source.encode
363+
if expected:
364+
if isinstance(source, bytes):
365+
result = func(self.encoding, scheme)
366+
self.assertTrue(type(result) is str, type(result))
367+
self.assertEqual(result, expected,
368+
'%a.decode(%r, %r)=%a != %a'
369+
% (source, self.encoding, scheme, result,
370+
expected))
371+
else:
372+
result = func(self.encoding, scheme)
373+
self.assertTrue(type(result) is bytes, type(result))
374+
self.assertEqual(result, expected,
375+
'%a.encode(%r, %r)=%a != %a'
376+
% (source, self.encoding, scheme, result,
377+
expected))
378+
else:
379+
self.assertRaises(UnicodeError, func, self.encoding, scheme)
380+
351381
def load_teststring(name):
352382
dir = os.path.join(os.path.dirname(__file__), 'cjkencodings')
353383
with open(os.path.join(dir, name + '.txt'), 'rb') as f:

0 commit comments

Comments
 (0)