[Python-checkins] cpython (2.7): Make error report in test_codecs more informative.

serhiy.storchaka python-checkins at python.org
Sun Oct 4 06:53:15 EDT 2015


https://hg.python.org/cpython/rev/45a04eadefd6
changeset: 98536:45a04eadefd6
branch: 2.7
parent: 98532:739cc9ca55cd
user: Serhiy Storchaka <storchaka at gmail.com>
date: Sun Oct 04 13:52:40 2015 +0300
summary:
 Make error report in test_codecs more informative.
files:
 Lib/test/test_codecs.py | 36 ++++++++++++++++++++--------
 1 files changed, 26 insertions(+), 10 deletions(-)
diff --git a/Lib/test/test_codecs.py b/Lib/test/test_codecs.py
--- a/Lib/test/test_codecs.py
+++ b/Lib/test/test_codecs.py
@@ -573,9 +573,13 @@
 (b'\x00\xdcA\x00', u'\ufffdA'),
 ]
 for raw, expected in tests:
- self.assertRaises(UnicodeDecodeError, codecs.utf_16_le_decode,
- raw, 'strict', True)
- self.assertEqual(raw.decode('utf-16le', 'replace'), expected)
+ try:
+ with self.assertRaises(UnicodeDecodeError):
+ codecs.utf_16_le_decode(raw, 'strict', True)
+ self.assertEqual(raw.decode('utf-16le', 'replace'), expected)
+ except:
+ print 'raw=%r' % raw
+ raise
 
 class UTF16BETest(ReadTest):
 encoding = "utf-16-be"
@@ -610,9 +614,13 @@
 (b'\xdc\x00\x00A', u'\ufffdA'),
 ]
 for raw, expected in tests:
- self.assertRaises(UnicodeDecodeError, codecs.utf_16_be_decode,
- raw, 'strict', True)
- self.assertEqual(raw.decode('utf-16be', 'replace'), expected)
+ try:
+ with self.assertRaises(UnicodeDecodeError):
+ codecs.utf_16_be_decode(raw, 'strict', True)
+ self.assertEqual(raw.decode('utf-16be', 'replace'), expected)
+ except:
+ print 'raw=%r' % raw
+ raise
 
 class UTF8Test(ReadTest):
 encoding = "utf-8"
@@ -704,9 +712,13 @@
 ('a+IKw\xffb', u'a\u20ac\ufffdb'),
 ]
 for raw, expected in tests:
- self.assertRaises(UnicodeDecodeError, codecs.utf_7_decode,
- raw, 'strict', True)
- self.assertEqual(raw.decode('utf-7', 'replace'), expected)
+ try:
+ with self.assertRaises(UnicodeDecodeError):
+ codecs.utf_7_decode(raw, 'strict', True)
+ self.assertEqual(raw.decode('utf-7', 'replace'), expected)
+ except:
+ print 'raw=%r' % raw
+ raise
 
 def test_nonbmp(self):
 self.assertEqual(u'\U000104A0'.encode(self.encoding), '+2AHcoA-')
@@ -740,7 +752,11 @@
 ('a+IKwgrNgBA-b', u'a\u20ac\u20ac\ufffdb'),
 ]
 for raw, expected in tests:
- self.assertEqual(raw.decode('utf-7', 'replace'), expected)
+ try:
+ self.assertEqual(raw.decode('utf-7', 'replace'), expected)
+ except:
+ print 'raw=%r' % raw
+ raise
 
 class UTF16ExTest(unittest.TestCase):
 
-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /