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
8118df7b
Kaydet (Commit)
8118df7b
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.
üst
8493a04e
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
0 deletions
+26
-0
test_base64.py
Lib/test/test_base64.py
+26
-0
No files found.
Lib/test/test_base64.py
Dosyayı görüntüle @
8118df7b
...
@@ -18,6 +18,8 @@ class LegacyBase64TestCase(unittest.TestCase):
...
@@ -18,6 +18,8 @@ class LegacyBase64TestCase(unittest.TestCase):
"YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXpBQkNE"
"YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXpBQkNE"
"RUZHSElKS0xNTk9QUVJTVFVWV1hZWjAxMjM0
\n
NT"
"RUZHSElKS0xNTk9QUVJTVFVWV1hZWjAxMjM0
\n
NT"
"Y3ODkhQCMwXiYqKCk7Ojw+LC4gW117fQ==
\n
"
)
"Y3ODkhQCMwXiYqKCk7Ojw+LC4gW117fQ==
\n
"
)
# Non-bytes
eq
(
base64
.
encodestring
(
bytearray
(
'abc'
)),
'YWJj
\n
'
)
def
test_decodestring
(
self
):
def
test_decodestring
(
self
):
eq
=
self
.
assertEqual
eq
=
self
.
assertEqual
...
@@ -32,6 +34,8 @@ class LegacyBase64TestCase(unittest.TestCase):
...
@@ -32,6 +34,8 @@ class LegacyBase64TestCase(unittest.TestCase):
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"0123456789!@#0^&*();:<>,. []{}"
)
"0123456789!@#0^&*();:<>,. []{}"
)
eq
(
base64
.
decodestring
(
''
),
''
)
eq
(
base64
.
decodestring
(
''
),
''
)
# Non-bytes
eq
(
base64
.
decodestring
(
bytearray
(
"YWJj
\n
"
)),
"abc"
)
def
test_encode
(
self
):
def
test_encode
(
self
):
eq
=
self
.
assertEqual
eq
=
self
.
assertEqual
...
@@ -73,6 +77,10 @@ class BaseXYTestCase(unittest.TestCase):
...
@@ -73,6 +77,10 @@ class BaseXYTestCase(unittest.TestCase):
"Y3ODkhQCMwXiYqKCk7Ojw+LC4gW117fQ=="
)
"Y3ODkhQCMwXiYqKCk7Ojw+LC4gW117fQ=="
)
# Test with arbitrary alternative characters
# Test with arbitrary alternative characters
eq
(
base64
.
b64encode
(
'
\xd3
V
\xbe
o
\xf7\x1d
'
,
altchars
=
'*$'
),
'01a*b$cd'
)
eq
(
base64
.
b64encode
(
'
\xd3
V
\xbe
o
\xf7\x1d
'
,
altchars
=
'*$'
),
'01a*b$cd'
)
# Non-bytes
eq
(
base64
.
b64encode
(
bytearray
(
'abcd'
)),
'YWJjZA=='
)
self
.
assertRaises
(
TypeError
,
base64
.
b64encode
,
'
\xd3
V
\xbe
o
\xf7\x1d
'
,
altchars
=
bytearray
(
'*$'
))
# Test standard alphabet
# Test standard alphabet
eq
(
base64
.
standard_b64encode
(
"www.python.org"
),
"d3d3LnB5dGhvbi5vcmc="
)
eq
(
base64
.
standard_b64encode
(
"www.python.org"
),
"d3d3LnB5dGhvbi5vcmc="
)
eq
(
base64
.
standard_b64encode
(
"a"
),
"YQ=="
)
eq
(
base64
.
standard_b64encode
(
"a"
),
"YQ=="
)
...
@@ -85,8 +93,12 @@ class BaseXYTestCase(unittest.TestCase):
...
@@ -85,8 +93,12 @@ class BaseXYTestCase(unittest.TestCase):
"YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXpBQkNE"
"YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXpBQkNE"
"RUZHSElKS0xNTk9QUVJTVFVWV1hZWjAxMjM0NT"
"RUZHSElKS0xNTk9QUVJTVFVWV1hZWjAxMjM0NT"
"Y3ODkhQCMwXiYqKCk7Ojw+LC4gW117fQ=="
)
"Y3ODkhQCMwXiYqKCk7Ojw+LC4gW117fQ=="
)
# Non-bytes
eq
(
base64
.
standard_b64encode
(
bytearray
(
'abcd'
)),
'YWJjZA=='
)
# Test with 'URL safe' alternative characters
# Test with 'URL safe' alternative characters
eq
(
base64
.
urlsafe_b64encode
(
'
\xd3
V
\xbe
o
\xf7\x1d
'
),
'01a-b_cd'
)
eq
(
base64
.
urlsafe_b64encode
(
'
\xd3
V
\xbe
o
\xf7\x1d
'
),
'01a-b_cd'
)
# Non-bytes
eq
(
base64
.
urlsafe_b64encode
(
bytearray
(
'
\xd3
V
\xbe
o
\xf7\x1d
'
)),
'01a-b_cd'
)
def
test_b64decode
(
self
):
def
test_b64decode
(
self
):
eq
=
self
.
assertEqual
eq
=
self
.
assertEqual
...
@@ -104,6 +116,8 @@ class BaseXYTestCase(unittest.TestCase):
...
@@ -104,6 +116,8 @@ class BaseXYTestCase(unittest.TestCase):
eq
(
base64
.
b64decode
(
''
),
''
)
eq
(
base64
.
b64decode
(
''
),
''
)
# Test with arbitrary alternative characters
# Test with arbitrary alternative characters
eq
(
base64
.
b64decode
(
'01a*b$cd'
,
altchars
=
'*$'
),
'
\xd3
V
\xbe
o
\xf7\x1d
'
)
eq
(
base64
.
b64decode
(
'01a*b$cd'
,
altchars
=
'*$'
),
'
\xd3
V
\xbe
o
\xf7\x1d
'
)
# Non-bytes
eq
(
base64
.
b64decode
(
bytearray
(
"YWJj"
)),
"abc"
)
# Test standard alphabet
# Test standard alphabet
eq
(
base64
.
standard_b64decode
(
"d3d3LnB5dGhvbi5vcmc="
),
"www.python.org"
)
eq
(
base64
.
standard_b64decode
(
"d3d3LnB5dGhvbi5vcmc="
),
"www.python.org"
)
eq
(
base64
.
standard_b64decode
(
"YQ=="
),
"a"
)
eq
(
base64
.
standard_b64decode
(
"YQ=="
),
"a"
)
...
@@ -116,8 +130,12 @@ class BaseXYTestCase(unittest.TestCase):
...
@@ -116,8 +130,12 @@ class BaseXYTestCase(unittest.TestCase):
"abcdefghijklmnopqrstuvwxyz"
"abcdefghijklmnopqrstuvwxyz"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"0123456789!@#0^&*();:<>,. []{}"
)
"0123456789!@#0^&*();:<>,. []{}"
)
# Non-bytes
eq
(
base64
.
standard_b64decode
(
bytearray
(
"YWJj"
)),
"abc"
)
# Test with 'URL safe' alternative characters
# Test with 'URL safe' alternative characters
eq
(
base64
.
urlsafe_b64decode
(
'01a-b_cd'
),
'
\xd3
V
\xbe
o
\xf7\x1d
'
)
eq
(
base64
.
urlsafe_b64decode
(
'01a-b_cd'
),
'
\xd3
V
\xbe
o
\xf7\x1d
'
)
# Non-bytes
eq
(
base64
.
urlsafe_b64decode
(
bytearray
(
'01a-b_cd'
)),
'
\xd3
V
\xbe
o
\xf7\x1d
'
)
def
test_b64decode_error
(
self
):
def
test_b64decode_error
(
self
):
self
.
assertRaises
(
TypeError
,
base64
.
b64decode
,
'abc'
)
self
.
assertRaises
(
TypeError
,
base64
.
b64decode
,
'abc'
)
...
@@ -131,6 +149,8 @@ class BaseXYTestCase(unittest.TestCase):
...
@@ -131,6 +149,8 @@ class BaseXYTestCase(unittest.TestCase):
eq
(
base64
.
b32encode
(
'abc'
),
'MFRGG==='
)
eq
(
base64
.
b32encode
(
'abc'
),
'MFRGG==='
)
eq
(
base64
.
b32encode
(
'abcd'
),
'MFRGGZA='
)
eq
(
base64
.
b32encode
(
'abcd'
),
'MFRGGZA='
)
eq
(
base64
.
b32encode
(
'abcde'
),
'MFRGGZDF'
)
eq
(
base64
.
b32encode
(
'abcde'
),
'MFRGGZDF'
)
# Non-bytes
eq
(
base64
.
b32encode
(
bytearray
(
'abcd'
)),
'MFRGGZA='
)
def
test_b32decode
(
self
):
def
test_b32decode
(
self
):
eq
=
self
.
assertEqual
eq
=
self
.
assertEqual
...
@@ -141,6 +161,8 @@ class BaseXYTestCase(unittest.TestCase):
...
@@ -141,6 +161,8 @@ class BaseXYTestCase(unittest.TestCase):
eq
(
base64
.
b32decode
(
'MFRGG==='
),
'abc'
)
eq
(
base64
.
b32decode
(
'MFRGG==='
),
'abc'
)
eq
(
base64
.
b32decode
(
'MFRGGZA='
),
'abcd'
)
eq
(
base64
.
b32decode
(
'MFRGGZA='
),
'abcd'
)
eq
(
base64
.
b32decode
(
'MFRGGZDF'
),
'abcde'
)
eq
(
base64
.
b32decode
(
'MFRGGZDF'
),
'abcde'
)
# Non-bytes
self
.
assertRaises
(
TypeError
,
base64
.
b32decode
,
bytearray
(
'MFRGG==='
))
def
test_b32decode_casefold
(
self
):
def
test_b32decode_casefold
(
self
):
eq
=
self
.
assertEqual
eq
=
self
.
assertEqual
...
@@ -171,6 +193,8 @@ class BaseXYTestCase(unittest.TestCase):
...
@@ -171,6 +193,8 @@ class BaseXYTestCase(unittest.TestCase):
eq
=
self
.
assertEqual
eq
=
self
.
assertEqual
eq
(
base64
.
b16encode
(
'
\x01\x02\xab\xcd\xef
'
),
'0102ABCDEF'
)
eq
(
base64
.
b16encode
(
'
\x01\x02\xab\xcd\xef
'
),
'0102ABCDEF'
)
eq
(
base64
.
b16encode
(
'
\x00
'
),
'00'
)
eq
(
base64
.
b16encode
(
'
\x00
'
),
'00'
)
# Non-bytes
eq
(
base64
.
b16encode
(
bytearray
(
'
\x01\x02\xab\xcd\xef
'
)),
'0102ABCDEF'
)
def
test_b16decode
(
self
):
def
test_b16decode
(
self
):
eq
=
self
.
assertEqual
eq
=
self
.
assertEqual
...
@@ -180,6 +204,8 @@ class BaseXYTestCase(unittest.TestCase):
...
@@ -180,6 +204,8 @@ class BaseXYTestCase(unittest.TestCase):
self
.
assertRaises
(
TypeError
,
base64
.
b16decode
,
'0102abcdef'
)
self
.
assertRaises
(
TypeError
,
base64
.
b16decode
,
'0102abcdef'
)
# Case fold
# Case fold
eq
(
base64
.
b16decode
(
'0102abcdef'
,
True
),
'
\x01\x02\xab\xcd\xef
'
)
eq
(
base64
.
b16decode
(
'0102abcdef'
,
True
),
'
\x01\x02\xab\xcd\xef
'
)
# Non-bytes
eq
(
base64
.
b16decode
(
bytearray
(
"0102ABCDEF"
)),
'
\x01\x02\xab\xcd\xef
'
)
...
...
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