[Python-checkins] cpython (2.7): Issue #17842. Added base64 module tests with bytearray arguments.

serhiy.storchaka python-checkins at python.org
Sun Apr 28 14:58:37 CEST 2013


http://hg.python.org/cpython/rev/6e57d097ae56
changeset:   83530:6e57d097ae56
branch:      2.7
parent:      83527:44fe1f5b07e3
user:        Serhiy Storchaka <storchaka at gmail.com>
date:        Sun Apr 28 15:48:54 2013 +0300
summary:
  Issue #17842. Added base64 module tests with bytearray arguments.

files:
  Lib/test/test_base64.py |  26 ++++++++++++++++++++++++++
  1 files changed, 26 insertions(+), 0 deletions(-)


diff --git a/Lib/test/test_base64.py b/Lib/test/test_base64.py
--- a/Lib/test/test_base64.py
+++ b/Lib/test/test_base64.py
@@ -18,6 +18,8 @@
            "YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXpBQkNE"
            "RUZHSElKS0xNTk9QUVJTVFVWV1hZWjAxMjM0\nNT"
            "Y3ODkhQCMwXiYqKCk7Ojw+LC4gW117fQ==\n")
+        # Non-bytes
+        eq(base64.encodestring(bytearray('abc')), 'YWJj\n')
 
     def test_decodestring(self):
         eq = self.assertEqual
@@ -32,6 +34,8 @@
            "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
            "0123456789!@#0^&*();:<>,. []{}")
         eq(base64.decodestring(''), '')
+        # Non-bytes
+        eq(base64.decodestring(bytearray("YWJj\n")), "abc")
 
     def test_encode(self):
         eq = self.assertEqual
@@ -73,6 +77,10 @@
            "Y3ODkhQCMwXiYqKCk7Ojw+LC4gW117fQ==")
         # Test with arbitrary alternative characters
         eq(base64.b64encode('\xd3V\xbeo\xf7\x1d', altchars='*$'), '01a*b$cd')
+        # Non-bytes
+        eq(base64.b64encode(bytearray('abcd')), 'YWJjZA==')
+        self.assertRaises(TypeError, base64.b64encode,
+                          '\xd3V\xbeo\xf7\x1d', altchars=bytearray('*$'))
         # Test standard alphabet
         eq(base64.standard_b64encode("www.python.org"), "d3d3LnB5dGhvbi5vcmc=")
         eq(base64.standard_b64encode("a"), "YQ==")
@@ -85,8 +93,12 @@
            "YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXpBQkNE"
            "RUZHSElKS0xNTk9QUVJTVFVWV1hZWjAxMjM0NT"
            "Y3ODkhQCMwXiYqKCk7Ojw+LC4gW117fQ==")
+        # Non-bytes
+        eq(base64.standard_b64encode(bytearray('abcd')), 'YWJjZA==')
         # Test with 'URL safe' alternative characters
         eq(base64.urlsafe_b64encode('\xd3V\xbeo\xf7\x1d'), '01a-b_cd')
+        # Non-bytes
+        eq(base64.urlsafe_b64encode(bytearray('\xd3V\xbeo\xf7\x1d')), '01a-b_cd')
 
     def test_b64decode(self):
         eq = self.assertEqual
@@ -104,6 +116,8 @@
         eq(base64.b64decode(''), '')
         # Test with arbitrary alternative characters
         eq(base64.b64decode('01a*b$cd', altchars='*$'), '\xd3V\xbeo\xf7\x1d')
+        # Non-bytes
+        eq(base64.b64decode(bytearray("YWJj")), "abc")
         # Test standard alphabet
         eq(base64.standard_b64decode("d3d3LnB5dGhvbi5vcmc="), "www.python.org")
         eq(base64.standard_b64decode("YQ=="), "a")
@@ -116,8 +130,12 @@
            "abcdefghijklmnopqrstuvwxyz"
            "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
            "0123456789!@#0^&*();:<>,. []{}")
+        # Non-bytes
+        eq(base64.standard_b64decode(bytearray("YWJj")), "abc")
         # Test with 'URL safe' alternative characters
         eq(base64.urlsafe_b64decode('01a-b_cd'), '\xd3V\xbeo\xf7\x1d')
+        # Non-bytes
+        eq(base64.urlsafe_b64decode(bytearray('01a-b_cd')), '\xd3V\xbeo\xf7\x1d')
 
     def test_b64decode_error(self):
         self.assertRaises(TypeError, base64.b64decode, 'abc')
@@ -131,6 +149,8 @@
         eq(base64.b32encode('abc'), 'MFRGG===')
         eq(base64.b32encode('abcd'), 'MFRGGZA=')
         eq(base64.b32encode('abcde'), 'MFRGGZDF')
+        # Non-bytes
+        eq(base64.b32encode(bytearray('abcd')), 'MFRGGZA=')
 
     def test_b32decode(self):
         eq = self.assertEqual
@@ -141,6 +161,8 @@
         eq(base64.b32decode('MFRGG==='), 'abc')
         eq(base64.b32decode('MFRGGZA='), 'abcd')
         eq(base64.b32decode('MFRGGZDF'), 'abcde')
+        # Non-bytes
+        self.assertRaises(TypeError, base64.b32decode, bytearray('MFRGG==='))
 
     def test_b32decode_casefold(self):
         eq = self.assertEqual
@@ -171,6 +193,8 @@
         eq = self.assertEqual
         eq(base64.b16encode('\x01\x02\xab\xcd\xef'), '0102ABCDEF')
         eq(base64.b16encode('\x00'), '00')
+        # Non-bytes
+        eq(base64.b16encode(bytearray('\x01\x02\xab\xcd\xef')), '0102ABCDEF')
 
     def test_b16decode(self):
         eq = self.assertEqual
@@ -180,6 +204,8 @@
         self.assertRaises(TypeError, base64.b16decode, '0102abcdef')
         # Case fold
         eq(base64.b16decode('0102abcdef', True), '\x01\x02\xab\xcd\xef')
+        # Non-bytes
+        eq(base64.b16decode(bytearray("0102ABCDEF")), '\x01\x02\xab\xcd\xef')
 
 
 

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


More information about the Python-checkins mailing list