summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_codecs.py
diff options
context:
space:
mode:
authorNick Coghlan <ncoghlan@gmail.com>2013-10-02 14:43:22 (GMT)
committerNick Coghlan <ncoghlan@gmail.com>2013-10-02 14:43:22 (GMT)
commitfdf239a855c82bc20df157815de947867aa2648e (patch)
tree05995514fc9cbb3283c5bdd2586982baebc3286b /Lib/test/test_codecs.py
parent73c6ee00805729919f98d4f2dbe27e16c54b4db2 (diff)
downloadcpython-fdf239a855c82bc20df157815de947867aa2648e.zip
cpython-fdf239a855c82bc20df157815de947867aa2648e.tar.gz
cpython-fdf239a855c82bc20df157815de947867aa2648e.tar.bz2
Close #17839: support bytes-like objects in base64 module
This mostly affected the encodebytes and decodebytes function (which are used by base64_codec) Also added a test to ensure all bytes-bytes codecs can handle memoryview input and tests for handling of multidimensional and non-bytes format input in the modern base64 API.
Diffstat (limited to 'Lib/test/test_codecs.py')
-rw-r--r--Lib/test/test_codecs.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/Lib/test/test_codecs.py b/Lib/test/test_codecs.py
index 2f3cf4d..99d928d 100644
--- a/Lib/test/test_codecs.py
+++ b/Lib/test/test_codecs.py
@@ -2285,6 +2285,24 @@ class TransformCodecTest(unittest.TestCase):
sout = reader.readline()
self.assertEqual(sout, b"\x80")
+ def test_buffer_api_usage(self):
+ # We check all the transform codecs accept memoryview input
+ # for encoding and decoding
+ # and also that they roundtrip correctly
+ original = b"12345\x80"
+ for encoding in bytes_transform_encodings:
+ data = original
+ view = memoryview(data)
+ data = codecs.encode(data, encoding)
+ view_encoded = codecs.encode(view, encoding)
+ self.assertEqual(view_encoded, data)
+ view = memoryview(data)
+ data = codecs.decode(data, encoding)
+ self.assertEqual(data, original)
+ view_decoded = codecs.decode(view, encoding)
+ self.assertEqual(view_decoded, data)
+
+
@unittest.skipUnless(sys.platform == 'win32',
'code pages are specific to Windows')