Ignore:
Timestamp:
Mar 19, 2014, 11:31:01 PM (11 years ago)
Author:
dmik
Message:

python: Merge vendor 2.7.6 to trunk.

Location:
python/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • python/trunk

  • python/trunk/Lib/test/test_base64.py

    r2 r391  
    2020           "RUZHSElKS0xNTk9QUVJTVFVWV1hZWjAxMjM0\nNT"
    2121           "Y3ODkhQCMwXiYqKCk7Ojw+LC4gW117fQ==\n")
     22        # Non-bytes
     23        eq(base64.encodestring(bytearray('abc')), 'YWJj\n')
    2224
    2325    def test_decodestring(self):
     
    3436           "0123456789!@#0^&*();:<>,. []{}")
    3537        eq(base64.decodestring(''), '')
     38        # Non-bytes
     39        eq(base64.decodestring(bytearray("YWJj\n")), "abc")
    3640
    3741    def test_encode(self):
     
    7680        # Test with arbitrary alternative characters
    7781        eq(base64.b64encode('\xd3V\xbeo\xf7\x1d', altchars='*$'), '01a*b$cd')
     82        # Non-bytes
     83        eq(base64.b64encode(bytearray('abcd')), 'YWJjZA==')
     84        self.assertRaises(TypeError, base64.b64encode,
     85                          '\xd3V\xbeo\xf7\x1d', altchars=bytearray('*$'))
    7886        # Test standard alphabet
    7987        eq(base64.standard_b64encode("www.python.org"), "d3d3LnB5dGhvbi5vcmc=")
     
    8896           "RUZHSElKS0xNTk9QUVJTVFVWV1hZWjAxMjM0NT"
    8997           "Y3ODkhQCMwXiYqKCk7Ojw+LC4gW117fQ==")
     98        # Non-bytes
     99        eq(base64.standard_b64encode(bytearray('abcd')), 'YWJjZA==')
    90100        # Test with 'URL safe' alternative characters
    91101        eq(base64.urlsafe_b64encode('\xd3V\xbeo\xf7\x1d'), '01a-b_cd')
     102        # Non-bytes
     103        eq(base64.urlsafe_b64encode(bytearray('\xd3V\xbeo\xf7\x1d')), '01a-b_cd')
    92104
    93105    def test_b64decode(self):
     
    107119        # Test with arbitrary alternative characters
    108120        eq(base64.b64decode('01a*b$cd', altchars='*$'), '\xd3V\xbeo\xf7\x1d')
     121        # Non-bytes
     122        eq(base64.b64decode(bytearray("YWJj")), "abc")
    109123        # Test standard alphabet
    110124        eq(base64.standard_b64decode("d3d3LnB5dGhvbi5vcmc="), "www.python.org")
     
    119133           "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    120134           "0123456789!@#0^&*();:<>,. []{}")
     135        # Non-bytes
     136        eq(base64.standard_b64decode(bytearray("YWJj")), "abc")
    121137        # Test with 'URL safe' alternative characters
    122138        eq(base64.urlsafe_b64decode('01a-b_cd'), '\xd3V\xbeo\xf7\x1d')
     139        # Non-bytes
     140        eq(base64.urlsafe_b64decode(bytearray('01a-b_cd')), '\xd3V\xbeo\xf7\x1d')
    123141
    124142    def test_b64decode_error(self):
     
    134152        eq(base64.b32encode('abcd'), 'MFRGGZA=')
    135153        eq(base64.b32encode('abcde'), 'MFRGGZDF')
     154        # Non-bytes
     155        eq(base64.b32encode(bytearray('abcd')), 'MFRGGZA=')
    136156
    137157    def test_b32decode(self):
     
    144164        eq(base64.b32decode('MFRGGZA='), 'abcd')
    145165        eq(base64.b32decode('MFRGGZDF'), 'abcde')
     166        # Non-bytes
     167        self.assertRaises(TypeError, base64.b32decode, bytearray('MFRGG==='))
    146168
    147169    def test_b32decode_casefold(self):
     
    174196        eq(base64.b16encode('\x01\x02\xab\xcd\xef'), '0102ABCDEF')
    175197        eq(base64.b16encode('\x00'), '00')
     198        # Non-bytes
     199        eq(base64.b16encode(bytearray('\x01\x02\xab\xcd\xef')), '0102ABCDEF')
    176200
    177201    def test_b16decode(self):
     
    183207        # Case fold
    184208        eq(base64.b16decode('0102abcdef', True), '\x01\x02\xab\xcd\xef')
     209        # Non-bytes
     210        eq(base64.b16decode(bytearray("0102ABCDEF")), '\x01\x02\xab\xcd\xef')
    185211
    186212
Note: See TracChangeset for help on using the changeset viewer.