Commit bb4d3527 authored by Benjamin Peterson's avatar Benjamin Peterson

add a test for access errors from OpenKey (closes #21871)

Patch from Vladimir Iofik.
parent 4becf85d
...@@ -144,6 +144,23 @@ class Win32MimeTypesTestCase(unittest.TestCase): ...@@ -144,6 +144,23 @@ class Win32MimeTypesTestCase(unittest.TestCase):
finally: finally:
mimetypes._winreg = _winreg 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(): def test_main():
test_support.run_unittest(MimeTypesTestCase, test_support.run_unittest(MimeTypesTestCase,
Win32MimeTypesTestCase Win32MimeTypesTestCase
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment