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")

def test_decodebytes(self): @@ -37,6 +39,8 @@ class LegacyBase64TestCase(unittest.Test b"ABCDEFGHIJKLMNOPQRSTUVWXYZ" b"0123456789!@#0^&*();:<>,. []{}") eq(base64.decodebytes(b''), b'')

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')

@@ -93,11 +101,14 @@ class BaseXYTestCase(unittest.TestCase): b"YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXpBQkNE" b"RUZHSElKS0xNTk9QUVJTVFVWV1hZWjAxMjM0NT" b"Y3ODkhQCMwXiYqKCk7Ojw+LC4gW117fQ==")

@@ -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)

# 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)

# 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)

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')

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)

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')

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')

def test_decode_nonascii_str(self): decode_funcs = (base64.b64decode,