Back to index

python3.2  3.2.2
Public Member Functions
test.test_base64.BaseXYTestCase Class Reference

List of all members.

Public Member Functions

def test_b64encode
def test_b64decode
def test_b64decode_padding_error
def test_b64decode_invalid_chars
def test_b32encode
def test_b32decode
def test_b32decode_casefold
def test_b32decode_error
def test_b16encode
def test_b16decode
def test_ErrorHeritage

Detailed Description

Definition at line 62 of file test_base64.py.


Member Function Documentation

Definition at line 214 of file test_base64.py.

00214 
00215     def test_b16decode(self):
00216         eq = self.assertEqual
00217         eq(base64.b16decode(b'0102ABCDEF'), b'\x01\x02\xab\xcd\xef')
00218         eq(base64.b16decode(b'00'), b'\x00')
00219         # Lower case is not allowed without a flag
00220         self.assertRaises(binascii.Error, base64.b16decode, b'0102abcdef')
00221         # Case fold
00222         eq(base64.b16decode(b'0102abcdef', True), b'\x01\x02\xab\xcd\xef')
00223         self.assertRaises(TypeError, base64.b16decode, "")

Here is the call graph for this function:

Definition at line 208 of file test_base64.py.

00208 
00209     def test_b16encode(self):
00210         eq = self.assertEqual
00211         eq(base64.b16encode(b'\x01\x02\xab\xcd\xef'), b'0102ABCDEF')
00212         eq(base64.b16encode(b'\x00'), b'00')
00213         self.assertRaises(TypeError, base64.b16encode, "")

Here is the call graph for this function:

Definition at line 171 of file test_base64.py.

00171 
00172     def test_b32decode(self):
00173         eq = self.assertEqual
00174         eq(base64.b32decode(b''), b'')
00175         eq(base64.b32decode(b'AA======'), b'\x00')
00176         eq(base64.b32decode(b'ME======'), b'a')
00177         eq(base64.b32decode(b'MFRA===='), b'ab')
00178         eq(base64.b32decode(b'MFRGG==='), b'abc')
00179         eq(base64.b32decode(b'MFRGGZA='), b'abcd')
00180         eq(base64.b32decode(b'MFRGGZDF'), b'abcde')
00181         self.assertRaises(TypeError, base64.b32decode, "")

Here is the call graph for this function:

Definition at line 182 of file test_base64.py.

00182 
00183     def test_b32decode_casefold(self):
00184         eq = self.assertEqual
00185         eq(base64.b32decode(b'', True), b'')
00186         eq(base64.b32decode(b'ME======', True), b'a')
00187         eq(base64.b32decode(b'MFRA====', True), b'ab')
00188         eq(base64.b32decode(b'MFRGG===', True), b'abc')
00189         eq(base64.b32decode(b'MFRGGZA=', True), b'abcd')
00190         eq(base64.b32decode(b'MFRGGZDF', True), b'abcde')
00191         # Lower cases
00192         eq(base64.b32decode(b'me======', True), b'a')
00193         eq(base64.b32decode(b'mfra====', True), b'ab')
00194         eq(base64.b32decode(b'mfrgg===', True), b'abc')
00195         eq(base64.b32decode(b'mfrggza=', True), b'abcd')
00196         eq(base64.b32decode(b'mfrggzdf', True), b'abcde')
00197         # Expected exceptions
00198         self.assertRaises(TypeError, base64.b32decode, b'me======')
00199         # Mapping zero and one
00200         eq(base64.b32decode(b'MLO23456'), b'b\xdd\xad\xf3\xbe')
00201         eq(base64.b32decode(b'M1023456', map01=b'L'), b'b\xdd\xad\xf3\xbe')
00202         eq(base64.b32decode(b'M1023456', map01=b'I'), b'b\x1d\xad\xf3\xbe')
00203         self.assertRaises(TypeError, base64.b32decode, b"", map01="")

Here is the call graph for this function:

Definition at line 204 of file test_base64.py.

