Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(35)

Side by Side Diff: Lib/test/test_codecs.py

Issue 25270: codecs.escape_encode systemerror on empty byte string
Patch Set: Created 3 years, 6 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
OLDNEW
1 import codecs 1 import codecs
2 import contextlib 2 import contextlib
3 import io 3 import io
4 import locale 4 import locale
5 import sys 5 import sys
6 import unittest 6 import unittest
7 import encodings 7 import encodings
8 8
9 from test import support 9 from test import support
10 10
(...skipping 2522 matching lines...) Expand 10 before | Expand all | Expand 10 after
2533 b"\\" + c + b"0"*i) 2533 b"\\" + c + b"0"*i)
2534 self.assertRaises(UnicodeDecodeError, decode, 2534 self.assertRaises(UnicodeDecodeError, decode,
2535 b"[\\" + c + b"0"*i + b"]") 2535 b"[\\" + c + b"0"*i + b"]")
2536 data = b"[\\" + c + b"0"*i + b"]\\" + c + b"0"*i 2536 data = b"[\\" + c + b"0"*i + b"]\\" + c + b"0"*i
2537 self.assertEqual(decode(data, "ignore"), ("[]", len(data))) 2537 self.assertEqual(decode(data, "ignore"), ("[]", len(data)))
2538 self.assertEqual(decode(data, "replace"), 2538 self.assertEqual(decode(data, "replace"),
2539 ("[\ufffd]\ufffd", len(data))) 2539 ("[\ufffd]\ufffd", len(data)))
2540 self.assertRaises(UnicodeDecodeError, decode, br"\U00110000") 2540 self.assertRaises(UnicodeDecodeError, decode, br"\U00110000")
2541 self.assertEqual(decode(br"\U00110000", "ignore"), ("", 10)) 2541 self.assertEqual(decode(br"\U00110000", "ignore"), ("", 10))
2542 self.assertEqual(decode(br"\U00110000", "replace"), ("\ufffd", 10)) 2542 self.assertEqual(decode(br"\U00110000", "replace"), ("\ufffd", 10))
2543
2544
2545 class EscapeEncodeTest(unittest.TestCase):
2546
2547 def test_escape_encode(self):
2548 tests = [
2549 (b'', (b'', 0)),
2550 (b'foobar', (b'foobar', 6)),
2551 (b'spam\0eggs', (b'spam\\x00eggs', 9)),
storchaka 2016/09/16 12:20:39 Please add tests for '\'', '\\', '\t', '\x7f' and
berkerpeksag 2016/09/16 12:41:15 Done.
2552 ]
2553 for data, output in tests:
2554 with self.subTest(data=data):
2555 self.assertEqual(codecs.escape_encode(data), output)
2556 self.assertRaises(TypeError, codecs.escape_encode, 'spam')
storchaka 2016/09/16 12:20:39 Please add a test for bytearray.
berkerpeksag 2016/09/16 12:41:15 Done.
2543 2557
2544 2558
2545 class SurrogateEscapeTest(unittest.TestCase): 2559 class SurrogateEscapeTest(unittest.TestCase):
2546 2560
2547 def test_utf8(self): 2561 def test_utf8(self):
2548 # Bad byte 2562 # Bad byte
2549 self.assertEqual(b"foo\x80bar".decode("utf-8", "surrogateescape"), 2563 self.assertEqual(b"foo\x80bar".decode("utf-8", "surrogateescape"),
2550 "foo\udc80bar") 2564 "foo\udc80bar")
2551 self.assertEqual("foo\udc80bar".encode("utf-8", "surrogateescape"), 2565 self.assertEqual("foo\udc80bar".encode("utf-8", "surrogateescape"),
2552 b"foo\x80bar") 2566 b"foo\x80bar")
(...skipping 672 matching lines...) Expand 10 before | Expand all | Expand 10 after
3225 for data, expected in ( 3239 for data, expected in (
3226 (b'abc', 'abc'), 3240 (b'abc', 'abc'),
3227 (b'[\x80\xff]', '[\x80\xff]'), 3241 (b'[\x80\xff]', '[\x80\xff]'),
3228 ): 3242 ):
3229 with self.subTest(data=data, expected=expected): 3243 with self.subTest(data=data, expected=expected):
3230 self.assertEqual(data.decode('latin1'), expected) 3244 self.assertEqual(data.decode('latin1'), expected)
3231 3245
3232 3246
3233 if __name__ == "__main__": 3247 if __name__ == "__main__":
3234 unittest.main() 3248 unittest.main()
OLDNEW
« no previous file with comments | « Doc/c-api/bytes.rst ('k') | Objects/bytesobject.c » ('j') | Objects/bytesobject.c » ('J')

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+