[Python-checkins] r86161 - in python/branches/py3k-ttk-debug-on-xp5/Lib/test: regrtest.py support.py

hirokazu.yamamoto python-checkins at python.org
Thu Nov 4 13:59:37 CET 2010


Author: hirokazu.yamamoto
Date: Thu Nov  4 13:59:37 2010
New Revision: 86161

Log:
Moved check code into test.support.requires and require_resource.
Raises unittest.SkipTest if GUI is not available.

Modified:
   python/branches/py3k-ttk-debug-on-xp5/Lib/test/regrtest.py
   python/branches/py3k-ttk-debug-on-xp5/Lib/test/support.py

Modified: python/branches/py3k-ttk-debug-on-xp5/Lib/test/regrtest.py
==============================================================================
--- python/branches/py3k-ttk-debug-on-xp5/Lib/test/regrtest.py	(original)
+++ python/branches/py3k-ttk-debug-on-xp5/Lib/test/regrtest.py	Thu Nov  4 13:59:37 2010
@@ -216,41 +216,6 @@
 RESOURCE_NAMES = ('audio', 'curses', 'largefile', 'network',
                   'decimal', 'compiler', 'subprocess', 'urlfetch', 'gui')
 
-if sys.platform == "win32":
-    import ctypes
-    import ctypes.wintypes
-
-    UOI_FLAGS = 1
-    WSF_VISIBLE = 0x0001
-
-    class USEROBJECTFLAGS(ctypes.Structure):
-        _fields_ = [("fInherit", ctypes.wintypes.BOOL),
-                    ("fReserved", ctypes.wintypes.BOOL),
-                    ("dwFlags", ctypes.wintypes.DWORD)]
-
-    def window_station_has_display_surfaces():
-        dll = ctypes.windll.user32
-        h = dll.GetProcessWindowStation()
-        if not h:
-            raise ctypes.WinError()
-        uof = USEROBJECTFLAGS()
-        needed = ctypes.wintypes.DWORD()
-        res = dll.GetUserObjectInformationW(h,
-            UOI_FLAGS,
-            ctypes.byref(uof),
-            ctypes.sizeof(uof),
-            ctypes.byref(needed))
-        if not res:
-            raise ctypes.WinError()
-        return bool(uof.dwFlags & WSF_VISIBLE)
-
-    # XXX: is this right place to do this?
-    if not window_station_has_display_surfaces():
-        print("Window Station has no display surfaces, so remove gui from RESOURCE_NAMES")
-        tmp = list(RESOURCE_NAMES)
-        tmp.remove("gui")
-        RESOURCE_NAMES = tuple(tmp)
-
 TEMPDIR = os.path.abspath(tempfile.gettempdir())
 
 def usage(msg):

Modified: python/branches/py3k-ttk-debug-on-xp5/Lib/test/support.py
==============================================================================
--- python/branches/py3k-ttk-debug-on-xp5/Lib/test/support.py	(original)
+++ python/branches/py3k-ttk-debug-on-xp5/Lib/test/support.py	Thu Nov  4 13:59:37 2010
@@ -229,6 +229,36 @@
         unlink(imp.cache_from_source(source, debug_override=True))
         unlink(imp.cache_from_source(source, debug_override=False))
 
+# On some platforms, should not run gui test even if it is allowed
+# in `use_resources'.
+if sys.platform.startswith('win'):
+    import ctypes
+    import ctypes.wintypes
+    def _is_gui_available():
+        UOI_FLAGS = 1
+        WSF_VISIBLE = 0x0001
+        class USEROBJECTFLAGS(ctypes.Structure):
+            _fields_ = [("fInherit", ctypes.wintypes.BOOL),
+                        ("fReserved", ctypes.wintypes.BOOL),
+                        ("dwFlags", ctypes.wintypes.DWORD)]
+        dll = ctypes.windll.user32
+        h = dll.GetProcessWindowStation()
+        if not h:
+            raise ctypes.WinError()
+        uof = USEROBJECTFLAGS()
+        needed = ctypes.wintypes.DWORD()
+        res = dll.GetUserObjectInformationW(h,
+            UOI_FLAGS,
+            ctypes.byref(uof),
+            ctypes.sizeof(uof),
+            ctypes.byref(needed))
+        if not res:
+            raise ctypes.WinError()
+        return bool(uof.dwFlags & WSF_VISIBLE)
+else:
+    def _is_gui_available():
+        return True
+
 def is_resource_enabled(resource):
     """Test whether a resource is enabled.  Known resources are set by
     regrtest.py."""
@@ -241,6 +271,8 @@
     possibility of False being returned occurs when regrtest.py is
     executing.
     """
+    if resource == 'gui' and not _is_gui_available():
+        raise unittest.SkipTest("Cannot use the 'gui' resource")
     # see if the caller's module is __main__ - if so, treat as if
     # the resource was set
     if sys._getframe(1).f_globals.get("__name__") == "__main__":
@@ -1046,7 +1078,9 @@
     return obj
 
 def requires_resource(resource):
-    if resource_is_enabled(resource):
+    if resource == 'gui' and not _is_gui_available():
+        return unittest.skip("resource 'gui' is not available")
+    if is_resource_enabled(resource):
         return _id
     else:
         return unittest.skip("resource {0!r} is not enabled".format(resource))


More information about the Python-checkins mailing list