Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
1cda4535
Commit
1cda4535
authored
Apr 28, 2013
by
Serhiy Storchaka
Browse files
Options
Browse Files
Download
Plain Diff
Issue #17842. Added base64 module tests with bytearray arguments.
Original patch by Kushal Das.
parents
5f99fa72
017523c4
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
1 deletion
+26
-1
Lib/test/test_base64.py
Lib/test/test_base64.py
+26
-1
No files found.
Lib/test/test_base64.py
View file @
1cda4535
...
...
@@ -22,6 +22,8 @@ class LegacyBase64TestCase(unittest.TestCase):
b"YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXpBQkNE"
b"RUZHSElKS0xNTk9QUVJTVFVWV1hZWjAxMjM0
\
n
NT"
b"Y3ODkhQCMwXiYqKCk7Ojw+LC4gW117fQ==
\
n
"
)
# Non-bytes
eq
(
base64
.
encodebytes
(
bytearray
(
b'abc'
)),
b'YWJj
\
n
'
)
self
.
assertRaises
(
TypeError
,
base64
.
encodebytes
,
""
)
def
test_decodebytes
(
self
):
...
...
@@ -37,6 +39,8 @@ class LegacyBase64TestCase(unittest.TestCase):
b"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
b"0123456789!@#0^&*();:<>,. []{}"
)
eq
(
base64
.
decodebytes
(
b''
),
b''
)
# Non-bytes
eq
(
base64
.
decodebytes
(
bytearray
(
b'YWJj
\
n
'
)),
b'abc'
)
self
.
assertRaises
(
TypeError
,
base64
.
decodebytes
,
""
)
def
test_encode
(
self
):
...
...
@@ -78,6 +82,10 @@ class BaseXYTestCase(unittest.TestCase):
b"Y3ODkhQCMwXiYqKCk7Ojw+LC4gW117fQ=="
)
# Test with arbitrary alternative characters
eq
(
base64
.
b64encode
(
b'
\
xd3
V
\
xbe
o
\
xf7
\
x1d
'
,
altchars
=
b'*$'
),
b'01a*b$cd'
)
# Non-bytes
eq
(
base64
.
b64encode
(
bytearray
(
b'abcd'
)),
b'YWJjZA=='
)
eq
(
base64
.
b64encode
(
b'
\
xd3
V
\
xbe
o
\
xf7
\
x1d
'
,
altchars
=
bytearray
(
b'*$'
)),
b'01a*b$cd'
)
# Check if passing a str object raises an error
self
.
assertRaises
(
TypeError
,
base64
.
b64encode
,
""
)
self
.
assertRaises
(
TypeError
,
base64
.
b64encode
,
b""
,
altchars
=
""
)
...
...
@@ -93,11 +101,14 @@ class BaseXYTestCase(unittest.TestCase):
b"YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXpBQkNE"
b"RUZHSElKS0xNTk9QUVJTVFVWV1hZWjAxMjM0NT"
b"Y3ODkhQCMwXiYqKCk7Ojw+LC4gW117fQ=="
)
# Non-bytes
eq
(
base64
.
standard_b64encode
(
bytearray
(
b'abcd'
)),
b'YWJjZA=='
)
# Check if passing a str object raises an error
self
.
assertRaises
(
TypeError
,
base64
.
standard_b64encode
,
""
)
self
.
assertRaises
(
TypeError
,
base64
.
standard_b64encode
,
b""
,
altchars
=
""
)
# Test with 'URL safe' alternative characters
eq
(
base64
.
urlsafe_b64encode
(
b'
\
xd3
V
\
xbe
o
\
xf7
\
x1d
'
),
b'01a-b_cd'
)
# Non-bytes
eq
(
base64
.
urlsafe_b64encode
(
bytearray
(
b'
\
xd3
V
\
xbe
o
\
xf7
\
x1d
'
)),
b'01a-b_cd'
)
# Check if passing a str object raises an error
self
.
assertRaises
(
TypeError
,
base64
.
urlsafe_b64encode
,
""
)
...
...
@@ -121,6 +132,8 @@ class BaseXYTestCase(unittest.TestCase):
for
data
,
res
in
tests
.
items
():
eq
(
base64
.
b64decode
(
data
),
res
)
eq
(
base64
.
b64decode
(
data
.
decode
(
'ascii'
)),
res
)
# Non-bytes
eq
(
base64
.
b64decode
(
bytearray
(
b"YWJj"
)),
b"abc"
)
# Test with arbitrary alternative characters
tests_altchars
=
{(
b'01a*b$cd'
,
b'*$'
):
b'
\
xd3
V
\
xbe
o
\
xf7
\
x1d
'
,
...
...
@@ -138,6 +151,8 @@ class BaseXYTestCase(unittest.TestCase):
for
data
,
res
in
tests
.
items
():
eq
(
base64
.
standard_b64decode
(
data
),
res
)
eq
(
base64
.
standard_b64decode
(
data
.
decode
(
'ascii'
)),
res
)
# Non-bytes
eq
(
base64
.
standard_b64decode
(
bytearray
(
b"YWJj"
)),
b"abc"
)
# Test with 'URL safe' alternative characters
tests_urlsafe
=
{
b'01a-b_cd'
:
b'
\
xd3
V
\
xbe
o
\
xf7
\
x1d
'
,
...
...
@@ -146,6 +161,8 @@ class BaseXYTestCase(unittest.TestCase):
for
data
,
res
in
tests_urlsafe
.
items
():
eq
(
base64
.
urlsafe_b64decode
(
data
),
res
)
eq
(
base64
.
urlsafe_b64decode
(
data
.
decode
(
'ascii'
)),
res
)
# Non-bytes
eq
(
base64
.
urlsafe_b64decode
(
bytearray
(
b'01a-b_cd'
)),
b'
\
xd3
V
\
xbe
o
\
xf7
\
x1d
'
)
def
test_b64decode_padding_error
(
self
):
self
.
assertRaises
(
binascii
.
Error
,
base64
.
b64decode
,
b'abc'
)
...
...
@@ -179,6 +196,8 @@ class BaseXYTestCase(unittest.TestCase):
eq
(
base64
.
b32encode
(
b'abc'
),
b'MFRGG==='
)
eq
(
base64
.
b32encode
(
b'abcd'
),
b'MFRGGZA='
)
eq
(
base64
.
b32encode
(
b'abcde'
),
b'MFRGGZDF'
)
# Non-bytes
eq
(
base64
.
b32encode
(
bytearray
(
b'abcd'
)),
b'MFRGGZA='
)
self
.
assertRaises
(
TypeError
,
base64
.
b32encode
,
""
)
def
test_b32decode
(
self
):
...
...
@@ -194,6 +213,8 @@ class BaseXYTestCase(unittest.TestCase):
for
data
,
res
in
tests
.
items
():
eq
(
base64
.
b32decode
(
data
),
res
)
eq
(
base64
.
b32decode
(
data
.
decode
(
'ascii'
)),
res
)
# Non-bytes
eq
(
base64
.
b32decode
(
bytearray
(
b'MFRGG==='
)),
b'abc'
)
def
test_b32decode_casefold
(
self
):
eq
=
self
.
assertEqual
...
...
@@ -245,6 +266,8 @@ class BaseXYTestCase(unittest.TestCase):
eq
=
self
.
assertEqual
eq
(
base64
.
b16encode
(
b'
\
x01
\
x02
\
xab
\
xcd
\
xef
'
),
b'0102ABCDEF'
)
eq
(
base64
.
b16encode
(
b'
\
x00
'
),
b'00'
)
# Non-bytes
eq
(
base64
.
b16encode
(
bytearray
(
b'
\
x01
\
x02
\
xab
\
xcd
\
xef
'
)),
b'0102ABCDEF'
)
self
.
assertRaises
(
TypeError
,
base64
.
b16encode
,
""
)
def
test_b16decode
(
self
):
...
...
@@ -259,6 +282,8 @@ class BaseXYTestCase(unittest.TestCase):
# Case fold
eq
(
base64
.
b16decode
(
b'0102abcdef'
,
True
),
b'
\
x01
\
x02
\
xab
\
xcd
\
xef
'
)
eq
(
base64
.
b16decode
(
'0102abcdef'
,
True
),
b'
\
x01
\
x02
\
xab
\
xcd
\
xef
'
)
# Non-bytes
eq
(
base64
.
b16decode
(
bytearray
(
b"0102ABCDEF"
)),
b'
\
x01
\
x02
\
xab
\
xcd
\
xef
'
)
def
test_decode_nonascii_str
(
self
):
decode_funcs
=
(
base64
.
b64decode
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment