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

Delta Between Two Patch Sets: Lib/test/test_codecs.py

Issue 25270: codecs.escape_encode systemerror on empty byte string
Left Patch Set: Created 3 years, 5 months ago
Right Patch Set: Created 3 years, 5 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:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « Doc/c-api/bytes.rst ('k') | Objects/bytesobject.c » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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 2530 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 2543
2544 2544
2545 class EscapeEncodeTest(unittest.TestCase): 2545 class EscapeEncodeTest(unittest.TestCase):
2546 2546
2547 def test_escape_encode(self): 2547 def test_escape_encode(self):
2548 tests = [ 2548 tests = [
2549 (b'', (b'', 0)), 2549 (b'', (b'', 0)),
2550 (b'foobar', (b'foobar', 6)), 2550 (b'foobar', (b'foobar', 6)),
2551 (b'spam\0eggs', (b'spam\\x00eggs', 9)), 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 (b'a\'b', (b"a\\'b", 3)),
2553 (b'b\\c', (b'b\\\\c', 3)),
2554 (b'c\nd', (b'c\\nd', 3)),
2555 (b'd\re', (b'd\\re', 3)),
2556 (b'f\x7fg', (b'f\\x7fg', 3)),
2557 (b'h\ri', (b'h\\ri', 3)),
storchaka 2016/09/16 13:52:41 Duplicates (b'd\re', (b'd\\re', 3))
2552 ] 2558 ]
2553 for data, output in tests: 2559 for data, output in tests:
2554 with self.subTest(data=data): 2560 with self.subTest(data=data):
2555 self.assertEqual(codecs.escape_encode(data), output) 2561 self.assertEqual(codecs.escape_encode(data), output)
2556 self.assertRaises(TypeError, codecs.escape_encode, 'spam') 2562 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.
2563 self.assertRaises(TypeError, codecs.escape_encode, bytearray(b'spam'))
2557 2564
2558 2565
2559 class SurrogateEscapeTest(unittest.TestCase): 2566 class SurrogateEscapeTest(unittest.TestCase):
2560 2567
2561 def test_utf8(self): 2568 def test_utf8(self):
2562 # Bad byte 2569 # Bad byte
2563 self.assertEqual(b"foo\x80bar".decode("utf-8", "surrogateescape"), 2570 self.assertEqual(b"foo\x80bar".decode("utf-8", "surrogateescape"),
2564 "foo\udc80bar") 2571 "foo\udc80bar")
2565 self.assertEqual("foo\udc80bar".encode("utf-8", "surrogateescape"), 2572 self.assertEqual("foo\udc80bar".encode("utf-8", "surrogateescape"),
2566 b"foo\x80bar") 2573 b"foo\x80bar")
(...skipping 672 matching lines...) Expand 10 before | Expand all | Expand 10 after
3239 for data, expected in ( 3246 for data, expected in (
3240 (b'abc', 'abc'), 3247 (b'abc', 'abc'),
3241 (b'[\x80\xff]', '[\x80\xff]'), 3248 (b'[\x80\xff]', '[\x80\xff]'),
3242 ): 3249 ):
3243 with self.subTest(data=data, expected=expected): 3250 with self.subTest(data=data, expected=expected):
3244 self.assertEqual(data.decode('latin1'), expected) 3251 self.assertEqual(data.decode('latin1'), expected)
3245 3252
3246 3253
3247 if __name__ == "__main__": 3254 if __name__ == "__main__":
3248 unittest.main() 3255 unittest.main()
LEFTRIGHT

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