Author: Philip Jenvey <pjen...@underboss.org> Branch: py3.3 Changeset: r72864:0c8f0c10188c Date: 2014-08-17 16:05 -0700 http://bitbucket.org/pypy/pypy/changeset/0c8f0c10188c/
Log: Merged in numerodix/pypy/py3.3-fixes3 (pull request #270) py3.3: fixes for failing hashlib tests diff --git a/lib-python/3/test/test_hashlib.py b/lib-python/3/test/test_hashlib.py --- a/lib-python/3/test/test_hashlib.py +++ b/lib-python/3/test/test_hashlib.py @@ -142,7 +142,7 @@ def test_hexdigest(self): for cons in self.hash_constructors: h = cons() - assert isinstance(h.digest(), bytes), name + assert isinstance(h.digest(), bytes), cons.__name__ self.assertEqual(hexstr(h.digest()), h.hexdigest()) def test_large_update(self): diff --git a/lib_pypy/_sha1.py b/lib_pypy/_sha1.py --- a/lib_pypy/_sha1.py +++ b/lib_pypy/_sha1.py @@ -123,6 +123,8 @@ def __init__(self): "Initialisation." + self.name = 'sha' + # Initial message length in bits(!). self.length = 0 self.count = [0, 0] @@ -349,6 +351,7 @@ """ crypto = sha() + crypto.name = 'sha1' if arg: crypto.update(arg) diff --git a/lib_pypy/_sha256.py b/lib_pypy/_sha256.py --- a/lib_pypy/_sha256.py +++ b/lib_pypy/_sha256.py @@ -201,13 +201,14 @@ dig = [] for i in sha_info['digest']: dig.extend([ ((i>>24) & 0xff), ((i>>16) & 0xff), ((i>>8) & 0xff), (i & 0xff) ]) - return ''.join([chr(i) for i in dig]) + return bytes(dig) class sha256(object): digest_size = digestsize = SHA_DIGESTSIZE block_size = SHA_BLOCKSIZE def __init__(self, s=None): + self.name = 'sha256' self._sha = sha_init() if s: sha_update(self._sha, s) @@ -219,7 +220,7 @@ return sha_final(self._sha.copy())[:self._sha['digestsize']] def hexdigest(self): - return ''.join(['%.2x' % ord(i) for i in self.digest()]) + return ''.join(['%.2x' % i for i in self.digest()]) def copy(self): new = sha256.__new__(sha256) @@ -230,6 +231,7 @@ digest_size = digestsize = 28 def __init__(self, s=None): + self.name = 'sha224' self._sha = sha224_init() if s: sha_update(self._sha, s) @@ -240,7 +242,7 @@ return new def test(): - a_str = "just a test string" + a_str = b"just a test string" assert 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855' == sha256().hexdigest() assert 'd7b553c6f09ac85d142415f857c5310f3bbbe7cdd787cce4b985acedd585266f' == sha256(a_str).hexdigest() diff --git a/lib_pypy/_sha512.py b/lib_pypy/_sha512.py --- a/lib_pypy/_sha512.py +++ b/lib_pypy/_sha512.py @@ -236,6 +236,7 @@ block_size = SHA_BLOCKSIZE def __init__(self, s=None): + self.name = 'sha512' self._sha = sha_init() if s: sha_update(self._sha, s) @@ -258,6 +259,7 @@ digest_size = digestsize = 48 def __init__(self, s=None): + self.name = 'sha384' self._sha = sha384_init() if s: sha_update(self._sha, s) @@ -270,7 +272,7 @@ def test(): import _sha512 - a_str = "just a test string" + a_str = b"just a test string" assert _sha512.sha512().hexdigest() == sha512().hexdigest() assert _sha512.sha512(a_str).hexdigest() == sha512(a_str).hexdigest() diff --git a/pypy/module/_md5/interp_md5.py b/pypy/module/_md5/interp_md5.py --- a/pypy/module/_md5/interp_md5.py +++ b/pypy/module/_md5/interp_md5.py @@ -52,6 +52,7 @@ copy = interp2app(W_MD5.copy_w), digest_size = 16, block_size = 64, + name = 'md5', __doc__ = """md5(arg) -> return new md5 object. If arg is present, the method call update(arg) is made.""") diff --git a/pypy/module/_md5/test/test_md5.py b/pypy/module/_md5/test/test_md5.py --- a/pypy/module/_md5/test/test_md5.py +++ b/pypy/module/_md5/test/test_md5.py @@ -19,6 +19,12 @@ """) + def test_name(self): + """ + md5.name should be 'md5'. + """ + assert self.md5.md5().name == 'md5' + def test_digest_size(self): """ md5.digest_size should be 16. diff --git a/pypy/module/test_lib_pypy/test_sha_extra.py b/pypy/module/test_lib_pypy/test_sha_extra.py --- a/pypy/module/test_lib_pypy/test_sha_extra.py +++ b/pypy/module/test_lib_pypy/test_sha_extra.py @@ -37,3 +37,30 @@ assert _sha.sha1().digest_size == 20 assert _sha.sha1().digestsize == 20 assert _sha.sha1().block_size == 64 + + assert _sha.sha().name == 'sha' + assert _sha.sha1().name == 'sha1' + + +class AppTestSHA256: + spaceconfig = dict(usemodules=('struct',)) + + def setup_class(cls): + cls.w__sha256 = import_lib_pypy(cls.space, '_sha256') + + def test_attributes(self): + _sha256 = self._sha256 + assert _sha256.sha224().name == 'sha224' + assert _sha256.sha256().name == 'sha256' + + +class AppTestSHA512: + spaceconfig = dict(usemodules=('struct',)) + + def setup_class(cls): + cls.w__sha512 = import_lib_pypy(cls.space, '_sha512') + + def test_attributes(self): + _sha512 = self._sha512 + assert _sha512.sha384().name == 'sha384' + assert _sha512.sha512().name == 'sha512' _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit