Fix test_hashlib regression caused by my fixing hexdigest() to return
a text string instead of bytes. (This being hex digits it *should* be a text string -- that it wasn't before was a misunderstanding on my part of the C code.)
This commit is contained in:
parent
1bd2122041
commit
558ca84730
|
@ -13,11 +13,10 @@ from test import test_support
|
|||
|
||||
def hexstr(s):
|
||||
assert isinstance(s, bytes), repr(s)
|
||||
h = b"0123456789abcdef"
|
||||
r = b''
|
||||
h = "0123456789abcdef"
|
||||
r = ''
|
||||
for i in s:
|
||||
r.append(h[(i >> 4) & 0xF])
|
||||
r.append(h[i & 0xF])
|
||||
r += h[(i >> 4) & 0xF] + h[i & 0xF]
|
||||
return r
|
||||
|
||||
|
||||
|
@ -60,22 +59,22 @@ class HashLibTestCase(unittest.TestCase):
|
|||
def check(self, name, data, digest):
|
||||
# test the direct constructors
|
||||
computed = getattr(hashlib, name)(data).hexdigest()
|
||||
self.assert_(computed == digest)
|
||||
self.assertEqual(computed, digest)
|
||||
# test the general new() interface
|
||||
computed = hashlib.new(name, data).hexdigest()
|
||||
self.assert_(computed == digest)
|
||||
self.assertEqual(computed, digest)
|
||||
|
||||
|
||||
def test_case_md5_0(self):
|
||||
self.check('md5', b'', b'd41d8cd98f00b204e9800998ecf8427e')
|
||||
self.check('md5', b'', 'd41d8cd98f00b204e9800998ecf8427e')
|
||||
|
||||
def test_case_md5_1(self):
|
||||
self.check('md5', b'abc', b'900150983cd24fb0d6963f7d28e17f72')
|
||||
self.check('md5', b'abc', '900150983cd24fb0d6963f7d28e17f72')
|
||||
|
||||
def test_case_md5_2(self):
|
||||
self.check('md5',
|
||||
b'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789',
|
||||
b'd174ab98d277d9f5a5611c2c9f419d9f')
|
||||
'd174ab98d277d9f5a5611c2c9f419d9f')
|
||||
|
||||
|
||||
# use the three examples from Federal Information Processing Standards
|
||||
|
@ -84,20 +83,20 @@ class HashLibTestCase(unittest.TestCase):
|
|||
|
||||
def test_case_sha1_0(self):
|
||||
self.check('sha1', b"",
|
||||
b"da39a3ee5e6b4b0d3255bfef95601890afd80709")
|
||||
"da39a3ee5e6b4b0d3255bfef95601890afd80709")
|
||||
|
||||
def test_case_sha1_1(self):
|
||||
self.check('sha1', b"abc",
|
||||
b"a9993e364706816aba3e25717850c26c9cd0d89d")
|
||||
"a9993e364706816aba3e25717850c26c9cd0d89d")
|
||||
|
||||
def test_case_sha1_2(self):
|
||||
self.check('sha1',
|
||||
b"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
|
||||
b"84983e441c3bd26ebaae4aa1f95129e5e54670f1")
|
||||
"84983e441c3bd26ebaae4aa1f95129e5e54670f1")
|
||||
|
||||
def test_case_sha1_3(self):
|
||||
self.check('sha1', b"a" * 1000000,
|
||||
b"34aa973cd4c4daa4f61eeb2bdbad27316534016f")
|
||||
"34aa973cd4c4daa4f61eeb2bdbad27316534016f")
|
||||
|
||||
|
||||
# use the examples from Federal Information Processing Standards
|
||||
|
|
Loading…
Reference in New Issue