diff options
author | Gregory P. Smith <greg@krypto.org> | 2012-07-22 04:19:53 (GMT) |
---|---|---|
committer | Gregory P. Smith <greg@krypto.org> | 2012-07-22 04:19:53 (GMT) |
commit | 76c28f7ce27ea48254e152032d25ded3117973cb (patch) | |
tree | b789dd9bd4df9d70249e067af39094d02d67472d | |
parent | 00528e8fec37bdf203bdb172ec3363353268d908 (diff) | |
download | cpython-76c28f7ce27ea48254e152032d25ded3117973cb.zip cpython-76c28f7ce27ea48254e152032d25ded3117973cb.tar.gz cpython-76c28f7ce27ea48254e152032d25ded3117973cb.tar.bz2 |
Consistently raise a TypeError when a non str is passed to hashlib.new
regardless of which of the two implementations of new is used.
-rw-r--r-- | Lib/hashlib.py | 2 | ||||
-rw-r--r-- | Lib/test/test_hashlib.py | 9 |
2 files changed, 4 insertions, 7 deletions
diff --git a/Lib/hashlib.py b/Lib/hashlib.py index 9108095..21454c7 100644 --- a/Lib/hashlib.py +++ b/Lib/hashlib.py @@ -88,7 +88,7 @@ def __get_builtin_constructor(name): except ImportError: pass # no extension module, this hash is unsupported. - raise ValueError('unsupported hash type %s' % name) + raise ValueError('unsupported hash type ' + name) def __get_openssl_constructor(name): diff --git a/Lib/test/test_hashlib.py b/Lib/test/test_hashlib.py index 97981dd..29d3a1c 100644 --- a/Lib/test/test_hashlib.py +++ b/Lib/test/test_hashlib.py @@ -111,12 +111,8 @@ class HashLibTestCase(unittest.TestCase): issubset(hashlib.algorithms_available)) def test_unknown_hash(self): - try: - hashlib.new('spam spam spam spam spam') - except ValueError: - pass - else: - self.assertTrue(0 == "hashlib didn't reject bogus hash name") + self.assertRaises(ValueError, hashlib.new, 'spam spam spam spam spam') + self.assertRaises(TypeError, hashlib.new, 1) def test_get_builtin_constructor(self): get_builtin_constructor = hashlib.__dict__[ @@ -135,6 +131,7 @@ class HashLibTestCase(unittest.TestCase): sys.modules['_md5'] = _md5 else: del sys.modules['_md5'] + self.assertRaises(TypeError, get_builtin_constructor, 3) def test_hexdigest(self): for name in self.supported_hash_names: |