summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorBerker Peksag <berker.peksag@gmail.com>2016-09-16 14:32:06 (GMT)
committerBerker Peksag <berker.peksag@gmail.com>2016-09-16 14:32:06 (GMT)
commit7b4bcd20041d25d5c5b5f416bc6d1090dd3e374a (patch)
treea840f7f6ce44a552b1e4b066ae79664e6d521e6d /Lib/test
parentde3f48ae9a5c807f1af26f2841a39a3667cc9760 (diff)
parent4a72a7b6c4c95f7613486f0e4e20a3d4815a16c5 (diff)
downloadcpython-7b4bcd20041d25d5c5b5f416bc6d1090dd3e374a.zip
cpython-7b4bcd20041d25d5c5b5f416bc6d1090dd3e374a.tar.gz
cpython-7b4bcd20041d25d5c5b5f416bc6d1090dd3e374a.tar.bz2
Issue #25270: Merge from 3.5
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_codecs.py20
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):