summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_codecs.py
diff options
context:
space:
mode:
authorMartin Panter <vadmium>2015-09-12 02:20:06 (GMT)
committerMartin Panter <vadmium>2015-09-12 02:20:06 (GMT)
commit90bc71f5b18abc0bb232f8ff8f56683b4420c3e0 (patch)
tree79f6e08a129fa33311e9eb3d6c3586f7cd3c2bb0 /Lib/test/test_codecs.py
parentd0384044ee1bbf62173eed3fb55cb4eca0159e3a (diff)
downloadcpython-90bc71f5b18abc0bb232f8ff8f56683b4420c3e0.zip
cpython-90bc71f5b18abc0bb232f8ff8f56683b4420c3e0.tar.gz
cpython-90bc71f5b18abc0bb232f8ff8f56683b4420c3e0.tar.bz2
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().
Diffstat (limited to 'Lib/test/test_codecs.py')
-rw-r--r--Lib/test/test_codecs.py53
1 files changed, 8 insertions, 45 deletions
diff --git a/Lib/test/test_codecs.py b/Lib/test/test_codecs.py
index c7072a6..7300f23 100644
--- a/Lib/test/test_codecs.py
+++ b/Lib/test/test_codecs.py
@@ -2101,6 +2101,13 @@ class BomTest(unittest.TestCase):
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 @@ def test_main():
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()