diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2013-01-29 09:07:27 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2013-01-29 09:07:27 (GMT) |
commit | db6add7d7114a1cc86d5d62df7f625a37deee2d4 (patch) | |
tree | de1660a59904f12938a025ae965fd3391bab3be3 /Lib | |
parent | 0ef48f02f2161c035679f85782fd5a0a712e032a (diff) | |
parent | 077cb347a9ecfa5736050292045fb702ede9bed9 (diff) | |
download | cpython-db6add7d7114a1cc86d5d62df7f625a37deee2d4.zip cpython-db6add7d7114a1cc86d5d62df7f625a37deee2d4.tar.gz cpython-db6add7d7114a1cc86d5d62df7f625a37deee2d4.tar.bz2 |
Clean up escape-decode decoder tests.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_codecs.py | 76 |
1 files changed, 40 insertions, 36 deletions
diff --git a/Lib/test/test_codecs.py b/Lib/test/test_codecs.py index 4c0c6de..88f4e35 100644 --- a/Lib/test/test_codecs.py +++ b/Lib/test/test_codecs.py @@ -930,51 +930,55 @@ class UTF8SigTest(ReadTest, unittest.TestCase): class EscapeDecodeTest(unittest.TestCase): def test_empty(self): - self.assertEqual(codecs.escape_decode(""), (b"", 0)) + self.assertEqual(codecs.escape_decode(b""), (b"", 0)) def test_raw(self): + decode = codecs.escape_decode for b in range(256): - if b != b'\\'[0]: - self.assertEqual(codecs.escape_decode(bytes([b]) + b'0'), - (bytes([b]) + b'0', 2)) + b = bytes([b]) + if b != b'\\': + self.assertEqual(decode(b + b'0'), (b + b'0', 2)) def test_escape(self): - self.assertEqual(codecs.escape_decode(b"[\\\n]"), (b"[]", 4)) - self.assertEqual(codecs.escape_decode(br'[\"]'), (b'["]', 4)) - self.assertEqual(codecs.escape_decode(br"[\']"), (b"[']", 4)) - self.assertEqual(codecs.escape_decode(br"[\\]"), (br"[\]", 4)) - self.assertEqual(codecs.escape_decode(br"[\a]"), (b"[\x07]", 4)) - self.assertEqual(codecs.escape_decode(br"[\b]"), (b"[\x08]", 4)) - self.assertEqual(codecs.escape_decode(br"[\t]"), (b"[\x09]", 4)) - self.assertEqual(codecs.escape_decode(br"[\n]"), (b"[\x0a]", 4)) - self.assertEqual(codecs.escape_decode(br"[\v]"), (b"[\x0b]", 4)) - self.assertEqual(codecs.escape_decode(br"[\f]"), (b"[\x0c]", 4)) - self.assertEqual(codecs.escape_decode(br"[\r]"), (b"[\x0d]", 4)) - self.assertEqual(codecs.escape_decode(br"[\7]"), (b"[\x07]", 4)) - self.assertEqual(codecs.escape_decode(br"[\8]"), (br"[\8]", 4)) - self.assertEqual(codecs.escape_decode(br"[\78]"), (b"[\x078]", 5)) - self.assertEqual(codecs.escape_decode(br"[\41]"), (b"[!]", 5)) - self.assertEqual(codecs.escape_decode(br"[\418]"), (b"[!8]", 6)) - self.assertEqual(codecs.escape_decode(br"[\101]"), (b"[A]", 6)) - self.assertEqual(codecs.escape_decode(br"[\1010]"), (b"[A0]", 7)) - self.assertEqual(codecs.escape_decode(br"[\501]"), (b"[A]", 6)) - self.assertEqual(codecs.escape_decode(br"[\x41]"), (b"[A]", 6)) - self.assertEqual(codecs.escape_decode(br"[\X41]"), (br"[\X41]", 6)) - self.assertEqual(codecs.escape_decode(br"[\x410]"), (b"[A0]", 7)) + decode = codecs.escape_decode + check = coding_checker(self, decode) + check(b"[\\\n]", b"[]") + check(br'[\"]', b'["]') + check(br"[\']", b"[']") + check(br"[\\]", br"[\]") + check(br"[\a]", b"[\x07]") + check(br"[\b]", b"[\x08]") + check(br"[\t]", b"[\x09]") + check(br"[\n]", b"[\x0a]") + check(br"[\v]", b"[\x0b]") + check(br"[\f]", b"[\x0c]") + check(br"[\r]", b"[\x0d]") + check(br"[\7]", b"[\x07]") + check(br"[\8]", br"[\8]") + check(br"[\78]", b"[\x078]") + check(br"[\41]", b"[!]") + check(br"[\418]", b"[!8]") + check(br"[\101]", b"[A]") + check(br"[\1010]", b"[A0]") + check(br"[\501]", b"[A]") + check(br"[\x41]", b"[A]") + check(br"[\X41]", br"[\X41]") + check(br"[\x410]", b"[A0]") for b in range(256): if b not in b'\n"\'\\abtnvfr01234567x': - self.assertEqual(codecs.escape_decode(b'\\' + bytes([b])), - (b'\\' + bytes([b]), 2)) + b = bytes([b]) + check(b'\\' + b, b'\\' + b) def test_errors(self): - self.assertRaises(ValueError, codecs.escape_decode, br"\x") - self.assertRaises(ValueError, codecs.escape_decode, br"[\x]") - self.assertEqual(codecs.escape_decode(br"[\x]\x", "ignore"), (b"[]", 6)) - self.assertEqual(codecs.escape_decode(br"[\x]\x", "replace"), (b"[?]?", 6)) - self.assertRaises(ValueError, codecs.escape_decode, br"\x0") - self.assertRaises(ValueError, codecs.escape_decode, br"[\x0]") - self.assertEqual(codecs.escape_decode(br"[\x0]\x0", "ignore"), (b"[]", 8)) - self.assertEqual(codecs.escape_decode(br"[\x0]\x0", "replace"), (b"[?]?", 8)) + decode = codecs.escape_decode + self.assertRaises(ValueError, decode, br"\x") + self.assertRaises(ValueError, decode, br"[\x]") + self.assertEqual(decode(br"[\x]\x", "ignore"), (b"[]", 6)) + self.assertEqual(decode(br"[\x]\x", "replace"), (b"[?]?", 6)) + self.assertRaises(ValueError, decode, br"\x0") + self.assertRaises(ValueError, decode, br"[\x0]") + self.assertEqual(decode(br"[\x0]\x0", "ignore"), (b"[]", 8)) + self.assertEqual(decode(br"[\x0]\x0", "replace"), (b"[?]?", 8)) class RecodingTest(unittest.TestCase): def test_recoding(self): |