From 914061ab151a7dd25e9b05091eabbfd2690ee438 Mon Sep 17 00:00:00 2001 From: "Gregory P. Smith" Date: Mon, 5 Aug 2013 13:14:37 -0700 Subject: * 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. --- Lib/test/test_hashlib.py | 15 ++++++++------- 1 file 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, -- cgit v0.12