00204 
00205     def test_b32decode_error(self):
00206         self.assertRaises(binascii.Error, base64.b32decode, b'abc')
00207         self.assertRaises(binascii.Error, base64.b32decode, b'ABCDEF==')

Here is the call graph for this function:

Definition at line 160 of file test_base64.py.

00160 
00161     def test_b32encode(self):
00162         eq = self.assertEqual
00163         eq(base64.b32encode(b''), b'')
00164         eq(base64.b32encode(b'\x00'), b'AA======')
00165         eq(base64.b32encode(b'a'), b'ME======')
00166         eq(base64.b32encode(b'ab'), b'MFRA====')
00167         eq(base64.b32encode(b'abc'), b'MFRGG===')
00168         eq(base64.b32encode(b'abcd'), b'MFRGGZA=')
00169         eq(base64.b32encode(b'abcde'), b'MFRGGZDF')
00170         self.assertRaises(TypeError, base64.b32encode, "")

Here is the call graph for this function:

Definition at line 103 of file test_base64.py.

00103 
00104     def test_b64decode(self):
00105         eq = self.assertEqual
00106         eq(base64.b64decode(b"d3d3LnB5dGhvbi5vcmc="), b"www.python.org")
00107         eq(base64.b64decode(b'AA=='), b'\x00')
00108         eq(base64.b64decode(b"YQ=="), b"a")
00109         eq(base64.b64decode(b"YWI="), b"ab")
00110         eq(base64.b64decode(b"YWJj"), b"abc")
00111         eq(base64.b64decode(b"YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXpBQkNE"
00112                             b"RUZHSElKS0xNTk9QUVJTVFVWV1hZWjAxMjM0\nNT"
00113                             b"Y3ODkhQCMwXiYqKCk7Ojw+LC4gW117fQ=="),
00114            b"abcdefghijklmnopqrstuvwxyz"
00115            b"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
00116            b"0123456789!@#0^&*();:<>,. []{}")
00117         eq(base64.b64decode(b''), b'')
00118         # Test with arbitrary alternative characters
00119         eq(base64.b64decode(b'01a*b$cd', altchars=b'*$'), b'\xd3V\xbeo\xf7\x1d')
00120         # Check if passing a str object raises an error
00121         self.assertRaises(TypeError, base64.b64decode, "")
00122         self.assertRaises(TypeError, base64.b64decode, b"", altchars="")
00123         # Test standard alphabet
00124         eq(base64.standard_b64decode(b"d3d3LnB5dGhvbi5vcmc="), b"www.python.org")
00125         eq(base64.standard_b64decode(b"YQ=="), b"a")
00126         eq(base64.standard_b64decode(b"YWI="), b"ab")
00127         eq(base64.standard_b64decode(b"YWJj"), b"abc")
00128         eq(base64.standard_b64decode(b""), b"")
00129         eq(base64.standard_b64decode(b"YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXpBQkNE"
00130                                      b"RUZHSElKS0xNTk9QUVJTVFVWV1hZWjAxMjM0NT"
00131                                      b"Y3ODkhQCMwXiYqKCk7Ojw+LC4gW117fQ=="),
00132            b"abcdefghijklmnopqrstuvwxyz"
00133            b"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
00134            b"0123456789!@#0^&*();:<>,. []{}")
00135         # Check if passing a str object raises an error
00136         self.assertRaises(TypeError, base64.standard_b64decode, "")
00137         self.assertRaises(TypeError, base64.standard_b64decode, b"", altchars="")
00138         # Test with 'URL safe' alternative characters
00139         eq(base64.urlsafe_b64decode(b'01a-b_cd'), b'\xd3V\xbeo\xf7\x1d')
00140         self.assertRaises(TypeError, base64.urlsafe_b64decode, "")

Here is the call graph for this function:

Definition at line 144 of file test_base64.py.

