Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(13716)

Delta Between Two Patch Sets: Lib/test/test_base64.py

Issue 17839: base64 module should use memoryview
Left Patch Set: Created 6 years, 3 months ago
Right Patch Set: Created 6 years, 3 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « Lib/base64.py ('k') | Lib/test/test_codecs.py » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 import unittest 1 import unittest
2 from test import support 2 from test import support
3 import base64 3 import base64
4 import binascii 4 import binascii
5 import os 5 import os
6 import sys 6 import sys
7 import subprocess 7 import subprocess
8 from array import array 8 from array import array
9 9
10 10
11 11
12 class LegacyBase64TestCase(unittest.TestCase): 12 class LegacyBase64TestCase(unittest.TestCase):
13 def test_encodebytes(self): 13 def test_encodebytes(self):
14 eq = self.assertEqual 14 eq = self.assertEqual
15 eq(base64.encodebytes(b"www.python.org"), b"d3d3LnB5dGhvbi5vcmc=\n") 15 eq(base64.encodebytes(b"www.python.org"), b"d3d3LnB5dGhvbi5vcmc=\n")
16 eq(base64.encodebytes(b"a"), b"YQ==\n") 16 eq(base64.encodebytes(b"a"), b"YQ==\n")
17 eq(base64.encodebytes(b"ab"), b"YWI=\n") 17 eq(base64.encodebytes(b"ab"), b"YWI=\n")
18 eq(base64.encodebytes(b"abc"), b"YWJj\n") 18 eq(base64.encodebytes(b"abc"), b"YWJj\n")
19 eq(base64.encodebytes(b""), b"") 19 eq(base64.encodebytes(b""), b"")
20 eq(base64.encodebytes(b"abcdefghijklmnopqrstuvwxyz" 20 eq(base64.encodebytes(b"abcdefghijklmnopqrstuvwxyz"
21 b"ABCDEFGHIJKLMNOPQRSTUVWXYZ" 21 b"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
22 b"0123456789!@#0^&*();:<>,. []{}"), 22 b"0123456789!@#0^&*();:<>,. []{}"),
23 b"YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXpBQkNE" 23 b"YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXpBQkNE"
24 b"RUZHSElKS0xNTk9QUVJTVFVWV1hZWjAxMjM0\nNT" 24 b"RUZHSElKS0xNTk9QUVJTVFVWV1hZWjAxMjM0\nNT"
25 b"Y3ODkhQCMwXiYqKCk7Ojw+LC4gW117fQ==\n") 25 b"Y3ODkhQCMwXiYqKCk7Ojw+LC4gW117fQ==\n")
26 # Non-bytes 26 # Non-bytes
27 eq(base64.encodebytes(bytearray(b'abc')), b'YWJj\n') 27 eq(base64.encodebytes(bytearray(b'abc')), b'YWJj\n')
28 eq(base64.encodebytes(memoryview(b'abc')), b'YWJj\n')
29 eq(base64.encodebytes(array('B', b'abc')), b'YWJj\n')
28 self.assertRaises(TypeError, base64.encodebytes, "") 30 self.assertRaises(TypeError, base64.encodebytes, "")
29 self.assertRaises(TypeError, base64.encodebytes, []) 31 self.assertRaises(TypeError, base64.encodebytes, [])
30 32
31 def test_decodebytes(self): 33 def test_decodebytes(self):
32 eq = self.assertEqual 34 eq = self.assertEqual
33 eq(base64.decodebytes(b"d3d3LnB5dGhvbi5vcmc=\n"), b"www.python.org") 35 eq(base64.decodebytes(b"d3d3LnB5dGhvbi5vcmc=\n"), b"www.python.org")
34 eq(base64.decodebytes(b"YQ==\n"), b"a") 36 eq(base64.decodebytes(b"YQ==\n"), b"a")
35 eq(base64.decodebytes(b"YWI=\n"), b"ab") 37 eq(base64.decodebytes(b"YWI=\n"), b"ab")
36 eq(base64.decodebytes(b"YWJj\n"), b"abc") 38 eq(base64.decodebytes(b"YWJj\n"), b"abc")
37 eq(base64.decodebytes(b"YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXpBQkNE" 39 eq(base64.decodebytes(b"YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXpBQkNE"
38 b"RUZHSElKS0xNTk9QUVJTVFVWV1hZWjAxMjM0\nNT" 40 b"RUZHSElKS0xNTk9QUVJTVFVWV1hZWjAxMjM0\nNT"
39 b"Y3ODkhQCMwXiYqKCk7Ojw+LC4gW117fQ==\n"), 41 b"Y3ODkhQCMwXiYqKCk7Ojw+LC4gW117fQ==\n"),
40 b"abcdefghijklmnopqrstuvwxyz" 42 b"abcdefghijklmnopqrstuvwxyz"
41 b"ABCDEFGHIJKLMNOPQRSTUVWXYZ" 43 b"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
42 b"0123456789!@#0^&*();:<>,. []{}") 44 b"0123456789!@#0^&*();:<>,. []{}")
43 eq(base64.decodebytes(b''), b'') 45 eq(base64.decodebytes(b''), b'')
44 # Non-bytes 46 # Non-bytes
45 eq(base64.decodebytes(bytearray(b'YWJj\n')), b'abc') 47 eq(base64.decodebytes(bytearray(b'YWJj\n')), b'abc')
48 eq(base64.decodebytes(memoryview(b'YWJj\n')), b'abc')
49 eq(base64.decodebytes(array('B', b'YWJj\n')), b'abc')
46 self.assertRaises(TypeError, base64.decodebytes, "") 50 self.assertRaises(TypeError, base64.decodebytes, "")
47 self.assertRaises(TypeError, base64.decodebytes, []) 51 self.assertRaises(TypeError, base64.decodebytes, [])
48 52
49 def test_encode(self): 53 def test_encode(self):
50 eq = self.assertEqual 54 eq = self.assertEqual
51 from io import BytesIO, StringIO 55 from io import BytesIO, StringIO
52 infp = BytesIO(b'abcdefghijklmnopqrstuvwxyz' 56 infp = BytesIO(b'abcdefghijklmnopqrstuvwxyz'
53 b'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 57 b'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
54 b'0123456789!@#0^&*();:<>,. []{}') 58 b'0123456789!@#0^&*();:<>,. []{}')
55 outfp = BytesIO() 59 outfp = BytesIO()
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after
390 output = self.get_output('-d', support.TESTFN) 394 output = self.get_output('-d', support.TESTFN)
391 self.assertEqual(output.rstrip(), b'a\xffb') 395 self.assertEqual(output.rstrip(), b'a\xffb')
392 396
393 397
394 398
395 def test_main(): 399 def test_main():
396 support.run_unittest(__name__) 400 support.run_unittest(__name__)
397 401
398 if __name__ == '__main__': 402 if __name__ == '__main__':
399 test_main() 403 test_main()
LEFTRIGHT

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+