Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
017523c4
Kaydet (Commit)
017523c4
authored
Nis 28, 2013
tarafından
Serhiy Storchaka
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #17842. Added base64 module tests with bytearray arguments.
Original patch by Kushal Das.
üst
d160b122
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
1 deletion
+26
-1
test_base64.py
Lib/test/test_base64.py
+26
-1
No files found.
Lib/test/test_base64.py
Dosyayı görüntüle @
017523c4
...
@@ -22,6 +22,8 @@ class LegacyBase64TestCase(unittest.TestCase):
...
@@ -22,6 +22,8 @@ class LegacyBase64TestCase(unittest.TestCase):
b
"YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXpBQkNE"
b
"YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXpBQkNE"
b
"RUZHSElKS0xNTk9QUVJTVFVWV1hZWjAxMjM0
\n
NT"
b
"RUZHSElKS0xNTk9QUVJTVFVWV1hZWjAxMjM0
\n
NT"
b
"Y3ODkhQCMwXiYqKCk7Ojw+LC4gW117fQ==
\n
"
)
b
"Y3ODkhQCMwXiYqKCk7Ojw+LC4gW117fQ==
\n
"
)
# Non-bytes
eq
(
base64
.
encodebytes
(
bytearray
(
b
'abc'
)),
b
'YWJj
\n
'
)
self
.
assertRaises
(
TypeError
,
base64
.
encodebytes
,
""
)
self
.
assertRaises
(
TypeError
,
base64
.
encodebytes
,
""
)
def
test_decodebytes
(
self
):
def
test_decodebytes
(
self
):
...
@@ -37,6 +39,8 @@ class LegacyBase64TestCase(unittest.TestCase):
...
@@ -37,6 +39,8 @@ class LegacyBase64TestCase(unittest.TestCase):
b
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
b
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
b
"0123456789!@#0^&*();:<>,. []{}"
)
b
"0123456789!@#0^&*();:<>,. []{}"
)
eq
(
base64
.
decodebytes
(
b
''
),
b
''
)
eq
(
base64
.
decodebytes
(
b
''
),
b
''
)
# Non-bytes
eq
(
base64
.
decodebytes
(
bytearray
(
b
'YWJj
\n
'
)),
b
'abc'
)
self
.
assertRaises
(
TypeError
,
base64
.
decodebytes
,
""
)
self
.
assertRaises
(
TypeError
,
base64
.
decodebytes
,
""
)
def
test_encode
(
self
):
def
test_encode
(
self
):
...
@@ -78,6 +82,10 @@ class BaseXYTestCase(unittest.TestCase):
...
@@ -78,6 +82,10 @@ class BaseXYTestCase(unittest.TestCase):
b
"Y3ODkhQCMwXiYqKCk7Ojw+LC4gW117fQ=="
)
b
"Y3ODkhQCMwXiYqKCk7Ojw+LC4gW117fQ=="
)
# Test with arbitrary alternative characters
# Test with arbitrary alternative characters
eq
(
base64
.
b64encode
(
b
'
\xd3
V
\xbe
o
\xf7\x1d
'
,
altchars
=
b
'*$'
),
b
'01a*b$cd'
)
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
# Check if passing a str object raises an error
self
.
assertRaises
(
TypeError
,
base64
.
b64encode
,
""
)
self
.
assertRaises
(
TypeError
,
base64
.
b64encode
,
""
)
self
.
assertRaises
(
TypeError
,
base64
.
b64encode
,
b
""
,
altchars
=
""
)
self
.
assertRaises
(
TypeError
,
base64
.
b64encode
,
b
""
,
altchars
=
""
)
...
@@ -93,11 +101,14 @@ class BaseXYTestCase(unittest.TestCase):
...
@@ -93,11 +101,14 @@ class BaseXYTestCase(unittest.TestCase):
b
"YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXpBQkNE"
b
"YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXpBQkNE"
b
"RUZHSElKS0xNTk9QUVJTVFVWV1hZWjAxMjM0NT"
b
"RUZHSElKS0xNTk9QUVJTVFVWV1hZWjAxMjM0NT"
b
"Y3ODkhQCMwXiYqKCk7Ojw+LC4gW117fQ=="
)
b
"Y3ODkhQCMwXiYqKCk7Ojw+LC4gW117fQ=="
)
# Non-bytes
eq
(
base64
.
standard_b64encode
(
bytearray
(
b
'abcd'
)),
b
'YWJjZA=='
)
# Check if passing a str object raises an error
# Check if passing a str object raises an error
self
.
assertRaises
(
TypeError
,
base64
.
standard_b64encode
,
""
)
self
.
assertRaises
(
TypeError
,
base64
.
standard_b64encode
,
""
)
self
.
assertRaises
(
TypeError
,
base64
.
standard_b64encode
,
b
""
,
altchars
=
""
)
# Test with 'URL safe' alternative characters
# Test with 'URL safe' alternative characters
eq
(
base64
.
urlsafe_b64encode
(
b
'
\xd3
V
\xbe
o
\xf7\x1d
'
),
b
'01a-b_cd'
)
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
# Check if passing a str object raises an error
self
.
assertRaises
(
TypeError
,
base64
.
urlsafe_b64encode
,
""
)
self
.
assertRaises
(
TypeError
,
base64
.
urlsafe_b64encode
,
""
)
...
@@ -121,6 +132,8 @@ class BaseXYTestCase(unittest.TestCase):
...
@@ -121,6 +132,8 @@ class BaseXYTestCase(unittest.TestCase):
for
data
,
res
in
tests
.
items
():
for
data
,
res
in
tests
.
items
():
eq
(
base64
.
b64decode
(
data
),
res
)
eq
(
base64
.
b64decode
(
data
),
res
)
eq
(
base64
.
b64decode
(
data
.
decode
(
'ascii'
)),
res
)
eq
(
base64
.
b64decode
(
data
.
decode
(
'ascii'
)),
res
)
# Non-bytes
eq
(
base64
.
b64decode
(
bytearray
(
b
"YWJj"
)),
b
"abc"
)
# Test with arbitrary alternative characters
# Test with arbitrary alternative characters
tests_altchars
=
{(
b
'01a*b$cd'
,
b
'*$'
):
b
'
\xd3
V
\xbe
o
\xf7\x1d
'
,
tests_altchars
=
{(
b
'01a*b$cd'
,
b
'*$'
):
b
'
\xd3
V
\xbe
o
\xf7\x1d
'
,
...
@@ -138,6 +151,8 @@ class BaseXYTestCase(unittest.TestCase):
...
@@ -138,6 +151,8 @@ class BaseXYTestCase(unittest.TestCase):
for
data
,
res
in
tests
.
items
():
for
data
,
res
in
tests
.
items
():
eq
(
base64
.
standard_b64decode
(
data
),
res
)
eq
(
base64
.
standard_b64decode
(
data
),
res
)
eq
(
base64
.
standard_b64decode
(
data
.
decode
(
'ascii'
)),
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
# Test with 'URL safe' alternative characters
tests_urlsafe
=
{
b
'01a-b_cd'
:
b
'
\xd3
V
\xbe
o
\xf7\x1d
'
,
tests_urlsafe
=
{
b
'01a-b_cd'
:
b
'
\xd3
V
\xbe
o
\xf7\x1d
'
,
...
@@ -146,6 +161,8 @@ class BaseXYTestCase(unittest.TestCase):
...
@@ -146,6 +161,8 @@ class BaseXYTestCase(unittest.TestCase):
for
data
,
res
in
tests_urlsafe
.
items
():
for
data
,
res
in
tests_urlsafe
.
items
():
eq
(
base64
.
urlsafe_b64decode
(
data
),
res
)
eq
(
base64
.
urlsafe_b64decode
(
data
),
res
)
eq
(
base64
.
urlsafe_b64decode
(
data
.
decode
(
'ascii'
)),
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
):
def
test_b64decode_padding_error
(
self
):
self
.
assertRaises
(
binascii
.
Error
,
base64
.
b64decode
,
b
'abc'
)
self
.
assertRaises
(
binascii
.
Error
,
base64
.
b64decode
,
b
'abc'
)
...
@@ -179,6 +196,8 @@ class BaseXYTestCase(unittest.TestCase):
...
@@ -179,6 +196,8 @@ class BaseXYTestCase(unittest.TestCase):
eq
(
base64
.
b32encode
(
b
'abc'
),
b
'MFRGG==='
)
eq
(
base64
.
b32encode
(
b
'abc'
),
b
'MFRGG==='
)
eq
(
base64
.
b32encode
(
b
'abcd'
),
b
'MFRGGZA='
)
eq
(
base64
.
b32encode
(
b
'abcd'
),
b
'MFRGGZA='
)
eq
(
base64
.
b32encode
(
b
'abcde'
),
b
'MFRGGZDF'
)
eq
(
base64
.
b32encode
(
b
'abcde'
),
b
'MFRGGZDF'
)
# Non-bytes
eq
(
base64
.
b32encode
(
bytearray
(
b
'abcd'
)),
b
'MFRGGZA='
)
self
.
assertRaises
(
TypeError
,
base64
.
b32encode
,
""
)
self
.
assertRaises
(
TypeError
,
base64
.
b32encode
,
""
)
def
test_b32decode
(
self
):
def
test_b32decode
(
self
):
...
@@ -194,6 +213,8 @@ class BaseXYTestCase(unittest.TestCase):
...
@@ -194,6 +213,8 @@ class BaseXYTestCase(unittest.TestCase):
for
data
,
res
in
tests
.
items
():
for
data
,
res
in
tests
.
items
():
eq
(
base64
.
b32decode
(
data
),
res
)
eq
(
base64
.
b32decode
(
data
),
res
)
eq
(
base64
.
b32decode
(
data
.
decode
(
'ascii'
)),
res
)
eq
(
base64
.
b32decode
(
data
.
decode
(
'ascii'
)),
res
)
# Non-bytes
eq
(
base64
.
b32decode
(
bytearray
(
b
'MFRGG==='
)),
b
'abc'
)
def
test_b32decode_casefold
(
self
):
def
test_b32decode_casefold
(
self
):
eq
=
self
.
assertEqual
eq
=
self
.
assertEqual
...
@@ -245,6 +266,8 @@ class BaseXYTestCase(unittest.TestCase):
...
@@ -245,6 +266,8 @@ class BaseXYTestCase(unittest.TestCase):
eq
=
self
.
assertEqual
eq
=
self
.
assertEqual
eq
(
base64
.
b16encode
(
b
'
\x01\x02\xab\xcd\xef
'
),
b
'0102ABCDEF'
)
eq
(
base64
.
b16encode
(
b
'
\x01\x02\xab\xcd\xef
'
),
b
'0102ABCDEF'
)
eq
(
base64
.
b16encode
(
b
'
\x00
'
),
b
'00'
)
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
,
""
)
self
.
assertRaises
(
TypeError
,
base64
.
b16encode
,
""
)
def
test_b16decode
(
self
):
def
test_b16decode
(
self
):
...
@@ -259,6 +282,8 @@ class BaseXYTestCase(unittest.TestCase):
...
@@ -259,6 +282,8 @@ class BaseXYTestCase(unittest.TestCase):
# Case fold
# Case fold
eq
(
base64
.
b16decode
(
b
'0102abcdef'
,
True
),
b
'
\x01\x02\xab\xcd\xef
'
)
eq
(
base64
.
b16decode
(
b
'0102abcdef'
,
True
),
b
'
\x01\x02\xab\xcd\xef
'
)
eq
(
base64
.
b16decode
(
'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
):
def
test_decode_nonascii_str
(
self
):
decode_funcs
=
(
base64
.
b64decode
,
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