00144 
00145     def test_b64decode_invalid_chars(self):
00146         # issue 1466065: Test some invalid characters.
00147         tests = ((b'%3d==', b'\xdd'),
00148                  (b'$3d==', b'\xdd'),
00149                  (b'[==', b''),
00150                  (b'YW]3=', b'am'),
00151                  (b'3{d==', b'\xdd'),
00152                  (b'3d}==', b'\xdd'),
00153                  (b'@@', b''),
00154                  (b'!', b''),
00155                  (b'YWJj\nYWI=', b'abcab'))
00156         for bstr, res in tests:
00157             self.assertEqual(base64.b64decode(bstr), res)
00158             with self.assertRaises(binascii.Error):
00159                 base64.b64decode(bstr, validate=True)

Here is the call graph for this function:

Definition at line 141 of file test_base64.py.

00141 
00142     def test_b64decode_padding_error(self):
00143         self.assertRaises(binascii.Error, base64.b64decode, b'abc')

Here is the call graph for this function:

Definition at line 63 of file test_base64.py.

00063 
00064     def test_b64encode(self):
00065         eq = self.assertEqual
00066         # Test default alphabet
00067         eq(base64.b64encode(b"www.python.org"), b"d3d3LnB5dGhvbi5vcmc=")
00068         eq(base64.b64encode(b'\x00'), b'AA==')
00069         eq(base64.b64encode(b"a"), b"YQ==")
00070         eq(base64.b64encode(b"ab"), b"YWI=")
00071         eq(base64.b64encode(b"abc"), b"YWJj")
00072         eq(base64.b64encode(b""), b"")
00073         eq(base64.b64encode(b"abcdefghijklmnopqrstuvwxyz"
00074                             b"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
00075                             b"0123456789!@#0^&*();:<>,. []{}"),
00076            b"YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXpBQkNE"
00077            b"RUZHSElKS0xNTk9QUVJTVFVWV1hZWjAxMjM0NT"
00078            b"Y3ODkhQCMwXiYqKCk7Ojw+LC4gW117fQ==")
00079         # Test with arbitrary alternative characters
00080         eq(base64.b64encode(b'\xd3V\xbeo\xf7\x1d', altchars=b'*$'), b'01a*b$cd')
00081         # Check if passing a str object raises an error
00082         self.assertRaises(TypeError, base64.b64encode, "")
00083         self.assertRaises(TypeError, base64.b64encode, b"", altchars="")
00084         # Test standard alphabet
00085         eq(base64.standard_b64encode(b"www.python.org"), b"d3d3LnB5dGhvbi5vcmc=")
00086         eq(base64.standard_b64encode(b"a"), b"YQ==")
00087         eq(base64.standard_b64encode(b"ab"), b"YWI=")
00088         eq(base64.standard_b64encode(b"abc"), b"YWJj")
00089         eq(base64.standard_b64encode(b""), b"")
00090         eq(base64.standard_b64encode(b"abcdefghijklmnopqrstuvwxyz"
00091                                      b"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
00092                                      b"0123456789!@#0^&*();:<>,. []{}"),
00093            b"YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXpBQkNE"
00094            b"RUZHSElKS0xNTk9QUVJTVFVWV1hZWjAxMjM0NT"
00095            b"Y3ODkhQCMwXiYqKCk7Ojw+LC4gW117fQ==")
00096         # Check if passing a str object raises an error
00097         self.assertRaises(TypeError, base64.standard_b64encode, "")
00098         self.assertRaises(TypeError, base64.standard_b64encode, b"", altchars="")
00099         # Test with 'URL safe' alternative characters
00100         eq(base64.urlsafe_b64encode(b'\xd3V\xbeo\xf7\x1d'), b'01a-b_cd')
00101         # Check if passing a str object raises an error
00102         self.assertRaises(TypeError, base64.urlsafe_b64encode, "")

Here is the call graph for this function:

Definition at line 224 of file test_base64.py.

00224 
00225     def test_ErrorHeritage(self):
00226         self.assertTrue(issubclass(binascii.Error, ValueError))
00227 
00228 

Here is the call graph for this function:


The documentation for this class was generated from the following file: