Skip to content

Commit cb4af0e

Browse files
Add more tests for a85encode().
1 parent cd2e330 commit cb4af0e

File tree

1 file changed

+60
-28
lines changed

1 file changed

+60
-28
lines changed

Lib/test/test_base64.py

Lines changed: 60 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -174,27 +174,6 @@ def test_b64encode(self):
174174
b"RUZHSElKS0xNTk9QUVJTVFVWV1hZWjAxMjM0NT"
175175
b"Y3ODkhQCMwXiYqKCk7Ojw+LC4gW117fQ==")
176176

177-
eq(base64.b64encode(b"www.python.org", wrapcol=0), b'd3d3LnB5dGhvbi5vcmc=')
178-
eq(base64.b64encode(b"www.python.org", wrapcol=8), b'd3d3LnB5\ndGhvbi5v\ncmc=')
179-
eq(base64.b64encode(b"www.python.org", wrapcol=76), b'd3d3LnB5dGhvbi5vcmc=')
180-
eq(base64.b64encode(b"www.python.org", wrapcol=1),
181-
b'd\n3\nd\n3\nL\nn\nB\n5\nd\nG\nh\nv\nb\ni\n5\nv\nc\nm\nc\n=')
182-
eq(base64.b64encode(b"www.python.org", wrapcol=sys.maxsize),
183-
b'd3d3LnB5dGhvbi5vcmc=')
184-
if check_impl_detail():
185-
eq(base64.b64encode(b"www.python.org", wrapcol=sys.maxsize*2),
186-
b'd3d3LnB5dGhvbi5vcmc=')
187-
with self.assertRaises(OverflowError):
188-
base64.b64encode(b"www.python.org", wrapcol=2**1000)
189-
with self.assertRaises(ValueError):
190-
base64.b64encode(b"www.python.org", wrapcol=-8)
191-
with self.assertRaises(TypeError):
192-
base64.b64encode(b"www.python.org", wrapcol=8.0)
193-
with self.assertRaises(TypeError):
194-
base64.b64encode(b"www.python.org", wrapcol='8')
195-
eq(base64.b64encode(b"", wrapcol=0), b'')
196-
eq(base64.b64encode(b"", wrapcol=8), b'')
197-
198177
# Test with arbitrary alternative characters
199178
eq(base64.b64encode(b'\xd3V\xbeo\xf7\x1d', altchars=b'*$'), b'01a*b$cd')
200179
eq(base64.b64encode(b'\xd3V\xbeo\xf7\x1d', altchars=bytearray(b'*$')),
@@ -230,6 +209,31 @@ def test_b64encode(self):
230209
b'\xd3V\xbeo\xf7\x1d', b'01a-b_cd')
231210
self.check_encode_type_errors(base64.urlsafe_b64encode)
232211

212+
def test_b64encode_wrapcol(self):
213+
eq = self.assertEqual
214+
b = b'www.python.org'
215+
eq(base64.b64encode(b, wrapcol=0), b'd3d3LnB5dGhvbi5vcmc=')
216+
eq(base64.b64encode(b, wrapcol=8), b'd3d3LnB5\ndGhvbi5v\ncmc=')
217+
eq(base64.b64encode(b, wrapcol=76), b'd3d3LnB5dGhvbi5vcmc=')
218+
eq(base64.b64encode(b, wrapcol=1),
219+
b'd\n3\nd\n3\nL\nn\nB\n5\nd\nG\nh\nv\nb\ni\n5\nv\nc\nm\nc\n=')
220+
eq(base64.b64encode(b, wrapcol=sys.maxsize), b'd3d3LnB5dGhvbi5vcmc=')
221+
if check_impl_detail():
222+
eq(base64.b64encode(b, wrapcol=sys.maxsize*2),
223+
b'd3d3LnB5dGhvbi5vcmc=')
224+
with self.assertRaises(OverflowError):
225+
base64.b64encode(b, wrapcol=2**1000)
226+
with self.assertRaises(ValueError):
227+
base64.b64encode(b, wrapcol=-8)
228+
with self.assertRaises(TypeError):
229+
base64.b64encode(b, wrapcol=8.0)
230+
with self.assertRaises(TypeError):
231+
base64.b64encode(b, wrapcol='8')
232+
with self.assertRaises(TypeError):
233+
base64.b64encode(b, wrapcol=None)
234+
eq(base64.b64encode(b'', wrapcol=0), b'')
235+
eq(base64.b64encode(b'', wrapcol=8), b'')
236+
233237
def test_b64decode(self):
234238
eq = self.assertEqual
235239

@@ -637,18 +641,46 @@ def test_a85encode(self):
637641

638642
self.assertRaises(TypeError, base64.a85encode, "")
639643

640-
eq(base64.a85encode(b"www.python.org", wrapcol=7, adobe=False),
641-
b'GB\\6`E-\nZP=Df.1\nGEb>')
642-
eq(base64.a85encode(b"\0\0\0\0www.python.org", wrapcol=7, adobe=False),
643-
b'zGB\\6`E\n-ZP=Df.\n1GEb>')
644-
eq(base64.a85encode(b"www.python.org", wrapcol=7, adobe=True),
645-
b'<~GB\\6`\nE-ZP=Df\n.1GEb>\n~>')
646-
647644
eq(base64.a85encode(b' '*8, foldspaces=True, adobe=False), b'yy')
648645
eq(base64.a85encode(b' '*7, foldspaces=True, adobe=False), b'y+<Vd')
649646
eq(base64.a85encode(b' '*6, foldspaces=True, adobe=False), b'y+<U')
650647
eq(base64.a85encode(b' '*5, foldspaces=True, adobe=False), b'y+9')
651648

649+
def test_a85encode_wrapcol(self):
650+
eq = self.assertEqual
651+
b = b'www.python.org'
652+
eq(base64.a85encode(b, wrapcol=0), b'GB\\6`E-ZP=Df.1GEb>')
653+
eq(base64.a85encode(b, wrapcol=7), b'GB\\6`E-\nZP=Df.1\nGEb>')
654+
eq(base64.a85encode(b"\0\0\0\0www.python.org", wrapcol=7),
655+
b'zGB\\6`E\n-ZP=Df.\n1GEb>')
656+
eq(base64.a85encode(b, wrapcol=75), b'GB\\6`E-ZP=Df.1GEb>')
657+
eq(base64.a85encode(b, wrapcol=1),
658+
b'G\nB\n\\\n6\n`\nE\n-\nZ\nP\n=\nD\nf\n.\n1\nG\nE\nb\n>')
659+
eq(base64.a85encode(b, wrapcol=7, adobe=True),
660+
b'<~GB\\6`\nE-ZP=Df\n.1GEb>\n~>')
661+
eq(base64.a85encode(b, wrapcol=1),
662+
b'G\nB\n\\\n6\n`\nE\n-\nZ\nP\n=\nD\nf\n.\n1\nG\nE\nb\n>')
663+
eq(base64.a85encode(b, wrapcol=1, adobe=True),
664+
b'<~\nGB\n\\6\n`E\n-Z\nP=\nDf\n.1\nGE\nb>\n~>')
665+
eq(base64.a85encode(b, wrapcol=sys.maxsize), b'GB\\6`E-ZP=Df.1GEb>')
666+
if check_impl_detail():
667+
eq(base64.a85encode(b, wrapcol=2**1000), b'GB\\6`E-ZP=Df.1GEb>')
668+
eq(base64.a85encode(b, wrapcol=-7),
669+
b'G\nB\n\\\n6\n`\nE\n-\nZ\nP\n=\nD\nf\n.\n1\nG\nE\nb\n>')
670+
eq(base64.a85encode(b, wrapcol=-7, adobe=True),
671+
b'<~\nGB\n\\6\n`E\n-Z\nP=\nDf\n.1\nGE\nb>\n~>')
672+
with self.assertRaises(TypeError):
673+
base64.a85encode(b, wrapcol=7.0)
674+
with self.assertRaises(TypeError):
675+
base64.a85encode(b, wrapcol='7')
676+
if check_impl_detail():
677+
eq(base64.a85encode(b, wrapcol=None), b'GB\\6`E-ZP=Df.1GEb>')
678+
eq(base64.a85encode(b'', wrapcol=0), b'')
679+
eq(base64.a85encode(b'', wrapcol=7), b'')
680+
eq(base64.a85encode(b'', wrapcol=1, adobe=True), b'<~\n~>')
681+
eq(base64.a85encode(b'', wrapcol=3, adobe=True), b'<~\n~>')
682+
eq(base64.a85encode(b'', wrapcol=4, adobe=True), b'<~~>')
683+
652684
def test_b85encode(self):
653685
eq = self.assertEqual
654686

0 commit comments

Comments
 (0)