cpython: 44edbea21640 (original) (raw)
--- a/Lib/test/test_base64.py +++ b/Lib/test/test_base64.py @@ -22,6 +22,8 @@ class LegacyBase64TestCase(unittest.Test b"YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXpBQkNE" b"RUZHSElKS0xNTk9QUVJTVFVWV1hZWjAxMjM0\nNT" b"Y3ODkhQCMwXiYqKCk7Ojw+LC4gW117fQ==\n")
# Non-bytes[](#l1.7)
eq(base64.encodebytes(bytearray(b'abc')), b'YWJj\n')[](#l1.8) self.assertRaises(TypeError, base64.encodebytes, "")[](#l1.9)
def test_decodebytes(self): @@ -37,6 +39,8 @@ class LegacyBase64TestCase(unittest.Test b"ABCDEFGHIJKLMNOPQRSTUVWXYZ" b"0123456789!@#0^&*();:<>,. []{}") eq(base64.decodebytes(b''), b'')
# Non-bytes[](#l1.16)
eq(base64.decodebytes(bytearray(b'YWJj\n')), b'abc')[](#l1.17) self.assertRaises(TypeError, base64.decodebytes, "")[](#l1.18)
def test_encode(self): @@ -78,6 +82,10 @@ class BaseXYTestCase(unittest.TestCase): b"Y3ODkhQCMwXiYqKCk7Ojw+LC4gW117fQ==") # Test with arbitrary alternative characters eq(base64.b64encode(b'\xd3V\xbeo\xf7\x1d', altchars=b'$'), b'01ab$cd')
# Non-bytes[](#l1.25)
eq(base64.b64encode(bytearray(b'abcd')), b'YWJjZA==')[](#l1.26)
eq(base64.b64encode(b'\xd3V\xbeo\xf7\x1d', altchars=bytearray(b'*$')),[](#l1.27)
b'01a*b$cd')[](#l1.28) # Check if passing a str object raises an error[](#l1.29) self.assertRaises(TypeError, base64.b64encode, "")[](#l1.30) self.assertRaises(TypeError, base64.b64encode, b"", altchars="")[](#l1.31)
@@ -93,11 +101,14 @@ class BaseXYTestCase(unittest.TestCase): b"YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXpBQkNE" b"RUZHSElKS0xNTk9QUVJTVFVWV1hZWjAxMjM0NT" b"Y3ODkhQCMwXiYqKCk7Ojw+LC4gW117fQ==")
# Non-bytes[](#l1.36)
eq(base64.standard_b64encode(bytearray(b'abcd')), b'YWJjZA==')[](#l1.37) # Check if passing a str object raises an error[](#l1.38) self.assertRaises(TypeError, base64.standard_b64encode, "")[](#l1.39)
self.assertRaises(TypeError, base64.standard_b64encode, b"", altchars="")[](#l1.40) # Test with 'URL safe' alternative characters[](#l1.41) eq(base64.urlsafe_b64encode(b'\xd3V\xbeo\xf7\x1d'), b'01a-b_cd')[](#l1.42)
# Non-bytes[](#l1.43)
eq(base64.urlsafe_b64encode(bytearray(b'\xd3V\xbeo\xf7\x1d')), b'01a-b_cd')[](#l1.44) # Check if passing a str object raises an error[](#l1.45) self.assertRaises(TypeError, base64.urlsafe_b64encode, "")[](#l1.46)
@@ -121,6 +132,8 @@ class BaseXYTestCase(unittest.TestCase): for data, res in tests.items(): eq(base64.b64decode(data), res) eq(base64.b64decode(data.decode('ascii')), res)
# Non-bytes[](#l1.52)
eq(base64.b64decode(bytearray(b"YWJj")), b"abc")[](#l1.53)
# Test with arbitrary alternative characters tests_altchars = {(b'01ab$cd', b'$'): b'\xd3V\xbeo\xf7\x1d', @@ -138,6 +151,8 @@ class BaseXYTestCase(unittest.TestCase): for data, res in tests.items(): eq(base64.standard_b64decode(data), res) eq(base64.standard_b64decode(data.decode('ascii')), res)
# Non-bytes[](#l1.61)
eq(base64.standard_b64decode(bytearray(b"YWJj")), b"abc")[](#l1.62)
# Test with 'URL safe' alternative characters tests_urlsafe = {b'01a-b_cd': b'\xd3V\xbeo\xf7\x1d', @@ -146,6 +161,8 @@ class BaseXYTestCase(unittest.TestCase): for data, res in tests_urlsafe.items(): eq(base64.urlsafe_b64decode(data), res) eq(base64.urlsafe_b64decode(data.decode('ascii')), res)
# Non-bytes[](#l1.70)
eq(base64.urlsafe_b64decode(bytearray(b'01a-b_cd')), b'\xd3V\xbeo\xf7\x1d')[](#l1.71)
def test_b64decode_padding_error(self): self.assertRaises(binascii.Error, base64.b64decode, b'abc') @@ -179,6 +196,8 @@ class BaseXYTestCase(unittest.TestCase): eq(base64.b32encode(b'abc'), b'MFRGG===') eq(base64.b32encode(b'abcd'), b'MFRGGZA=') eq(base64.b32encode(b'abcde'), b'MFRGGZDF')
# Non-bytes[](#l1.79)
eq(base64.b32encode(bytearray(b'abcd')), b'MFRGGZA=')[](#l1.80) self.assertRaises(TypeError, base64.b32encode, "")[](#l1.81)
def test_b32decode(self): @@ -194,6 +213,8 @@ class BaseXYTestCase(unittest.TestCase): for data, res in tests.items(): eq(base64.b32decode(data), res) eq(base64.b32decode(data.decode('ascii')), res)
# Non-bytes[](#l1.88)
eq(base64.b32decode(bytearray(b'MFRGG===')), b'abc')[](#l1.89)
def test_b32decode_casefold(self): eq = self.assertEqual @@ -245,6 +266,8 @@ class BaseXYTestCase(unittest.TestCase): eq = self.assertEqual eq(base64.b16encode(b'\x01\x02\xab\xcd\xef'), b'0102ABCDEF') eq(base64.b16encode(b'\x00'), b'00')
# Non-bytes[](#l1.97)
eq(base64.b16encode(bytearray(b'\x01\x02\xab\xcd\xef')), b'0102ABCDEF')[](#l1.98) self.assertRaises(TypeError, base64.b16encode, "")[](#l1.99)
def test_b16decode(self): @@ -259,6 +282,8 @@ class BaseXYTestCase(unittest.TestCase): # Case fold eq(base64.b16decode(b'0102abcdef', True), b'\x01\x02\xab\xcd\xef') eq(base64.b16decode('0102abcdef', True), b'\x01\x02\xab\xcd\xef')
# Non-bytes[](#l1.106)
eq(base64.b16decode(bytearray(b"0102ABCDEF")), b'\x01\x02\xab\xcd\xef')[](#l1.107)
def test_decode_nonascii_str(self): decode_funcs = (base64.b64decode,