summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorGregory P. Smith <greg@krypto.org>2011-05-14 22:15:49 (GMT)
committerGregory P. Smith <greg@krypto.org>2011-05-14 22:15:49 (GMT)
commit12c9d028ed0a1803019f3796014e75c74d9de2f6 (patch)
treeaf6ae4f6fe85005be8c7ad2e916a9f11528cdded /Lib/test
parente670c889ccf5ce7b27dedbc7d6d24e0679ca93bb (diff)
downloadcpython-12c9d028ed0a1803019f3796014e75c74d9de2f6.zip
cpython-12c9d028ed0a1803019f3796014e75c74d9de2f6.tar.gz
cpython-12c9d028ed0a1803019f3796014e75c74d9de2f6.tar.bz2
Fixes Issue #12059: Properly handle missing hash functions even when
the expected builtin modules are not present. This includes a unittest for __get_builtin_constructor() in the face of such an error.
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_hashlib.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/Lib/test/test_hashlib.py b/Lib/test/test_hashlib.py
index fe316fd..17d752b 100644
--- a/Lib/test/test_hashlib.py
+++ b/Lib/test/test_hashlib.py
@@ -118,6 +118,24 @@ class HashLibTestCase(unittest.TestCase):
else:
self.assertTrue(0 == "hashlib didn't reject bogus hash name")
+ def test_get_builtin_constructor(self):
+ get_builtin_constructor = hashlib.__dict__[
+ '__get_builtin_constructor']
+ self.assertRaises(ValueError, get_builtin_constructor, 'test')
+ try:
+ import _md5
+ except ImportError:
+ pass
+ # This forces an ImportError for "import _md5" statements
+ sys.modules['_md5'] = None
+ try:
+ self.assertRaises(ValueError, get_builtin_constructor, 'md5')
+ finally:
+ if '_md5' in locals():
+ sys.modules['_md5'] = _md5
+ else:
+ del sys.modules['_md5']
+
def test_hexdigest(self):
for name in self.supported_hash_names:
h = hashlib.new(name)