[Python-checkins] cpython: * Fix the assertions in hashlib to use unittest assertion methods instead of

gregory.p.smith python-checkins at python.org
Mon Aug 5 22:14:54 CEST 2013


http://hg.python.org/cpython/rev/c6d4564dc86f
changeset: 85044:c6d4564dc86f
user: Gregory P. Smith <greg at krypto.org>
date: Mon Aug 05 13:14:37 2013 -0700
summary:
 * 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.
files:
 Lib/test/test_hashlib.py | 15 ++++++++-------
 1 files changed, 8 insertions(+), 7 deletions(-)
diff --git a/Lib/test/test_hashlib.py b/Lib/test/test_hashlib.py
--- a/Lib/test/test_hashlib.py
+++ b/Lib/test/test_hashlib.py
@@ -75,8 +75,8 @@
 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 @@
 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 @@
 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,
-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /