[Python-checkins] cpython (2.7): add a test for access errors from OpenKey (closes #21871)

benjamin.peterson python-checkins at python.org
Sun Jun 29 22:04:05 CEST 2014


http://hg.python.org/cpython/rev/ee33d61f5e4b
changeset:   91466:ee33d61f5e4b
branch:      2.7
user:        Benjamin Peterson <benjamin at python.org>
date:        Sun Jun 29 13:02:12 2014 -0700
summary:
  add a test for access errors from OpenKey (closes #21871)

Patch from Vladimir Iofik.

files:
  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
--- a/Lib/test/test_mimetypes.py
+++ b/Lib/test/test_mimetypes.py
@@ -144,6 +144,23 @@
         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

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list