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
a0b6035a
Kaydet (Commit)
a0b6035a
authored
Kas 02, 2001
tarafından
Andrew M. Kuchling
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
[Patch #476612] Add test suite for PEP247 compliance
üst
a2085cb7
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
50 additions
and
0 deletions
+50
-0
test_pep247.py
Lib/test/test_pep247.py
+50
-0
No files found.
Lib/test/test_pep247.py
0 → 100644
Dosyayı görüntüle @
a0b6035a
#
# Test suite to check compliance with PEP 247, the standard API for
# hashing algorithms.
#
import
md5
,
sha
,
hmac
def
check_hash_module
(
module
,
key
=
None
):
assert
hasattr
(
module
,
'digest_size'
),
"Must have digest_size"
assert
(
module
.
digest_size
is
None
or
module
.
digest_size
>
0
),
"digest_size must be None or positive"
if
key
is
not
None
:
obj1
=
module
.
new
(
key
)
obj2
=
module
.
new
(
key
,
"string"
)
h1
=
module
.
new
(
key
,
"string"
)
.
digest
()
obj3
=
module
.
new
(
key
)
;
obj3
.
update
(
"string"
)
;
h2
=
obj3
.
digest
()
assert
h1
==
h2
,
"Hashes must match"
else
:
obj1
=
module
.
new
()
obj2
=
module
.
new
(
"string"
)
h1
=
module
.
new
(
"string"
)
.
digest
()
obj3
=
module
.
new
()
;
obj3
.
update
(
"string"
)
;
h2
=
obj3
.
digest
()
assert
h1
==
h2
,
"Hashes must match"
assert
hasattr
(
obj1
,
'digest_size'
),
"Objects must have digest_size attr"
if
module
.
digest_size
is
not
None
:
assert
obj1
.
digest_size
==
module
.
digest_size
,
"digest_size must match"
assert
obj1
.
digest_size
==
len
(
h1
),
"digest_size must match actual size"
obj1
.
update
(
"string"
)
obj_copy
=
obj1
.
copy
()
assert
obj1
.
digest
()
==
obj_copy
.
digest
(),
"Copied objects must match"
assert
obj1
.
hexdigest
()
==
obj_copy
.
hexdigest
(),
\
"Copied objects must match"
digest
,
hexdigest
=
obj1
.
digest
(),
obj1
.
hexdigest
()
hd2
=
""
for
byte
in
digest
:
hd2
+=
"
%02
x"
%
ord
(
byte
)
assert
hd2
==
hexdigest
,
"hexdigest doesn't appear correct"
print
'Module'
,
module
.
__name__
,
'seems to comply with PEP 247'
if
__name__
==
'__main__'
:
check_hash_module
(
md5
)
check_hash_module
(
sha
)
check_hash_module
(
hmac
,
key
=
'abc'
)
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