diff options
author | Benjamin Peterson <benjamin@python.org> | 2014-06-29 20:02:12 (GMT) |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2014-06-29 20:02:12 (GMT) |
commit | bb4d3527cf8a17d6b8e57c608033cf065ce67078 (patch) | |
tree | c967e38bf0499fe928222205bdf07bf713aef2d7 | |
parent | 4becf85d54d60605551a338a201b282aa7b64968 (diff) | |
download | cpython-bb4d3527cf8a17d6b8e57c608033cf065ce67078.zip cpython-bb4d3527cf8a17d6b8e57c608033cf065ce67078.tar.gz cpython-bb4d3527cf8a17d6b8e57c608033cf065ce67078.tar.bz2 |
add a test for access errors from OpenKey (closes #21871)
Patch from Vladimir Iofik.
-rw-r--r-- | Lib/test/test_mimetypes.py | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/Lib/test/test_mimetypes.py b/Lib/test/test_mimetypes.py index 8de4258..e9a7216 100644 --- a/Lib/test/test_mimetypes.py +++ b/Lib/test/test_mimetypes.py @@ -144,6 +144,23 @@ class Win32MimeTypesTestCase(unittest.TestCase): finally: mimetypes._winreg = _winreg + def test_registry_read_error(self): + import _winreg + + class MockWinreg(object): + def OpenKey(self, key, name): + if key != _winreg.HKEY_CLASSES_ROOT: + raise WindowsError(5, "Access is denied") + return _winreg.OpenKey(key, name) + def __getattr__(self, name): + return getattr(_winreg, name) + + mimetypes._winreg = MockWinreg() + try: + mimetypes.init() + finally: + mimetypes._winreg = _winreg + def test_main(): test_support.run_unittest(MimeTypesTestCase, Win32MimeTypesTestCase |