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

Unified Diff: Lib/test/test_codecs.py

Issue 25270: codecs.escape_encode systemerror on empty byte string
Patch Set: Created 3 years, 8 months ago
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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Doc/c-api/bytes.rst ('k') | Objects/bytesobject.c » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
--- a/Lib/test/test_codecs.py
+++ b/Lib/test/test_codecs.py
@@ -2537,16 +2537,37 @@ class RawUnicodeEscapeTest(unittest.Test
self.assertEqual(decode(data, "ignore"), ("[]", len(data)))
self.assertEqual(decode(data, "replace"),
("[\ufffd]\ufffd", len(data)))
self.assertRaises(UnicodeDecodeError, decode, br"\U00110000")
self.assertEqual(decode(br"\U00110000", "ignore"), ("", 10))
self.assertEqual(decode(br"\U00110000", "replace"), ("\ufffd", 10))
+class EscapeEncodeTest(unittest.TestCase):
+
+ def test_escape_encode(self):
+ tests = [
+ (b'', (b'', 0)),
+ (b'foobar', (b'foobar', 6)),
+ (b'spam\0eggs', (b'spam\\x00eggs', 9)),
+ (b'a\'b', (b"a\\'b", 3)),
+ (b'b\\c', (b'b\\\\c', 3)),
+ (b'c\nd', (b'c\\nd', 3)),
+ (b'd\re', (b'd\\re', 3)),
+ (b'f\x7fg', (b'f\\x7fg', 3)),
+ (b'h\ri', (b'h\\ri', 3)),
storchaka 2016/09/16 13:52:41 Duplicates (b'd\re', (b'd\\re', 3))
+ ]
+ for data, output in tests:
+ with self.subTest(data=data):
+ self.assertEqual(codecs.escape_encode(data), output)
+ self.assertRaises(TypeError, codecs.escape_encode, 'spam')
+ self.assertRaises(TypeError, codecs.escape_encode, bytearray(b'spam'))
+
+
class SurrogateEscapeTest(unittest.TestCase):
def test_utf8(self):
# Bad byte
self.assertEqual(b"foo\x80bar".decode("utf-8", "surrogateescape"),
"foo\udc80bar")
self.assertEqual("foo\udc80bar".encode("utf-8", "surrogateescape"),
b"foo\x80bar")
« no previous file with comments | « Doc/c-api/bytes.rst ('k') | Objects/bytesobject.c » ('j') | no next file with comments »

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