Changes in anticipation of stricter str vs. bytes enforcement.

This commit is contained in:
Guido van Rossum 2007-08-27 17:23:59 +00:00
parent 85825dc1ff
commit 39478e8528
15 changed files with 78 additions and 76 deletions

View file

@ -24,21 +24,21 @@ class TestVectorsTestCase(unittest.TestCase):
b"\xdd" * 50,
"56be34521d144c88dbb8c733f0e8b3f6")
md5test("".join([chr(i) for i in range(1, 26)]),
md5test(bytes(range(1, 26)),
b"\xcd" * 50,
"697eaf0aca3a3aea3a75164746ffaa79")
md5test(chr(0x0C) * 16,
"Test With Truncation",
md5test(b"\x0C" * 16,
b"Test With Truncation",
"56461ef2342edc00f9bab995690efd4c")
md5test(b"\xaa" * 80,
"Test Using Larger Than Block-Size Key - Hash Key First",
b"Test Using Larger Than Block-Size Key - Hash Key First",
"6b1ab7fe4bd7bf8f0b62e6ce61b9d0cd")
md5test(b"\xaa" * 80,
("Test Using Larger Than Block-Size Key "
"and Larger Than One Block-Size Data"),
(b"Test Using Larger Than Block-Size Key "
b"and Larger Than One Block-Size Data"),
"6f630fad67cda0ee1fb1f562db3aa53e")
def test_sha_vectors(self):
@ -62,8 +62,8 @@ class TestVectorsTestCase(unittest.TestCase):
b"\xCD" * 50,
"4c9007f4026250c6bc8414f9bf50c86c2d7235da")
shatest(chr(0x0C) * 20,
"Test With Truncation",
shatest(b"\x0C" * 20,
b"Test With Truncation",
"4c1a03424b55e07fe7f27be1d58bb9324a9a5a04")
shatest(b"\xAA" * 80,
@ -82,14 +82,14 @@ class ConstructorTestCase(unittest.TestCase):
# Standard constructor call.
failed = 0
try:
h = hmac.HMAC("key")
h = hmac.HMAC(b"key")
except:
self.fail("Standard constructor call raised exception.")
def test_withtext(self):
# Constructor call with text.
try:
h = hmac.HMAC("key", "hash this!")
h = hmac.HMAC(b"key", b"hash this!")
except:
self.fail("Constructor call with text argument raised exception.")
@ -97,7 +97,7 @@ class ConstructorTestCase(unittest.TestCase):
# Constructor call with text and digest module.
from hashlib import sha1
try:
h = hmac.HMAC("key", "", sha1)
h = hmac.HMAC(b"key", b"", sha1)
except:
self.fail("Constructor call with hashlib.sha1 raised exception.")
@ -107,15 +107,15 @@ class SanityTestCase(unittest.TestCase):
# Testing if HMAC defaults to MD5 algorithm.
# NOTE: this whitebox test depends on the hmac class internals
import hashlib
h = hmac.HMAC("key")
h = hmac.HMAC(b"key")
self.assertEqual(h.digest_cons, hashlib.md5)
def test_exercise_all_methods(self):
# Exercising all methods once.
# This must not raise any exceptions
try:
h = hmac.HMAC("my secret key")
h.update("compute the hash of this text!")
h = hmac.HMAC(b"my secret key")
h.update(b"compute the hash of this text!")
dig = h.digest()
dig = h.hexdigest()
h2 = h.copy()
@ -126,7 +126,7 @@ class CopyTestCase(unittest.TestCase):
def test_attributes(self):
# Testing if attributes are of same type.
h1 = hmac.HMAC("key")
h1 = hmac.HMAC(b"key")
h2 = h1.copy()
self.failUnless(h1.digest_cons == h2.digest_cons,
"digest constructors don't match.")
@ -137,7 +137,7 @@ class CopyTestCase(unittest.TestCase):
def test_realcopy(self):
# Testing if the copy method created a real copy.
h1 = hmac.HMAC("key")
h1 = hmac.HMAC(b"key")
h2 = h1.copy()
# Using id() in case somebody has overridden __cmp__.
self.failUnless(id(h1) != id(h2), "No real copy of the HMAC instance.")
@ -148,8 +148,8 @@ class CopyTestCase(unittest.TestCase):
def test_equality(self):
# Testing if the copy has the same digests.
h1 = hmac.HMAC("key")
h1.update("some random text")
h1 = hmac.HMAC(b"key")
h1.update(b"some random text")
h2 = h1.copy()
self.assertEqual(h1.digest(), h2.digest(),
"Digest of copy doesn't match original digest.")