(self)
| 135 | |
| 136 | |
| 137 | def test_b64encode(self): |
| 138 | eq = self.assertEqual |
| 139 | # Test default alphabet |
| 140 | eq(base64.b64encode(b"www.python.org"), b"d3d3LnB5dGhvbi5vcmc=") |
| 141 | eq(base64.b64encode(b'\x00'), b'AA==') |
| 142 | eq(base64.b64encode(b"a"), b"YQ==") |
| 143 | eq(base64.b64encode(b"ab"), b"YWI=") |
| 144 | eq(base64.b64encode(b"abc"), b"YWJj") |
| 145 | eq(base64.b64encode(b""), b"") |
| 146 | eq(base64.b64encode(b"abcdefghijklmnopqrstuvwxyz" |
| 147 | b"ABCDEFGHIJKLMNOPQRSTUVWXYZ" |
| 148 | b"0123456789!@#0^&*();:<>,. []{}"), |
| 149 | b"YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXpBQkNE" |
| 150 | b"RUZHSElKS0xNTk9QUVJTVFVWV1hZWjAxMjM0NT" |
| 151 | b"Y3ODkhQCMwXiYqKCk7Ojw+LC4gW117fQ==") |
| 152 | # Test with arbitrary alternative characters |
| 153 | eq(base64.b64encode(b'\xd3V\xbeo\xf7\x1d', altchars=b'*$'), b'01a*b$cd') |
| 154 | eq(base64.b64encode(b'\xd3V\xbeo\xf7\x1d', altchars=bytearray(b'*$')), |
| 155 | b'01a*b$cd') |
| 156 | eq(base64.b64encode(b'\xd3V\xbeo\xf7\x1d', altchars=memoryview(b'*$')), |
| 157 | b'01a*b$cd') |
| 158 | eq(base64.b64encode(b'\xd3V\xbeo\xf7\x1d', altchars=array('B', b'*$')), |
| 159 | b'01a*b$cd') |
| 160 | # Non-bytes |
| 161 | self.check_other_types(base64.b64encode, b'abcd', b'YWJjZA==') |
| 162 | self.check_encode_type_errors(base64.b64encode) |
| 163 | self.assertRaises(TypeError, base64.b64encode, b"", altchars="*$") |
| 164 | # Test standard alphabet |
| 165 | eq(base64.standard_b64encode(b"www.python.org"), b"d3d3LnB5dGhvbi5vcmc=") |
| 166 | eq(base64.standard_b64encode(b"a"), b"YQ==") |
| 167 | eq(base64.standard_b64encode(b"ab"), b"YWI=") |
| 168 | eq(base64.standard_b64encode(b"abc"), b"YWJj") |
| 169 | eq(base64.standard_b64encode(b""), b"") |
| 170 | eq(base64.standard_b64encode(b"abcdefghijklmnopqrstuvwxyz" |
| 171 | b"ABCDEFGHIJKLMNOPQRSTUVWXYZ" |
| 172 | b"0123456789!@#0^&*();:<>,. []{}"), |
| 173 | b"YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXpBQkNE" |
| 174 | b"RUZHSElKS0xNTk9QUVJTVFVWV1hZWjAxMjM0NT" |
| 175 | b"Y3ODkhQCMwXiYqKCk7Ojw+LC4gW117fQ==") |
| 176 | # Non-bytes |
| 177 | self.check_other_types(base64.standard_b64encode, |
| 178 | b'abcd', b'YWJjZA==') |
| 179 | self.check_encode_type_errors(base64.standard_b64encode) |
| 180 | # Test with 'URL safe' alternative characters |
| 181 | eq(base64.urlsafe_b64encode(b'\xd3V\xbeo\xf7\x1d'), b'01a-b_cd') |
| 182 | # Non-bytes |
| 183 | self.check_other_types(base64.urlsafe_b64encode, |
| 184 | b'\xd3V\xbeo\xf7\x1d', b'01a-b_cd') |
| 185 | self.check_encode_type_errors(base64.urlsafe_b64encode) |
| 186 | |
| 187 | def test_b64decode(self): |
| 188 | eq = self.assertEqual |
nothing calls this directly
no test coverage detected