mirror of
https://abf.rosa.ru/djam/python38.git
synced 2025-02-23 23:32:49 +00:00
56 lines
2.1 KiB
Diff
56 lines
2.1 KiB
Diff
|
|
# HG changeset patch
|
|
# User Antoine Pitrou <solipsis@pitrou.net>
|
|
# Date 1342824468 -7200
|
|
# Node ID 118fe0ee6921647ce188d706fdb0b16bc93f7f0d
|
|
# Parent f1f480650a0ad5c73729253a345fe5a5732ba79c# Parent 034ff986019da70d290c63bbfde5a748c63c65c6
|
|
Port additional tests from #14579 (the issue is already fixed).
|
|
|
|
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
|
|
@@ -557,8 +557,19 @@ class UTF16LETest(ReadTest):
|
|
)
|
|
|
|
def test_errors(self):
|
|
- self.assertRaises(UnicodeDecodeError, codecs.utf_16_le_decode,
|
|
- b"\xff", "strict", True)
|
|
+ tests = [
|
|
+ (b'\xff', '\ufffd'),
|
|
+ (b'A\x00Z', 'A\ufffd'),
|
|
+ (b'A\x00B\x00C\x00D\x00Z', 'ABCD\ufffd'),
|
|
+ (b'\x00\xd8', '\ufffd'),
|
|
+ (b'\x00\xd8A', '\ufffd'),
|
|
+ (b'\x00\xd8A\x00', '\ufffdA'),
|
|
+ (b'\x00\xdcA\x00', '\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)
|
|
|
|
def test_nonbmp(self):
|
|
self.assertEqual("\U00010203".encode(self.encoding),
|
|
@@ -585,8 +596,19 @@ class UTF16BETest(ReadTest):
|
|
)
|
|
|
|
def test_errors(self):
|
|
- self.assertRaises(UnicodeDecodeError, codecs.utf_16_be_decode,
|
|
- b"\xff", "strict", True)
|
|
+ tests = [
|
|
+ (b'\xff', '\ufffd'),
|
|
+ (b'\x00A\xff', 'A\ufffd'),
|
|
+ (b'\x00A\x00B\x00C\x00DZ', 'ABCD\ufffd'),
|
|
+ (b'\xd8\x00', '\ufffd'),
|
|
+ (b'\xd8\x00\xdc', '\ufffd'),
|
|
+ (b'\xd8\x00\x00A', '\ufffdA'),
|
|
+ (b'\xdc\x00\x00A', '\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)
|
|
|
|
def test_nonbmp(self):
|
|
self.assertEqual("\U00010203".encode(self.encoding),
|
|
|