MCPcopy Index your code
hub / github.com/python/cpython / test_b64encode

Method test_b64encode

Lib/test/test_base64.py:161–210  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

159
160
161 def test_b64encode(self):
162 eq = self.assertEqual
163 # Test default alphabet
164 eq(base64.b64encode(b"www.python.org"), b"d3d3LnB5dGhvbi5vcmc=")
165 eq(base64.b64encode(b'\x00'), b'AA==')
166 eq(base64.b64encode(b"a"), b"YQ==")
167 eq(base64.b64encode(b"ab"), b"YWI=")
168 eq(base64.b64encode(b"abc"), b"YWJj")
169 eq(base64.b64encode(b""), b"")
170 eq(base64.b64encode(b"abcdefghijklmnopqrstuvwxyz"
171 b"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
172 b"0123456789!@#0^&*();:<>,. []{}"),
173 b"YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXpBQkNE"
174 b"RUZHSElKS0xNTk9QUVJTVFVWV1hZWjAxMjM0NT"
175 b"Y3ODkhQCMwXiYqKCk7Ojw+LC4gW117fQ==")
176
177 # Test with arbitrary alternative characters
178 eq(base64.b64encode(b'\xd3V\xbeo\xf7\x1d', altchars=b'*$'), b'01a*b$cd')
179 eq(base64.b64encode(b'\xd3V\xbeo\xf7\x1d', altchars=bytearray(b'*$')),
180 b'01a*b$cd')
181 eq(base64.b64encode(b'\xd3V\xbeo\xf7\x1d', altchars=memoryview(b'*$')),
182 b'01a*b$cd')
183 eq(base64.b64encode(b'\xd3V\xbeo\xf7\x1d', altchars=array('B', b'*$')),
184 b'01a*b$cd')
185 # Non-bytes
186 self.check_other_types(base64.b64encode, b'abcd', b'YWJjZA==')
187 self.check_encode_type_errors(base64.b64encode)
188 self.assertRaises(TypeError, base64.b64encode, b"", altchars="*$")
189 # Test standard alphabet
190 eq(base64.standard_b64encode(b"www.python.org"), b"d3d3LnB5dGhvbi5vcmc=")
191 eq(base64.standard_b64encode(b"a"), b"YQ==")
192 eq(base64.standard_b64encode(b"ab"), b"YWI=")
193 eq(base64.standard_b64encode(b"abc"), b"YWJj")
194 eq(base64.standard_b64encode(b""), b"")
195 eq(base64.standard_b64encode(b"abcdefghijklmnopqrstuvwxyz"
196 b"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
197 b"0123456789!@#0^&*();:<>,. []{}"),
198 b"YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXpBQkNE"
199 b"RUZHSElKS0xNTk9QUVJTVFVWV1hZWjAxMjM0NT"
200 b"Y3ODkhQCMwXiYqKCk7Ojw+LC4gW117fQ==")
201 # Non-bytes
202 self.check_other_types(base64.standard_b64encode,
203 b'abcd', b'YWJjZA==')
204 self.check_encode_type_errors(base64.standard_b64encode)
205 # Test with 'URL safe' alternative characters
206 eq(base64.urlsafe_b64encode(b'\xd3V\xbeo\xf7\x1d'), b'01a-b_cd')
207 # Non-bytes
208 self.check_other_types(base64.urlsafe_b64encode,
209 b'\xd3V\xbeo\xf7\x1d', b'01a-b_cd')
210 self.check_encode_type_errors(base64.urlsafe_b64encode)
211
212 def test_b64encode_padded(self):
213 b64encode = base64.b64encode

Callers

nothing calls this directly

Calls 5

check_other_typesMethod · 0.95
eqFunction · 0.85
arrayClass · 0.85
assertRaisesMethod · 0.45

Tested by

no test coverage detected