diff options
author | Berker Peksag <berker.peksag@gmail.com> | 2016-09-16 14:32:32 (GMT) |
---|---|---|
committer | Berker Peksag <berker.peksag@gmail.com> | 2016-09-16 14:32:32 (GMT) |
commit | 0d850ba861e1e2ec640a0def61a3c2af711af223 (patch) | |
tree | 69b38da9ff62df2853a714ab2950d1c2296d3203 /Lib | |
parent | b33b02e1c97890417c2fa25ba5c637d365798e69 (diff) | |
parent | 7b4bcd20041d25d5c5b5f416bc6d1090dd3e374a (diff) | |
download | cpython-0d850ba861e1e2ec640a0def61a3c2af711af223.zip cpython-0d850ba861e1e2ec640a0def61a3c2af711af223.tar.gz cpython-0d850ba861e1e2ec640a0def61a3c2af711af223.tar.bz2 |
Issue #25270: Merge from 3.6
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_codecs.py | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/Lib/test/test_codecs.py b/Lib/test/test_codecs.py index 4d91a07..1e63ed8 100644 --- a/Lib/test/test_codecs.py +++ b/Lib/test/test_codecs.py @@ -2542,6 +2542,26 @@ class RawUnicodeEscapeTest(unittest.TestCase): 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)), + ] + 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): |