summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorGregory P. Smith <greg@krypto.org>2013-08-05 20:14:37 (GMT)
committerGregory P. Smith <greg@krypto.org>2013-08-05 20:14:37 (GMT)
commit914061ab151a7dd25e9b05091eabbfd2690ee438 (patch)
tree3cfd145c5a51b71791fa68f7d8c15870f7bec6d7 /Lib/test
parente5192cdbb91ab7c081cd321178dacd2a22f10019 (diff)
downloadcpython-914061ab151a7dd25e9b05091eabbfd2690ee438.zip
cpython-914061ab151a7dd25e9b05091eabbfd2690ee438.tar.gz
cpython-914061ab151a7dd25e9b05091eabbfd2690ee438.tar.bz2
* Fix the assertions in hashlib to use unittest assertion methods instead of
evil assert statements. * Add an additional assert to the new test_name_attribute test that actually confirms that a hash created using each h.name results in a new hash sharing the same name.
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_hashlib.py15
1 files changed, 8 insertions, 7 deletions
diff --git a/Lib/test/test_hashlib.py b/Lib/test/test_hashlib.py
index e944bde..40cc83a 100644
--- a/Lib/test/test_hashlib.py
+++ b/Lib/test/test_hashlib.py
@@ -75,8 +75,8 @@ class HashLibTestCase(unittest.TestCase):
if _hashlib:
# These two algorithms should always be present when this module
# is compiled. If not, something was compiled wrong.
- assert hasattr(_hashlib, 'openssl_md5')
- assert hasattr(_hashlib, 'openssl_sha1')
+ self.assertTrue(hasattr(_hashlib, 'openssl_md5'))
+ self.assertTrue(hasattr(_hashlib, 'openssl_sha1'))
for algorithm, constructors in self.constructors_to_test.items():
constructor = getattr(_hashlib, 'openssl_'+algorithm, None)
if constructor:
@@ -151,14 +151,15 @@ class HashLibTestCase(unittest.TestCase):
def test_hexdigest(self):
for cons in self.hash_constructors:
h = cons()
- assert isinstance(h.digest(), bytes), name
+ self.assertIsInstance(h.digest(), bytes)
self.assertEqual(hexstr(h.digest()), h.hexdigest())
def test_name_attribute(self):
for cons in self.hash_constructors:
h = cons()
- assert isinstance(h.name, str), "No name attribute"
- assert h.name in self.supported_hash_names
+ self.assertIsInstance(h.name, str)
+ self.assertIn(h.name, self.supported_hash_names)
+ self.assertEqual(h.name, hashlib.new(h.name).name)
def test_large_update(self):
aas = b'a' * 128
@@ -532,8 +533,8 @@ class HashLibTestCase(unittest.TestCase):
events = []
for threadnum in range(num_threads):
chunk_size = len(data) // (10**threadnum)
- assert chunk_size > 0
- assert chunk_size % len(smallest_data) == 0
+ self.assertGreater(chunk_size, 0)
+ self.assertEqual(chunk_size % len(smallest_data), 0)
event = threading.Event()
events.append(event)
threading.Thread(target=hash_in_chunks,