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
fdecda01
Kaydet (Commit)
fdecda01
authored
Eki 19, 1999
tarafından
Guido van Rossum
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Rewritten -- this now tests the binascii *except* for the binhex
module, which is tested by test_binhex.py.
üst
a0e85b24
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
85 additions
and
44 deletions
+85
-44
test_binascii.py
Lib/test/test_binascii.py
+85
-44
No files found.
Lib/test/test_binascii.py
Dosyayı görüntüle @
fdecda01
#! /usr/bin/env python
"""Test the binascii C module."""
"""Test script for the binascii C module
Uses the mechanism of the python binhex module
Roger E. Masse
"""
import
binhex
import
tempfile
from
test_support
import
verbose
from
test_support
import
verbose
import
binascii
# Show module doc string
print
binascii
.
__doc__
# Show module exceptions
print
binascii
.
Error
print
binascii
.
Incomplete
# Check presence and display doc strings of all functions
funcs
=
[]
for
suffix
in
"base64"
,
"hqx"
,
"uu"
:
prefixes
=
[
"a2b_"
,
"b2a_"
]
if
suffix
==
"hqx"
:
prefixes
.
extend
([
"crc_"
,
"rlecode_"
,
"rledecode_"
])
for
prefix
in
prefixes
:
name
=
prefix
+
suffix
funcs
.
append
(
getattr
(
binascii
,
name
))
for
func
in
funcs
:
print
"
%-15
s:
%
s"
%
(
func
.
__name__
,
func
.
__doc__
)
# Create binary test data
testdata
=
"The quick brown fox jumps over the lazy dog.
\r\n
"
for
i
in
range
(
256
):
# Be slow so we don't depend on other modules
testdata
=
testdata
+
chr
(
i
)
testdata
=
testdata
+
"
\r\n
Hello world.
\n
"
# Test base64 with valid data
print
"base64 test"
MAX_BASE64
=
57
lines
=
[]
for
i
in
range
(
0
,
len
(
testdata
),
MAX_BASE64
):
b
=
testdata
[
i
:
i
+
MAX_BASE64
]
a
=
binascii
.
b2a_base64
(
b
)
lines
.
append
(
a
)
print
a
,
res
=
""
for
line
in
lines
:
b
=
binascii
.
a2b_base64
(
line
)
res
=
res
+
b
assert
res
==
testdata
# Test base64 with random invalid characters sprinkled throughout
# (This requires a new version of binascii.)
fillers
=
""
valid
=
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/"
for
i
in
range
(
256
):
c
=
chr
(
i
)
if
c
not
in
valid
:
fillers
=
fillers
+
c
def
addnoise
(
line
):
noise
=
fillers
ratio
=
len
(
line
)
/
len
(
noise
)
res
=
""
while
line
and
noise
:
if
len
(
line
)
/
len
(
noise
)
>
ratio
:
c
,
line
=
line
[
0
],
line
[
1
:]
else
:
c
,
noise
=
noise
[
0
],
noise
[
1
:]
res
=
res
+
c
return
res
+
noise
+
line
res
=
""
for
line
in
map
(
addnoise
,
lines
):
b
=
binascii
.
a2b_base64
(
line
)
res
=
res
+
b
assert
res
==
testdata
# Test uu
print
"uu test"
MAX_UU
=
45
lines
=
[]
for
i
in
range
(
0
,
len
(
testdata
),
MAX_UU
):
b
=
testdata
[
i
:
i
+
MAX_UU
]
a
=
binascii
.
b2a_uu
(
b
)
lines
.
append
(
a
)
print
a
,
res
=
""
for
line
in
lines
:
b
=
binascii
.
a2b_uu
(
line
)
res
=
res
+
b
assert
res
==
testdata
def
test
():
# The hqx test is in test_binhex.py
try
:
fname1
=
tempfile
.
mktemp
()
fname2
=
tempfile
.
mktemp
()
f
=
open
(
fname1
,
'w'
)
except
:
raise
ImportError
,
"Cannot test binascii without a temp file"
start
=
'Jack is my hero'
f
.
write
(
start
)
f
.
close
()
binhex
.
binhex
(
fname1
,
fname2
)
if
verbose
:
print
'binhex'
binhex
.
hexbin
(
fname2
,
fname1
)
if
verbose
:
print
'hexbin'
f
=
open
(
fname1
,
'r'
)
finish
=
f
.
readline
()
if
start
<>
finish
:
print
'Error: binhex <> hexbin'
elif
verbose
:
print
'binhex == hexbin'
try
:
import
os
os
.
unlink
(
fname1
)
os
.
unlink
(
fname2
)
except
:
pass
test
()
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