[Python-checkins] cpython (2.7): Remove and enable misplaced codecs tests ported from Python 3

martin.panter python-checkins at python.org
Sat Sep 12 04:36:26 CEST 2015


https://hg.python.org/cpython/rev/9abe48b0f944
changeset:   97937:9abe48b0f944
branch:      2.7
parent:      97917:64d6130f9e24
user:        Martin Panter <vadmium>
date:        Sat Sep 12 02:20:06 2015 +0000
summary:
  Remove and enable misplaced codecs tests ported from Python 3

Most of these tests are about blacklisted non-text codecs, which are not
relevant in Python 2. The only one remaining is TransformCodecTest.test_uu_
invalid().

files:
  Lib/test/test_codecs.py |  53 ++++------------------------
  1 files changed, 8 insertions(+), 45 deletions(-)


diff --git a/Lib/test/test_codecs.py b/Lib/test/test_codecs.py
--- a/Lib/test/test_codecs.py
+++ b/Lib/test/test_codecs.py
@@ -2101,6 +2101,13 @@
                 self.assertEqual(f.read(), data * 2)
 
 
+class TransformCodecTest(unittest.TestCase):
+
+    def test_uu_invalid(self):
+        # Missing "begin" line
+        self.assertRaises(ValueError, codecs.decode, "", "uu-codec")
+
+
 def test_main():
     test_support.run_unittest(
         UTF32Test,
@@ -2132,53 +2139,9 @@
         UnicodeEscapeTest,
         RawUnicodeEscapeTest,
         BomTest,
+        TransformCodecTest,
     )
 
-    def test_uu_invalid(self):
-        # Missing "begin" line
-        self.assertRaises(ValueError, codecs.decode, "", "uu-codec")
-
-    def test_text_to_binary_blacklists_binary_transforms(self):
-        # Check binary -> binary codecs give a good error for str input
-        bad_input = "bad input type"
-        for encoding in bytes_transform_encodings:
-            fmt = (r"{!r} is not a text encoding; "
-                   r"use codecs.encode\(\) to handle arbitrary codecs")
-            msg = fmt.format(encoding)
-            with self.assertRaisesRegex(LookupError, msg) as failure:
-                bad_input.encode(encoding)
-            self.assertIsNone(failure.exception.__cause__)
-
-    def test_text_to_binary_blacklists_text_transforms(self):
-        # Check str.encode gives a good error message for str -> str codecs
-        msg = (r"^'rot_13' is not a text encoding; "
-               r"use codecs.encode\(\) to handle arbitrary codecs")
-        with self.assertRaisesRegex(LookupError, msg):
-            "just an example message".encode("rot_13")
-
-    def test_binary_to_text_blacklists_binary_transforms(self):
-        # Check bytes.decode and bytearray.decode give a good error
-        # message for binary -> binary codecs
-        data = b"encode first to ensure we meet any format restrictions"
-        for encoding in bytes_transform_encodings:
-            encoded_data = codecs.encode(data, encoding)
-            fmt = (r"{!r} is not a text encoding; "
-                   r"use codecs.decode\(\) to handle arbitrary codecs")
-            msg = fmt.format(encoding)
-            with self.assertRaisesRegex(LookupError, msg):
-                encoded_data.decode(encoding)
-            with self.assertRaisesRegex(LookupError, msg):
-                bytearray(encoded_data).decode(encoding)
-
-    def test_binary_to_text_blacklists_text_transforms(self):
-        # Check str -> str codec gives a good error for binary input
-        for bad_input in (b"immutable", bytearray(b"mutable")):
-            msg = (r"^'rot_13' is not a text encoding; "
-                   r"use codecs.decode\(\) to handle arbitrary codecs")
-            with self.assertRaisesRegex(LookupError, msg) as failure:
-                bad_input.decode("rot_13")
-            self.assertIsNone(failure.exception.__cause__)
-
 
 if __name__ == "__main__":
     test_main()

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list