@@ -19,6 +19,7 @@ def test_encodestring(self):
1919 b"YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXpBQkNE"
2020 b"RUZHSElKS0xNTk9QUVJTVFVWV1hZWjAxMjM0\n NT"
2121 b"Y3ODkhQCMwXiYqKCk7Ojw+LC4gW117fQ==\n " )
22+ self .assertRaises (TypeError , base64 .encodestring , "" )
2223
2324 def test_decodestring (self ):
2425 eq = self .assertEqual
@@ -33,6 +34,7 @@ def test_decodestring(self):
3334 b"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
3435 b"0123456789!@#0^&*();:<>,. []{}" )
3536 eq (base64 .decodestring (b'' ), b'' )
37+ self .assertRaises (TypeError , base64 .decodestring , "" )
3638
3739 def test_encode (self ):
3840 eq = self .assertEqual
@@ -54,7 +56,6 @@ def test_decode(self):
5456 base64 .decode (infp , outfp )
5557 self .assertEqual (outfp .getvalue (), b'www.python.org' )
5658
57-
5859
5960class BaseXYTestCase (unittest .TestCase ):
6061 def test_b64encode (self ):
@@ -73,7 +74,10 @@ def test_b64encode(self):
7374 b"RUZHSElKS0xNTk9QUVJTVFVWV1hZWjAxMjM0NT"
7475 b"Y3ODkhQCMwXiYqKCk7Ojw+LC4gW117fQ==" )
7576 # Test with arbitrary alternative characters
76- eq (base64 .b64encode (b'\xd3 V\xbe o\xf7 \x1d ' , altchars = '*$' ), b'01a*b$cd' )
77+ eq (base64 .b64encode (b'\xd3 V\xbe o\xf7 \x1d ' , altchars = b'*$' ), b'01a*b$cd' )
78+ # Check if passing a str object raises an error
79+ self .assertRaises (TypeError , base64 .b64encode , "" )
80+ self .assertRaises (TypeError , base64 .b64encode , b"" , altchars = "" )
7781 # Test standard alphabet
7882 eq (base64 .standard_b64encode (b"www.python.org" ), b"d3d3LnB5dGhvbi5vcmc=" )
7983 eq (base64 .standard_b64encode (b"a" ), b"YQ==" )
@@ -86,8 +90,13 @@ def test_b64encode(self):
8690 b"YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXpBQkNE"
8791 b"RUZHSElKS0xNTk9QUVJTVFVWV1hZWjAxMjM0NT"
8892 b"Y3ODkhQCMwXiYqKCk7Ojw+LC4gW117fQ==" )
93+ # Check if passing a str object raises an error
94+ self .assertRaises (TypeError , base64 .standard_b64encode , "" )
95+ self .assertRaises (TypeError , base64 .standard_b64encode , b"" , altchars = "" )
8996 # Test with 'URL safe' alternative characters
9097 eq (base64 .urlsafe_b64encode (b'\xd3 V\xbe o\xf7 \x1d ' ), b'01a-b_cd' )
98+ # Check if passing a str object raises an error
99+ self .assertRaises (TypeError , base64 .urlsafe_b64encode , "" )
91100
92101 def test_b64decode (self ):
93102 eq = self .assertEqual
@@ -104,7 +113,10 @@ def test_b64decode(self):
104113 b"0123456789!@#0^&*();:<>,. []{}" )
105114 eq (base64 .b64decode (b'' ), b'' )
106115 # Test with arbitrary alternative characters
107- eq (base64 .b64decode (b'01a*b$cd' , altchars = '*$' ), b'\xd3 V\xbe o\xf7 \x1d ' )
116+ eq (base64 .b64decode (b'01a*b$cd' , altchars = b'*$' ), b'\xd3 V\xbe o\xf7 \x1d ' )
117+ # Check if passing a str object raises an error
118+ self .assertRaises (TypeError , base64 .b64decode , "" )
119+ self .assertRaises (TypeError , base64 .b64decode , b"" , altchars = "" )
108120 # Test standard alphabet
109121 eq (base64 .standard_b64decode (b"d3d3LnB5dGhvbi5vcmc=" ), b"www.python.org" )
110122 eq (base64 .standard_b64decode (b"YQ==" ), b"a" )
@@ -117,8 +129,12 @@ def test_b64decode(self):
117129 b"abcdefghijklmnopqrstuvwxyz"
118130 b"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
119131 b"0123456789!@#0^&*();:<>,. []{}" )
132+ # Check if passing a str object raises an error
133+ self .assertRaises (TypeError , base64 .standard_b64decode , "" )
134+ self .assertRaises (TypeError , base64 .standard_b64decode , b"" , altchars = "" )
120135 # Test with 'URL safe' alternative characters
121136 eq (base64 .urlsafe_b64decode (b'01a-b_cd' ), b'\xd3 V\xbe o\xf7 \x1d ' )
137+ self .assertRaises (TypeError , base64 .urlsafe_b64decode , "" )
122138
123139 def test_b64decode_error (self ):
124140 self .assertRaises (binascii .Error , base64 .b64decode , b'abc' )
@@ -132,6 +148,7 @@ def test_b32encode(self):
132148 eq (base64 .b32encode (b'abc' ), b'MFRGG===' )
133149 eq (base64 .b32encode (b'abcd' ), b'MFRGGZA=' )
134150 eq (base64 .b32encode (b'abcde' ), b'MFRGGZDF' )
151+ self .assertRaises (TypeError , base64 .b32encode , "" )
135152
136153 def test_b32decode (self ):
137154 eq = self .assertEqual
@@ -142,6 +159,7 @@ def test_b32decode(self):
142159 eq (base64 .b32decode (b'MFRGG===' ), b'abc' )
143160 eq (base64 .b32decode (b'MFRGGZA=' ), b'abcd' )
144161 eq (base64 .b32decode (b'MFRGGZDF' ), b'abcde' )
162+ self .assertRaises (TypeError , base64 .b32decode , "" )
145163
146164 def test_b32decode_casefold (self ):
147165 eq = self .assertEqual
@@ -163,6 +181,7 @@ def test_b32decode_casefold(self):
163181 eq (base64 .b32decode (b'MLO23456' ), b'b\xdd \xad \xf3 \xbe ' )
164182 eq (base64 .b32decode (b'M1023456' , map01 = b'L' ), b'b\xdd \xad \xf3 \xbe ' )
165183 eq (base64 .b32decode (b'M1023456' , map01 = b'I' ), b'b\x1d \xad \xf3 \xbe ' )
184+ self .assertRaises (TypeError , base64 .b32decode , b"" , map01 = "" )
166185
167186 def test_b32decode_error (self ):
168187 self .assertRaises (binascii .Error , base64 .b32decode , b'abc' )
@@ -172,6 +191,7 @@ def test_b16encode(self):
172191 eq = self .assertEqual
173192 eq (base64 .b16encode (b'\x01 \x02 \xab \xcd \xef ' ), b'0102ABCDEF' )
174193 eq (base64 .b16encode (b'\x00 ' ), b'00' )
194+ self .assertRaises (TypeError , base64 .b16encode , "" )
175195
176196 def test_b16decode (self ):
177197 eq = self .assertEqual
@@ -181,6 +201,7 @@ def test_b16decode(self):
181201 self .assertRaises (binascii .Error , base64 .b16decode , b'0102abcdef' )
182202 # Case fold
183203 eq (base64 .b16decode (b'0102abcdef' , True ), b'\x01 \x02 \xab \xcd \xef ' )
204+ self .assertRaises (TypeError , base64 .b16decode , "" )
184205
185206 def test_ErrorHeritage (self ):
186207 self .assert_ (issubclass (binascii .Error , ValueError ))
0 commit comments