[Python-checkins] cpython (3.2): Issue #12016: Add test_errorhandle() to TestBase_Mapping of
victor.stinner
python-checkins at python.org
Fri Jun 3 23:58:05 CEST 2011
http://hg.python.org/cpython/rev/8572bf1b56ec
changeset: 70628:8572bf1b56ec
branch: 3.2
parent: 70625:3610841f7357
user: Victor Stinner <victor.stinner at haypocalc.com>
date: Fri Jun 03 23:44:39 2011 +0200
summary:
Issue #12016: Add test_errorhandle() to TestBase_Mapping of
test_multibytecodec_support. Improve also error message of the
test_errorhandle() of TestBase.
files:
Lib/test/test_multibytecodec_support.py | 36 +++++++++++-
1 files changed, 33 insertions(+), 3 deletions(-)
diff --git a/Lib/test/test_multibytecodec_support.py b/Lib/test/test_multibytecodec_support.py
--- a/Lib/test/test_multibytecodec_support.py
+++ b/Lib/test/test_multibytecodec_support.py
@@ -58,11 +58,16 @@
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 @@
pass_enctest = []
pass_dectest = []
supmaps = []
+ codectests = []
def __init__(self, *args, **kw):
unittest.TestCase.__init__(self, *args, **kw)
@@ -348,6 +354,30 @@
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:
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list