Mercurial > cpython-lru_cache-weakref
annotate Lib/test/test_base64.py @ 78069:a8aa77458e12 3.2
Add c_size_t and c_ssize_t to the ctypes summary table.
| author | Antoine Pitrou <solipsis@pitrou.net> |
|---|---|
| date | Thu, 12 Jul 2012 20:31:50 +0200 |
| parents | 707586c70195 |
| children | a92e73dfbff6 |
| rev | line source |
|---|---|
|
28917
1741af48fd9f
Combine the functionality of test_support.run_unittest()
Walter Dörwald <walter@livinglogic.de>
parents:
24954
diff
changeset
|
1 import unittest |
|
47201
9c930a32cebb
#2621 rename test.test_support to test.support
Benjamin Peterson <benjamin@python.org>
parents:
46638
diff
changeset
|
2 from test import support |
|
28917
1741af48fd9f
Combine the functionality of test_support.run_unittest()
Walter Dörwald <walter@livinglogic.de>
parents:
24954
diff
changeset
|
3 import base64 |
|
41827
eb45f85c4c79
Make test_base64 pass.
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
4 import binascii |
|
75363
707586c70195
Closes #14158: improved resilience to test files left behind.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents:
68257
diff
changeset
|
5 import os |
|
61916
4c2d6e1b890e
Issue #4769: Fix main() function of the base64 module, use sys.stdin.buffer and
Victor Stinner <victor.stinner@haypocalc.com>
parents:
55593
diff
changeset
|
6 import sys |
|
4c2d6e1b890e
Issue #4769: Fix main() function of the base64 module, use sys.stdin.buffer and
Victor Stinner <victor.stinner@haypocalc.com>
parents:
55593
diff
changeset
|
7 import subprocess |
|
24954
05da95bcd724
Made it more readable.
Guido van Rossum <guido@python.org>
parents:
24851
diff
changeset
|
8 |
|
23472
be0bc55ecf4a
Added Mitchell Surface's regression tests for base64. Closes patch #550002.
Raymond Hettinger <python@rcn.com>
parents:
diff
changeset
|
9 |
|
66340
2beb25369289
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
61918
diff
changeset
|
10 |
|
31327
8c7090908cec
More complete code coverage, including testing the new RFC 3548 support.
Barry Warsaw <barry@python.org>
parents:
28917
diff
changeset
|
11 class LegacyBase64TestCase(unittest.TestCase): |
|
54564
18d823e8b602
#3613: add base64.encodebytes and decodebytes as the new spelling of encodestring and decodestring; deprecate the latter.
Georg Brandl <georg@python.org>
parents:
47201
diff
changeset
|
12 def test_encodebytes(self): |
|
31327
8c7090908cec
More complete code coverage, including testing the new RFC 3548 support.
Barry Warsaw <barry@python.org>
parents:
28917
diff
changeset
|
13 eq = self.assertEqual |
|
54564
18d823e8b602
#3613: add base64.encodebytes and decodebytes as the new spelling of encodestring and decodestring; deprecate the latter.
Georg Brandl <georg@python.org>
parents:
47201
diff
changeset
|
14 eq(base64.encodebytes(b"www.python.org"), b"d3d3LnB5dGhvbi5vcmc=\n") |
|
18d823e8b602
#3613: add base64.encodebytes and decodebytes as the new spelling of encodestring and decodestring; deprecate the latter.
Georg Brandl <georg@python.org>
parents:
47201
diff
changeset
|
15 eq(base64.encodebytes(b"a"), b"YQ==\n") |
|
18d823e8b602
#3613: add base64.encodebytes and decodebytes as the new spelling of encodestring and decodestring; deprecate the latter.
Georg Brandl <georg@python.org>
parents:
47201
diff
changeset
|
16 eq(base64.encodebytes(b"ab"), b"YWI=\n") |
|
18d823e8b602
#3613: add base64.encodebytes and decodebytes as the new spelling of encodestring and decodestring; deprecate the latter.
Georg Brandl <georg@python.org>
parents:
47201
diff
changeset
|
17 eq(base64.encodebytes(b"abc"), b"YWJj\n") |
|
18d823e8b602
#3613: add base64.encodebytes and decodebytes as the new spelling of encodestring and decodestring; deprecate the latter.
Georg Brandl <georg@python.org>
parents:
47201
diff
changeset
|
18 eq(base64.encodebytes(b""), b"") |
|
18d823e8b602
#3613: add base64.encodebytes and decodebytes as the new spelling of encodestring and decodestring; deprecate the latter.
Georg Brandl <georg@python.org>
parents:
47201
diff
changeset
|
19 eq(base64.encodebytes(b"abcdefghijklmnopqrstuvwxyz" |
|
41827
eb45f85c4c79
Make test_base64 pass.
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
20 b"ABCDEFGHIJKLMNOPQRSTUVWXYZ" |
|
eb45f85c4c79
Make test_base64 pass.
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
21 b"0123456789!@#0^&*();:<>,. []{}"), |
|
eb45f85c4c79
Make test_base64 pass.
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
22 b"YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXpBQkNE" |
|
eb45f85c4c79
Make test_base64 pass.
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
23 b"RUZHSElKS0xNTk9QUVJTVFVWV1hZWjAxMjM0\nNT" |
|
eb45f85c4c79
Make test_base64 pass.
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
24 b"Y3ODkhQCMwXiYqKCk7Ojw+LC4gW117fQ==\n") |
|
54564
18d823e8b602
#3613: add base64.encodebytes and decodebytes as the new spelling of encodestring and decodestring; deprecate the latter.
Georg Brandl <georg@python.org>
parents:
47201
diff
changeset
|
25 self.assertRaises(TypeError, base64.encodebytes, "") |
|
23472
be0bc55ecf4a
Added Mitchell Surface's regression tests for base64. Closes patch #550002.
Raymond Hettinger <python@rcn.com>
parents:
diff
changeset
|
26 |
|
54564
18d823e8b602
#3613: add base64.encodebytes and decodebytes as the new spelling of encodestring and decodestring; deprecate the latter.
Georg Brandl <georg@python.org>
parents:
47201
diff
changeset
|
27 def test_decodebytes(self): |
|
31327
8c7090908cec
More complete code coverage, including testing the new RFC 3548 support.
Barry Warsaw <barry@python.org>
parents:
28917
diff
changeset
|
28 eq = self.assertEqual |
|
54564
18d823e8b602
#3613: add base64.encodebytes and decodebytes as the new spelling of encodestring and decodestring; deprecate the latter.
Georg Brandl <georg@python.org>
parents:
47201
diff
changeset
|
29 eq(base64.decodebytes(b"d3d3LnB5dGhvbi5vcmc=\n"), b"www.python.org") |
|
18d823e8b602
#3613: add base64.encodebytes and decodebytes as the new spelling of encodestring and decodestring; deprecate the latter.
Georg Brandl <georg@python.org>
parents:
47201
diff
changeset
|
30 eq(base64.decodebytes(b"YQ==\n"), b"a") |
|
18d823e8b602
#3613: add base64.encodebytes and decodebytes as the new spelling of encodestring and decodestring; deprecate the latter.
Georg Brandl <georg@python.org>
parents:
47201
diff
changeset
|
31 eq(base64.decodebytes(b"YWI=\n"), b"ab") |
|
18d823e8b602
#3613: add base64.encodebytes and decodebytes as the new spelling of encodestring and decodestring; deprecate the latter.
Georg Brandl <georg@python.org>
parents:
47201
diff
changeset
|
32 eq(base64.decodebytes(b"YWJj\n"), b"abc") |
|
18d823e8b602
#3613: add base64.encodebytes and decodebytes as the new spelling of encodestring and decodestring; deprecate the latter.
Georg Brandl <georg@python.org>
parents:
47201
diff
changeset
|
33 eq(base64.decodebytes(b"YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXpBQkNE" |
|
41827
eb45f85c4c79
Make test_base64 pass.
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
34 b"RUZHSElKS0xNTk9QUVJTVFVWV1hZWjAxMjM0\nNT" |
|
eb45f85c4c79
Make test_base64 pass.
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
35 b"Y3ODkhQCMwXiYqKCk7Ojw+LC4gW117fQ==\n"), |
|
eb45f85c4c79
Make test_base64 pass.
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
36 b"abcdefghijklmnopqrstuvwxyz" |
|
eb45f85c4c79
Make test_base64 pass.
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
37 b"ABCDEFGHIJKLMNOPQRSTUVWXYZ" |
|
eb45f85c4c79
Make test_base64 pass.
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
38 b"0123456789!@#0^&*();:<>,. []{}") |
|
54564
18d823e8b602
#3613: add base64.encodebytes and decodebytes as the new spelling of encodestring and decodestring; deprecate the latter.
Georg Brandl <georg@python.org>
parents:
47201
diff
changeset
|
39 eq(base64.decodebytes(b''), b'') |
|
18d823e8b602
#3613: add base64.encodebytes and decodebytes as the new spelling of encodestring and decodestring; deprecate the latter.
Georg Brandl <georg@python.org>
parents:
47201
diff
changeset
|
40 self.assertRaises(TypeError, base64.decodebytes, "") |
|
31327
8c7090908cec
More complete code coverage, including testing the new RFC 3548 support.
Barry Warsaw <barry@python.org>
parents:
28917
diff
changeset
|
41 |
|
8c7090908cec
More complete code coverage, including testing the new RFC 3548 support.
Barry Warsaw <barry@python.org>
parents:
28917
diff
changeset
|
42 def test_encode(self): |
|
8c7090908cec
More complete code coverage, including testing the new RFC 3548 support.
Barry Warsaw <barry@python.org>
parents:
28917
diff
changeset
|
43 eq = self.assertEqual |
|
42501
f6069f9dd52d
SF patch# 1770008 by Christian Heimes (plus some extras).
Guido van Rossum <guido@python.org>
parents:
41827
diff
changeset
|
44 from io import BytesIO |
|
f6069f9dd52d
SF patch# 1770008 by Christian Heimes (plus some extras).
Guido van Rossum <guido@python.org>
parents:
41827
diff
changeset
|
45 infp = BytesIO(b'abcdefghijklmnopqrstuvwxyz' |
|
f6069f9dd52d
SF patch# 1770008 by Christian Heimes (plus some extras).
Guido van Rossum <guido@python.org>
parents:
41827
diff
changeset
|
46 b'ABCDEFGHIJKLMNOPQRSTUVWXYZ' |
|
f6069f9dd52d
SF patch# 1770008 by Christian Heimes (plus some extras).
Guido van Rossum <guido@python.org>
parents:
41827
diff
changeset
|
47 b'0123456789!@#0^&*();:<>,. []{}') |
|
f6069f9dd52d
SF patch# 1770008 by Christian Heimes (plus some extras).
Guido van Rossum <guido@python.org>
parents:
41827
diff
changeset
|
48 outfp = BytesIO() |
|
31327
8c7090908cec
More complete code coverage, including testing the new RFC 3548 support.
Barry Warsaw <barry@python.org>
parents:
28917
diff
changeset
|
49 base64.encode(infp, outfp) |
|
8c7090908cec
More complete code coverage, including testing the new RFC 3548 support.
Barry Warsaw <barry@python.org>
parents:
28917
diff
changeset
|
50 eq(outfp.getvalue(), |
|
42501
f6069f9dd52d
SF patch# 1770008 by Christian Heimes (plus some extras).
Guido van Rossum <guido@python.org>
parents:
41827
diff
changeset
|
51 b'YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXpBQkNE' |
|
f6069f9dd52d
SF patch# 1770008 by Christian Heimes (plus some extras).
Guido van Rossum <guido@python.org>
parents:
41827
diff
changeset
|
52 b'RUZHSElKS0xNTk9QUVJTVFVWV1hZWjAxMjM0\nNT' |
|
f6069f9dd52d
SF patch# 1770008 by Christian Heimes (plus some extras).
Guido van Rossum <guido@python.org>
parents:
41827
diff
changeset
|
53 b'Y3ODkhQCMwXiYqKCk7Ojw+LC4gW117fQ==\n') |
|
31327
8c7090908cec
More complete code coverage, including testing the new RFC 3548 support.
Barry Warsaw <barry@python.org>
parents:
28917
diff
changeset
|
54 |
|
8c7090908cec
More complete code coverage, including testing the new RFC 3548 support.
Barry Warsaw <barry@python.org>
parents:
28917
diff
changeset
|
55 def test_decode(self): |
|
42501
f6069f9dd52d
SF patch# 1770008 by Christian Heimes (plus some extras).
Guido van Rossum <guido@python.org>
parents:
41827
diff
changeset
|
56 from io import BytesIO |
|
f6069f9dd52d
SF patch# 1770008 by Christian Heimes (plus some extras).
Guido van Rossum <guido@python.org>
parents:
41827
diff
changeset
|
57 infp = BytesIO(b'd3d3LnB5dGhvbi5vcmc=') |
|
f6069f9dd52d
SF patch# 1770008 by Christian Heimes (plus some extras).
Guido van Rossum <guido@python.org>
parents:
41827
diff
changeset
|
58 outfp = BytesIO() |
|
31327
8c7090908cec
More complete code coverage, including testing the new RFC 3548 support.
Barry Warsaw <barry@python.org>
parents:
28917
diff
changeset
|
59 base64.decode(infp, outfp) |
|
42501
f6069f9dd52d
SF patch# 1770008 by Christian Heimes (plus some extras).
Guido van Rossum <guido@python.org>
parents:
41827
diff
changeset
|
60 self.assertEqual(outfp.getvalue(), b'www.python.org') |
|
31327
8c7090908cec
More complete code coverage, including testing the new RFC 3548 support.
Barry Warsaw <barry@python.org>
parents:
28917
diff
changeset
|
61 |
|
66340
2beb25369289
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
61918
diff
changeset
|
62 |
|
31327
8c7090908cec
More complete code coverage, including testing the new RFC 3548 support.
Barry Warsaw <barry@python.org>
parents:
28917
diff
changeset
|
63 class BaseXYTestCase(unittest.TestCase): |
|
8c7090908cec
More complete code coverage, including testing the new RFC 3548 support.
Barry Warsaw <barry@python.org>
parents:
28917
diff
changeset
|
64 def test_b64encode(self): |
|
8c7090908cec
More complete code coverage, including testing the new RFC 3548 support.
Barry Warsaw <barry@python.org>
parents:
28917
diff
changeset
|
65 eq = self.assertEqual |
|
8c7090908cec
More complete code coverage, including testing the new RFC 3548 support.
Barry Warsaw <barry@python.org>
parents:
28917
diff
changeset
|
66 # Test default alphabet |
|
41827
eb45f85c4c79
Make test_base64 pass.
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
67 eq(base64.b64encode(b"www.python.org"), b"d3d3LnB5dGhvbi5vcmc=") |
|
eb45f85c4c79
Make test_base64 pass.
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
68 eq(base64.b64encode(b'\x00'), b'AA==') |
|
eb45f85c4c79
Make test_base64 pass.
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
69 eq(base64.b64encode(b"a"), b"YQ==") |
|
eb45f85c4c79
Make test_base64 pass.
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
70 eq(base64.b64encode(b"ab"), b"YWI=") |
|
eb45f85c4c79
Make test_base64 pass.
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
71 eq(base64.b64encode(b"abc"), b"YWJj") |
|
eb45f85c4c79
Make test_base64 pass.
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
72 eq(base64.b64encode(b""), b"") |
|
eb45f85c4c79
Make test_base64 pass.
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
73 eq(base64.b64encode(b"abcdefghijklmnopqrstuvwxyz" |
|
eb45f85c4c79
Make test_base64 pass.
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
74 b"ABCDEFGHIJKLMNOPQRSTUVWXYZ" |
|
eb45f85c4c79
Make test_base64 pass.
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
75 b"0123456789!@#0^&*();:<>,. []{}"), |
|
eb45f85c4c79
Make test_base64 pass.
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
76 b"YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXpBQkNE" |
|
eb45f85c4c79
Make test_base64 pass.
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
77 b"RUZHSElKS0xNTk9QUVJTVFVWV1hZWjAxMjM0NT" |
|
eb45f85c4c79
Make test_base64 pass.
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
78 b"Y3ODkhQCMwXiYqKCk7Ojw+LC4gW117fQ==") |
|
31327
8c7090908cec
More complete code coverage, including testing the new RFC 3548 support.
Barry Warsaw <barry@python.org>
parents:
28917
diff
changeset
|
79 # Test with arbitrary alternative characters |
|
46638
0fdef14981a8
Removed implicit convertions of str object to bytes from base64.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
42501
diff
changeset
|
80 eq(base64.b64encode(b'\xd3V\xbeo\xf7\x1d', altchars=b'*$'), b'01a*b$cd') |
|
0fdef14981a8
Removed implicit convertions of str object to bytes from base64.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
42501
diff
changeset
|
81 # Check if passing a str object raises an error |
|
0fdef14981a8
Removed implicit convertions of str object to bytes from base64.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
42501
diff
changeset
|
82 self.assertRaises(TypeError, base64.b64encode, "") |
|
0fdef14981a8
Removed implicit convertions of str object to bytes from base64.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
42501
diff
changeset
|
83 self.assertRaises(TypeError, base64.b64encode, b"", altchars="") |
|
31327
8c7090908cec
More complete code coverage, including testing the new RFC 3548 support.
Barry Warsaw <barry@python.org>
parents:
28917
diff
changeset
|
84 # Test standard alphabet |
|
41827
eb45f85c4c79
Make test_base64 pass.
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
85 eq(base64.standard_b64encode(b"www.python.org"), b"d3d3LnB5dGhvbi5vcmc=") |
|
eb45f85c4c79
Make test_base64 pass.
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
86 eq(base64.standard_b64encode(b"a"), b"YQ==") |
|
eb45f85c4c79
Make test_base64 pass.
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
87 eq(base64.standard_b64encode(b"ab"), b"YWI=") |
|
eb45f85c4c79
Make test_base64 pass.
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
88 eq(base64.standard_b64encode(b"abc"), b"YWJj") |
|
eb45f85c4c79
Make test_base64 pass.
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
89 eq(base64.standard_b64encode(b""), b"") |
|
eb45f85c4c79
Make test_base64 pass.
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
90 eq(base64.standard_b64encode(b"abcdefghijklmnopqrstuvwxyz" |
|
eb45f85c4c79
Make test_base64 pass.
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
91 b"ABCDEFGHIJKLMNOPQRSTUVWXYZ" |
|
eb45f85c4c79
Make test_base64 pass.
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
92 b"0123456789!@#0^&*();:<>,. []{}"), |
|
eb45f85c4c79
Make test_base64 pass.
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
93 b"YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXpBQkNE" |
|
eb45f85c4c79
Make test_base64 pass.
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
94 b"RUZHSElKS0xNTk9QUVJTVFVWV1hZWjAxMjM0NT" |
|
eb45f85c4c79
Make test_base64 pass.
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
95 b"Y3ODkhQCMwXiYqKCk7Ojw+LC4gW117fQ==") |
|
46638
0fdef14981a8
Removed implicit convertions of str object to bytes from base64.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
42501
diff
changeset
|
96 # Check if passing a str object raises an error |
|
0fdef14981a8
Removed implicit convertions of str object to bytes from base64.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
42501
diff
changeset
|
97 self.assertRaises(TypeError, base64.standard_b64encode, "") |
|
0fdef14981a8
Removed implicit convertions of str object to bytes from base64.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
42501
diff
changeset
|
98 self.assertRaises(TypeError, base64.standard_b64encode, b"", altchars="") |
|
31327
8c7090908cec
More complete code coverage, including testing the new RFC 3548 support.
Barry Warsaw <barry@python.org>
parents:
28917
diff
changeset
|
99 # Test with 'URL safe' alternative characters |
|
41827
eb45f85c4c79
Make test_base64 pass.
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
100 eq(base64.urlsafe_b64encode(b'\xd3V\xbeo\xf7\x1d'), b'01a-b_cd') |
|
46638
0fdef14981a8
Removed implicit convertions of str object to bytes from base64.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
42501
diff
changeset
|
101 # Check if passing a str object raises an error |
|
0fdef14981a8
Removed implicit convertions of str object to bytes from base64.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
42501
diff
changeset
|
102 self.assertRaises(TypeError, base64.urlsafe_b64encode, "") |
|
31327
8c7090908cec
More complete code coverage, including testing the new RFC 3548 support.
Barry Warsaw <barry@python.org>
parents:
28917
diff
changeset
|
103 |
|
8c7090908cec
More complete code coverage, including testing the new RFC 3548 support.
Barry Warsaw <barry@python.org>
parents:
28917
diff
changeset
|
104 def test_b64decode(self): |
|
8c7090908cec
More complete code coverage, including testing the new RFC 3548 support.
Barry Warsaw <barry@python.org>
parents:
28917
diff
changeset
|
105 eq = self.assertEqual |
|
41827
eb45f85c4c79
Make test_base64 pass.
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
106 eq(base64.b64decode(b"d3d3LnB5dGhvbi5vcmc="), b"www.python.org") |
|
eb45f85c4c79
Make test_base64 pass.
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
107 eq(base64.b64decode(b'AA=='), b'\x00') |
|
eb45f85c4c79
Make test_base64 pass.
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
108 eq(base64.b64decode(b"YQ=="), b"a") |
|
eb45f85c4c79
Make test_base64 pass.
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
109 eq(base64.b64decode(b"YWI="), b"ab") |
|
eb45f85c4c79
Make test_base64 pass.
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
110 eq(base64.b64decode(b"YWJj"), b"abc") |
|
eb45f85c4c79
Make test_base64 pass.
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
111 eq(base64.b64decode(b"YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXpBQkNE" |
|
eb45f85c4c79
Make test_base64 pass.
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
112 b"RUZHSElKS0xNTk9QUVJTVFVWV1hZWjAxMjM0\nNT" |
|
eb45f85c4c79
Make test_base64 pass.
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
113 b"Y3ODkhQCMwXiYqKCk7Ojw+LC4gW117fQ=="), |
|
eb45f85c4c79
Make test_base64 pass.
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
114 b"abcdefghijklmnopqrstuvwxyz" |
|
eb45f85c4c79
Make test_base64 pass.
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
115 b"ABCDEFGHIJKLMNOPQRSTUVWXYZ" |
|
eb45f85c4c79
Make test_base64 pass.
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
116 b"0123456789!@#0^&*();:<>,. []{}") |
|
eb45f85c4c79
Make test_base64 pass.
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
117 eq(base64.b64decode(b''), b'') |
|
31327
8c7090908cec
More complete code coverage, including testing the new RFC 3548 support.
Barry Warsaw <barry@python.org>
parents:
28917
diff
changeset
|
118 # Test with arbitrary alternative characters |
|
46638
0fdef14981a8
Removed implicit convertions of str object to bytes from base64.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
42501
diff
changeset
|
119 eq(base64.b64decode(b'01a*b$cd', altchars=b'*$'), b'\xd3V\xbeo\xf7\x1d') |
|
0fdef14981a8
Removed implicit convertions of str object to bytes from base64.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
42501
diff
changeset
|
120 # Check if passing a str object raises an error |
|
0fdef14981a8
Removed implicit convertions of str object to bytes from base64.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
42501
diff
changeset
|
121 self.assertRaises(TypeError, base64.b64decode, "") |
|
0fdef14981a8
Removed implicit convertions of str object to bytes from base64.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
42501
diff
changeset
|
122 self.assertRaises(TypeError, base64.b64decode, b"", altchars="") |
|
31327
8c7090908cec
More complete code coverage, including testing the new RFC 3548 support.
Barry Warsaw <barry@python.org>
parents:
28917
diff
changeset
|
123 # Test standard alphabet |
|
41827
eb45f85c4c79
Make test_base64 pass.
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
124 eq(base64.standard_b64decode(b"d3d3LnB5dGhvbi5vcmc="), b"www.python.org") |
|
eb45f85c4c79
Make test_base64 pass.
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
125 eq(base64.standard_b64decode(b"YQ=="), b"a") |
|
eb45f85c4c79
Make test_base64 pass.
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
126 eq(base64.standard_b64decode(b"YWI="), b"ab") |
|
eb45f85c4c79
Make test_base64 pass.
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
127 eq(base64.standard_b64decode(b"YWJj"), b"abc") |
|
eb45f85c4c79
Make test_base64 pass.
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
128 eq(base64.standard_b64decode(b""), b"") |
|
eb45f85c4c79
Make test_base64 pass.
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
129 eq(base64.standard_b64decode(b"YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXpBQkNE" |
|
eb45f85c4c79
Make test_base64 pass.
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
130 b"RUZHSElKS0xNTk9QUVJTVFVWV1hZWjAxMjM0NT" |
|
eb45f85c4c79
Make test_base64 pass.
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
131 b"Y3ODkhQCMwXiYqKCk7Ojw+LC4gW117fQ=="), |
|
eb45f85c4c79
Make test_base64 pass.
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
132 b"abcdefghijklmnopqrstuvwxyz" |
|
eb45f85c4c79
Make test_base64 pass.
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
133 b"ABCDEFGHIJKLMNOPQRSTUVWXYZ" |
|
eb45f85c4c79
Make test_base64 pass.
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
134 b"0123456789!@#0^&*();:<>,. []{}") |
|
46638
0fdef14981a8
Removed implicit convertions of str object to bytes from base64.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
42501
diff
changeset
|
135 # Check if passing a str object raises an error |
|
0fdef14981a8
Removed implicit convertions of str object to bytes from base64.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
42501
diff
changeset
|
136 self.assertRaises(TypeError, base64.standard_b64decode, "") |
|
0fdef14981a8
Removed implicit convertions of str object to bytes from base64.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
42501
diff
changeset
|
137 self.assertRaises(TypeError, base64.standard_b64decode, b"", altchars="") |
|
31327
8c7090908cec
More complete code coverage, including testing the new RFC 3548 support.
Barry Warsaw <barry@python.org>
parents:
28917
diff
changeset
|
138 # Test with 'URL safe' alternative characters |
|
41827
eb45f85c4c79
Make test_base64 pass.
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
139 eq(base64.urlsafe_b64decode(b'01a-b_cd'), b'\xd3V\xbeo\xf7\x1d') |
|
46638
0fdef14981a8
Removed implicit convertions of str object to bytes from base64.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
42501
diff
changeset
|
140 self.assertRaises(TypeError, base64.urlsafe_b64decode, "") |
|
31327
8c7090908cec
More complete code coverage, including testing the new RFC 3548 support.
Barry Warsaw <barry@python.org>
parents:
28917
diff
changeset
|
141 |
|
66152
857d9fe60169
#1466065: add validate option to base64.b64decode
R. David Murray <rdmurray@bitdance.com>
parents:
61918
diff
changeset
|
142 def test_b64decode_padding_error(self): |
|
41827
eb45f85c4c79
Make test_base64 pass.
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
143 self.assertRaises(binascii.Error, base64.b64decode, b'abc') |
|
31327
8c7090908cec
More complete code coverage, including testing the new RFC 3548 support.
Barry Warsaw <barry@python.org>
parents:
28917
diff
changeset
|
144 |
|
66152
857d9fe60169
#1466065: add validate option to base64.b64decode
R. David Murray <rdmurray@bitdance.com>
parents:
61918
diff
changeset
|
145 def test_b64decode_invalid_chars(self): |
|
857d9fe60169
#1466065: add validate option to base64.b64decode
R. David Murray <rdmurray@bitdance.com>
parents:
61918
diff
changeset
|
146 # issue 1466065: Test some invalid characters. |
|
857d9fe60169
#1466065: add validate option to base64.b64decode
R. David Murray <rdmurray@bitdance.com>
parents:
61918
diff
changeset
|
147 tests = ((b'%3d==', b'\xdd'), |
|
857d9fe60169
#1466065: add validate option to base64.b64decode
R. David Murray <rdmurray@bitdance.com>
parents:
61918
diff
changeset
|
148 (b'$3d==', b'\xdd'), |
|
857d9fe60169
#1466065: add validate option to base64.b64decode
R. David Murray <rdmurray@bitdance.com>
parents:
61918
diff
changeset
|
149 (b'[==', b''), |
|
857d9fe60169
#1466065: add validate option to base64.b64decode
R. David Murray <rdmurray@bitdance.com>
parents:
61918
diff
changeset
|
150 (b'YW]3=', b'am'), |
|
857d9fe60169
#1466065: add validate option to base64.b64decode
R. David Murray <rdmurray@bitdance.com>
parents:
61918
diff
changeset
|
151 (b'3{d==', b'\xdd'), |
|
857d9fe60169
#1466065: add validate option to base64.b64decode
R. David Murray <rdmurray@bitdance.com>
parents:
61918
diff
changeset
|
152 (b'3d}==', b'\xdd'), |
|
857d9fe60169
#1466065: add validate option to base64.b64decode
R. David Murray <rdmurray@bitdance.com>
parents:
61918
diff
changeset
|
153 (b'@@', b''), |
|
857d9fe60169
#1466065: add validate option to base64.b64decode
R. David Murray <rdmurray@bitdance.com>
parents:
61918
diff
changeset
|
154 (b'!', b''), |
|
857d9fe60169
#1466065: add validate option to base64.b64decode
R. David Murray <rdmurray@bitdance.com>
parents:
61918
diff
changeset
|
155 (b'YWJj\nYWI=', b'abcab')) |
|
857d9fe60169
#1466065: add validate option to base64.b64decode
R. David Murray <rdmurray@bitdance.com>
parents:
61918
diff
changeset
|
156 for bstr, res in tests: |
|
66310
9fe76c26ea9f
#9424: Replace deprecated assert* methods in the Python test suite.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
66152
diff
changeset
|
157 self.assertEqual(base64.b64decode(bstr), res) |
|
66152
857d9fe60169
#1466065: add validate option to base64.b64decode
R. David Murray <rdmurray@bitdance.com>
parents:
61918
diff
changeset
|
158 with self.assertRaises(binascii.Error): |
|
857d9fe60169
#1466065: add validate option to base64.b64decode
R. David Murray <rdmurray@bitdance.com>
parents:
61918
diff
changeset
|
159 base64.b64decode(bstr, validate=True) |
|
857d9fe60169
#1466065: add validate option to base64.b64decode
R. David Murray <rdmurray@bitdance.com>
parents:
61918
diff
changeset
|
160 |
|
31327
8c7090908cec
More complete code coverage, including testing the new RFC 3548 support.
Barry Warsaw <barry@python.org>
parents:
28917
diff
changeset
|
161 def test_b32encode(self): |
|
8c7090908cec
More complete code coverage, including testing the new RFC 3548 support.
Barry Warsaw <barry@python.org>
parents:
28917
diff
changeset
|
162 eq = self.assertEqual |
|
41827
eb45f85c4c79
Make test_base64 pass.
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
163 eq(base64.b32encode(b''), b'') |
|
eb45f85c4c79
Make test_base64 pass.
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
164 eq(base64.b32encode(b'\x00'), b'AA======') |
|
eb45f85c4c79
Make test_base64 pass.
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
165 eq(base64.b32encode(b'a'), b'ME======') |
|
eb45f85c4c79
Make test_base64 pass.
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
166 eq(base64.b32encode(b'ab'), b'MFRA====') |
|
eb45f85c4c79
Make test_base64 pass.
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
167 eq(base64.b32encode(b'abc'), b'MFRGG===') |
|
eb45f85c4c79
Make test_base64 pass.
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
168 eq(base64.b32encode(b'abcd'), b'MFRGGZA=') |
|
eb45f85c4c79
Make test_base64 pass.
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
169 eq(base64.b32encode(b'abcde'), b'MFRGGZDF') |
|
46638
0fdef14981a8
Removed implicit convertions of str object to bytes from base64.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
42501
diff
changeset
|
170 self.assertRaises(TypeError, base64.b32encode, "") |
|
31327
8c7090908cec
More complete code coverage, including testing the new RFC 3548 support.
Barry Warsaw <barry@python.org>
parents:
28917
diff
changeset
|
171 |
|
8c7090908cec
More complete code coverage, including testing the new RFC 3548 support.
Barry Warsaw <barry@python.org>
parents:
28917
diff
changeset
|
172 def test_b32decode(self): |
|
8c7090908cec
More complete code coverage, including testing the new RFC 3548 support.
Barry Warsaw <barry@python.org>
parents:
28917
diff
changeset
|
173 eq = self.assertEqual |
|
41827
eb45f85c4c79
Make test_base64 pass.
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
174 eq(base64.b32decode(b''), b'') |
|
eb45f85c4c79
Make test_base64 pass.
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
175 eq(base64.b32decode(b'AA======'), b'\x00') |
|
eb45f85c4c79
Make test_base64 pass.
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
176 eq(base64.b32decode(b'ME======'), b'a') |
|
eb45f85c4c79
Make test_base64 pass.
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
177 eq(base64.b32decode(b'MFRA===='), b'ab') |
|
eb45f85c4c79
Make test_base64 pass.
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
178 eq(base64.b32decode(b'MFRGG==='), b'abc') |
|
eb45f85c4c79
Make test_base64 pass.
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
179 eq(base64.b32decode(b'MFRGGZA='), b'abcd') |
|
eb45f85c4c79
Make test_base64 pass.
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
180 eq(base64.b32decode(b'MFRGGZDF'), b'abcde') |
|
46638
0fdef14981a8
Removed implicit convertions of str object to bytes from base64.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
42501
diff
changeset
|
181 self.assertRaises(TypeError, base64.b32decode, "") |
|
31327
8c7090908cec
More complete code coverage, including testing the new RFC 3548 support.
Barry Warsaw <barry@python.org>
parents:
28917
diff
changeset
|
182 |
|
8c7090908cec
More complete code coverage, including testing the new RFC 3548 support.
Barry Warsaw <barry@python.org>
parents:
28917
diff
changeset
|
183 def test_b32decode_casefold(self): |
|
8c7090908cec
More complete code coverage, including testing the new RFC 3548 support.
Barry Warsaw <barry@python.org>
parents:
28917
diff
changeset
|
184 eq = self.assertEqual |
|
41827
eb45f85c4c79
Make test_base64 pass.
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
185 eq(base64.b32decode(b'', True), b'') |
|
eb45f85c4c79
Make test_base64 pass.
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
186 eq(base64.b32decode(b'ME======', True), b'a') |
|
eb45f85c4c79
Make test_base64 pass.
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
187 eq(base64.b32decode(b'MFRA====', True), b'ab') |
|
eb45f85c4c79
Make test_base64 pass.
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
188 eq(base64.b32decode(b'MFRGG===', True), b'abc') |
|
eb45f85c4c79
Make test_base64 pass.
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
189 eq(base64.b32decode(b'MFRGGZA=', True), b'abcd') |
|
eb45f85c4c79
Make test_base64 pass.
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
190 eq(base64.b32decode(b'MFRGGZDF', True), b'abcde') |
|
31327
8c7090908cec
More complete code coverage, including testing the new RFC 3548 support.
Barry Warsaw <barry@python.org>
parents:
28917
diff
changeset
|
191 # Lower cases |
|
41827
eb45f85c4c79
Make test_base64 pass.
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
192 eq(base64.b32decode(b'me======', True), b'a') |
|
eb45f85c4c79
Make test_base64 pass.
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
193 eq(base64.b32decode(b'mfra====', True), b'ab') |
|
eb45f85c4c79
Make test_base64 pass.
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
194 eq(base64.b32decode(b'mfrgg===', True), b'abc') |
|
eb45f85c4c79
Make test_base64 pass.
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
195 eq(base64.b32decode(b'mfrggza=', True), b'abcd') |
|
eb45f85c4c79
Make test_base64 pass.
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
196 eq(base64.b32decode(b'mfrggzdf', True), b'abcde') |
|
31327
8c7090908cec
More complete code coverage, including testing the new RFC 3548 support.
Barry Warsaw <barry@python.org>
parents:
28917
diff
changeset
|
197 # Expected exceptions |
|
41827
eb45f85c4c79
Make test_base64 pass.
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
198 self.assertRaises(TypeError, base64.b32decode, b'me======') |
|
31327
8c7090908cec
More complete code coverage, including testing the new RFC 3548 support.
Barry Warsaw <barry@python.org>
parents:
28917
diff
changeset
|
199 # Mapping zero and one |
|
41827
eb45f85c4c79
Make test_base64 pass.
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
200 eq(base64.b32decode(b'MLO23456'), b'b\xdd\xad\xf3\xbe') |
|
eb45f85c4c79
Make test_base64 pass.
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
201 eq(base64.b32decode(b'M1023456', map01=b'L'), b'b\xdd\xad\xf3\xbe') |
|
eb45f85c4c79
Make test_base64 pass.
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
202 eq(base64.b32decode(b'M1023456', map01=b'I'), b'b\x1d\xad\xf3\xbe') |
|
46638
0fdef14981a8
Removed implicit convertions of str object to bytes from base64.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
42501
diff
changeset
|
203 self.assertRaises(TypeError, base64.b32decode, b"", map01="") |
|
31327
8c7090908cec
More complete code coverage, including testing the new RFC 3548 support.
Barry Warsaw <barry@python.org>
parents:
28917
diff
changeset
|
204 |
|
8c7090908cec
More complete code coverage, including testing the new RFC 3548 support.
Barry Warsaw <barry@python.org>
parents:
28917
diff
changeset
|
205 def test_b32decode_error(self): |
|
41827
eb45f85c4c79
Make test_base64 pass.
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
206 self.assertRaises(binascii.Error, base64.b32decode, b'abc') |
|
eb45f85c4c79
Make test_base64 pass.
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
207 self.assertRaises(binascii.Error, base64.b32decode, b'ABCDEF==') |
|
31327
8c7090908cec
More complete code coverage, including testing the new RFC 3548 support.
Barry Warsaw <barry@python.org>
parents:
28917
diff
changeset
|
208 |
|
8c7090908cec
More complete code coverage, including testing the new RFC 3548 support.
Barry Warsaw <barry@python.org>
parents:
28917
diff
changeset
|
209 def test_b16encode(self): |
|
8c7090908cec
More complete code coverage, including testing the new RFC 3548 support.
Barry Warsaw <barry@python.org>
parents:
28917
diff
changeset
|
210 eq = self.assertEqual |
|
41827
eb45f85c4c79
Make test_base64 pass.
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
211 eq(base64.b16encode(b'\x01\x02\xab\xcd\xef'), b'0102ABCDEF') |
|
eb45f85c4c79
Make test_base64 pass.
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
212 eq(base64.b16encode(b'\x00'), b'00') |
|
46638
0fdef14981a8
Removed implicit convertions of str object to bytes from base64.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
42501
diff
changeset
|
213 self.assertRaises(TypeError, base64.b16encode, "") |
|
31327
8c7090908cec
More complete code coverage, including testing the new RFC 3548 support.
Barry Warsaw <barry@python.org>
parents:
28917
diff
changeset
|
214 |
|
8c7090908cec
More complete code coverage, including testing the new RFC 3548 support.
Barry Warsaw <barry@python.org>
parents:
28917
diff
changeset
|
215 def test_b16decode(self): |
|
8c7090908cec
More complete code coverage, including testing the new RFC 3548 support.
Barry Warsaw <barry@python.org>
parents:
28917
diff
changeset
|
216 eq = self.assertEqual |
|
41827
eb45f85c4c79
Make test_base64 pass.
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
217 eq(base64.b16decode(b'0102ABCDEF'), b'\x01\x02\xab\xcd\xef') |
|
eb45f85c4c79
Make test_base64 pass.
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
218 eq(base64.b16decode(b'00'), b'\x00') |
|
31327
8c7090908cec
More complete code coverage, including testing the new RFC 3548 support.
Barry Warsaw <barry@python.org>
parents:
28917
diff
changeset
|
219 # Lower case is not allowed without a flag |
|
41827
eb45f85c4c79
Make test_base64 pass.
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
220 self.assertRaises(binascii.Error, base64.b16decode, b'0102abcdef') |
|
31327
8c7090908cec
More complete code coverage, including testing the new RFC 3548 support.
Barry Warsaw <barry@python.org>
parents:
28917
diff
changeset
|
221 # Case fold |
|
41827
eb45f85c4c79
Make test_base64 pass.
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
222 eq(base64.b16decode(b'0102abcdef', True), b'\x01\x02\xab\xcd\xef') |
|
46638
0fdef14981a8
Removed implicit convertions of str object to bytes from base64.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
42501
diff
changeset
|
223 self.assertRaises(TypeError, base64.b16decode, "") |
|
41827
eb45f85c4c79
Make test_base64 pass.
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
224 |
|
eb45f85c4c79
Make test_base64 pass.
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
225 def test_ErrorHeritage(self): |
|
55593
0bb232078b8c
Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents:
54564
diff
changeset
|
226 self.assertTrue(issubclass(binascii.Error, ValueError)) |
|
31327
8c7090908cec
More complete code coverage, including testing the new RFC 3548 support.
Barry Warsaw <barry@python.org>
parents:
28917
diff
changeset
|
227 |
|
8c7090908cec
More complete code coverage, including testing the new RFC 3548 support.
Barry Warsaw <barry@python.org>
parents:
28917
diff
changeset
|
228 |
|
66340
2beb25369289
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
61918
diff
changeset
|
229 |
|
61916
4c2d6e1b890e
Issue #4769: Fix main() function of the base64 module, use sys.stdin.buffer and
Victor Stinner <victor.stinner@haypocalc.com>
parents:
55593
diff
changeset
|
230 class TestMain(unittest.TestCase): |
|
75363
707586c70195
Closes #14158: improved resilience to test files left behind.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents:
68257
diff
changeset
|
231 def tearDown(self): |
|
707586c70195
Closes #14158: improved resilience to test files left behind.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents:
68257
diff
changeset
|
232 if os.path.exists(support.TESTFN): |
|
707586c70195
Closes #14158: improved resilience to test files left behind.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents:
68257
diff
changeset
|
233 os.unlink(support.TESTFN) |
|
707586c70195
Closes #14158: improved resilience to test files left behind.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents:
68257
diff
changeset
|
234 |
|
61916
4c2d6e1b890e
Issue #4769: Fix main() function of the base64 module, use sys.stdin.buffer and
Victor Stinner <victor.stinner@haypocalc.com>
parents:
55593
diff
changeset
|
235 def get_output(self, *args, **options): |
|
4c2d6e1b890e
Issue #4769: Fix main() function of the base64 module, use sys.stdin.buffer and
Victor Stinner <victor.stinner@haypocalc.com>
parents:
55593
diff
changeset
|
236 args = (sys.executable, '-m', 'base64') + args |
|
4c2d6e1b890e
Issue #4769: Fix main() function of the base64 module, use sys.stdin.buffer and
Victor Stinner <victor.stinner@haypocalc.com>
parents:
55593
diff
changeset
|
237 return subprocess.check_output(args, **options) |
|
4c2d6e1b890e
Issue #4769: Fix main() function of the base64 module, use sys.stdin.buffer and
Victor Stinner <victor.stinner@haypocalc.com>
parents:
55593
diff
changeset
|
238 |
|
4c2d6e1b890e
Issue #4769: Fix main() function of the base64 module, use sys.stdin.buffer and
Victor Stinner <victor.stinner@haypocalc.com>
parents:
55593
diff
changeset
|
239 def test_encode_decode(self): |
|
4c2d6e1b890e
Issue #4769: Fix main() function of the base64 module, use sys.stdin.buffer and
Victor Stinner <victor.stinner@haypocalc.com>
parents:
55593
diff
changeset
|
240 output = self.get_output('-t') |
|
4c2d6e1b890e
Issue #4769: Fix main() function of the base64 module, use sys.stdin.buffer and
Victor Stinner <victor.stinner@haypocalc.com>
parents:
55593
diff
changeset
|
241 self.assertSequenceEqual(output.splitlines(), ( |
|
4c2d6e1b890e
Issue #4769: Fix main() function of the base64 module, use sys.stdin.buffer and
Victor Stinner <victor.stinner@haypocalc.com>
parents:
55593
diff
changeset
|
242 b"b'Aladdin:open sesame'", |
|
4c2d6e1b890e
Issue #4769: Fix main() function of the base64 module, use sys.stdin.buffer and
Victor Stinner <victor.stinner@haypocalc.com>
parents:
55593
diff
changeset
|
243 br"b'QWxhZGRpbjpvcGVuIHNlc2FtZQ==\n'", |
|
4c2d6e1b890e
Issue #4769: Fix main() function of the base64 module, use sys.stdin.buffer and
Victor Stinner <victor.stinner@haypocalc.com>
parents:
55593
diff
changeset
|
244 b"b'Aladdin:open sesame'", |
|
4c2d6e1b890e
Issue #4769: Fix main() function of the base64 module, use sys.stdin.buffer and
Victor Stinner <victor.stinner@haypocalc.com>
parents:
55593
diff
changeset
|
245 )) |
|
4c2d6e1b890e
Issue #4769: Fix main() function of the base64 module, use sys.stdin.buffer and
Victor Stinner <victor.stinner@haypocalc.com>
parents:
55593
diff
changeset
|
246 |
|
4c2d6e1b890e
Issue #4769: Fix main() function of the base64 module, use sys.stdin.buffer and
Victor Stinner <victor.stinner@haypocalc.com>
parents:
55593
diff
changeset
|
247 def test_encode_file(self): |
|
4c2d6e1b890e
Issue #4769: Fix main() function of the base64 module, use sys.stdin.buffer and
Victor Stinner <victor.stinner@haypocalc.com>
parents:
55593
diff
changeset
|
248 with open(support.TESTFN, 'wb') as fp: |
|
4c2d6e1b890e
Issue #4769: Fix main() function of the base64 module, use sys.stdin.buffer and
Victor Stinner <victor.stinner@haypocalc.com>
parents:
55593
diff
changeset
|
249 fp.write(b'a\xffb\n') |
|
4c2d6e1b890e
Issue #4769: Fix main() function of the base64 module, use sys.stdin.buffer and
Victor Stinner <victor.stinner@haypocalc.com>
parents:
55593
diff
changeset
|
250 |
|
4c2d6e1b890e
Issue #4769: Fix main() function of the base64 module, use sys.stdin.buffer and
Victor Stinner <victor.stinner@haypocalc.com>
parents:
55593
diff
changeset
|
251 output = self.get_output('-e', support.TESTFN) |
|
66340
2beb25369289
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
61918
diff
changeset
|
252 self.assertEqual(output.rstrip(), b'Yf9iCg==') |
|
61916
4c2d6e1b890e
Issue #4769: Fix main() function of the base64 module, use sys.stdin.buffer and
Victor Stinner <victor.stinner@haypocalc.com>
parents:
55593
diff
changeset
|
253 |
|
4c2d6e1b890e
Issue #4769: Fix main() function of the base64 module, use sys.stdin.buffer and
Victor Stinner <victor.stinner@haypocalc.com>
parents:
55593
diff
changeset
|
254 with open(support.TESTFN, 'rb') as fp: |
|
4c2d6e1b890e
Issue #4769: Fix main() function of the base64 module, use sys.stdin.buffer and
Victor Stinner <victor.stinner@haypocalc.com>
parents:
55593
diff
changeset
|
255 output = self.get_output('-e', stdin=fp) |
|
66340
2beb25369289
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
61918
diff
changeset
|
256 self.assertEqual(output.rstrip(), b'Yf9iCg==') |
|
61916
4c2d6e1b890e
Issue #4769: Fix main() function of the base64 module, use sys.stdin.buffer and
Victor Stinner <victor.stinner@haypocalc.com>
parents:
55593
diff
changeset
|
257 |
|
4c2d6e1b890e
Issue #4769: Fix main() function of the base64 module, use sys.stdin.buffer and
Victor Stinner <victor.stinner@haypocalc.com>
parents:
55593
diff
changeset
|
258 def test_decode(self): |
|
4c2d6e1b890e
Issue #4769: Fix main() function of the base64 module, use sys.stdin.buffer and
Victor Stinner <victor.stinner@haypocalc.com>
parents:
55593
diff
changeset
|
259 with open(support.TESTFN, 'wb') as fp: |
|
4c2d6e1b890e
Issue #4769: Fix main() function of the base64 module, use sys.stdin.buffer and
Victor Stinner <victor.stinner@haypocalc.com>
parents:
55593
diff
changeset
|
260 fp.write(b'Yf9iCg==') |
|
4c2d6e1b890e
Issue #4769: Fix main() function of the base64 module, use sys.stdin.buffer and
Victor Stinner <victor.stinner@haypocalc.com>
parents:
55593
diff
changeset
|
261 output = self.get_output('-d', support.TESTFN) |
|
66340
2beb25369289
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
61918
diff
changeset
|
262 self.assertEqual(output.rstrip(), b'a\xffb') |
|
61916
4c2d6e1b890e
Issue #4769: Fix main() function of the base64 module, use sys.stdin.buffer and
Victor Stinner <victor.stinner@haypocalc.com>
parents:
55593
diff
changeset
|
263 |
|
4c2d6e1b890e
Issue #4769: Fix main() function of the base64 module, use sys.stdin.buffer and
Victor Stinner <victor.stinner@haypocalc.com>
parents:
55593
diff
changeset
|
264 |
|
66340
2beb25369289
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
61918
diff
changeset
|
265 |
|
23472
be0bc55ecf4a
Added Mitchell Surface's regression tests for base64. Closes patch #550002.
Raymond Hettinger <python@rcn.com>
parents:
diff
changeset
|
266 def test_main(): |
|
47201
9c930a32cebb
#2621 rename test.test_support to test.support
Benjamin Peterson <benjamin@python.org>
parents:
46638
diff
changeset
|
267 support.run_unittest(__name__) |
|
23472
be0bc55ecf4a
Added Mitchell Surface's regression tests for base64. Closes patch #550002.
Raymond Hettinger <python@rcn.com>
parents:
diff
changeset
|
268 |
|
31327
8c7090908cec
More complete code coverage, including testing the new RFC 3548 support.
Barry Warsaw <barry@python.org>
parents:
28917
diff
changeset
|
269 if __name__ == '__main__': |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
35047
diff
changeset
|
270 test_main() |
