mirror of
https://github.com/panda3d/panda3d.git
synced 2025-09-29 08:15:18 -04:00
tests: Add HashVal md5 unit test that doesn't rely on hashlib
This commit is contained in:
parent
e08cba191e
commit
a63bbba4c1
@ -1,8 +1,13 @@
|
|||||||
from panda3d import core
|
from panda3d import core
|
||||||
import random
|
import random
|
||||||
import hashlib
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
try:
|
||||||
|
import hashlib
|
||||||
|
except ImportError:
|
||||||
|
hashlib = object()
|
||||||
|
hashlib.algorithms_available = ()
|
||||||
|
|
||||||
|
|
||||||
def test_hashval_hex():
|
def test_hashval_hex():
|
||||||
hex = '%032x' % random.getrandbits(32 * 4)
|
hex = '%032x' % random.getrandbits(32 * 4)
|
||||||
@ -11,9 +16,25 @@ def test_hashval_hex():
|
|||||||
assert str(val) == hex.lower()
|
assert str(val) == hex.lower()
|
||||||
|
|
||||||
|
|
||||||
|
def test_hashval_md5_known():
|
||||||
|
known_hashes = {
|
||||||
|
'd41d8cd98f00b204e9800998ecf8427e': b'',
|
||||||
|
'93b885adfe0da089cdf634904fd59f71': b'\000',
|
||||||
|
'3b5d3c7d207e37dceeedd301e35e2e58': b'\000' * 64,
|
||||||
|
'202cb962ac59075b964b07152d234b70': b'123',
|
||||||
|
'520620de89e220f9b5850cc97cbff46c': b'01234567' * 8,
|
||||||
|
'ad32d3ef227a5ebd800a40d4eeaff41f': b'01234567' * 8 + b'a',
|
||||||
|
}
|
||||||
|
|
||||||
|
for known, plain in known_hashes.items():
|
||||||
|
hv = core.HashVal()
|
||||||
|
hv.hash_bytes(plain)
|
||||||
|
assert hv.as_hex() == known
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.skipif('md5' not in hashlib.algorithms_available,
|
@pytest.mark.skipif('md5' not in hashlib.algorithms_available,
|
||||||
reason="MD5 algorithm not available in hashlib")
|
reason="MD5 algorithm not available in hashlib")
|
||||||
def test_hashval_md5():
|
def test_hashval_md5_random():
|
||||||
data = bytearray()
|
data = bytearray()
|
||||||
|
|
||||||
for i in range(2500):
|
for i in range(2500):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user