Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4914f9e

Browse files
committed
Merged revisions 88652 via svnmerge from
svn+ssh://[email protected]/python/branches/py3k ........ r88652 | antoine.pitrou | 2011-02-26 16:58:05 +0100 (sam., 26 févr. 2011) | 4 lines Issue #9931: Fix hangs in GUI tests under Windows in certain conditions. Patch by Hirokazu Yamamoto. ........
1 parent 89807a5 commit 4914f9e

2 files changed

Lines changed: 37 additions & 0 deletions

File tree

Lib/test/support.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,36 @@ def forget(modname):
233233
unlink(imp.cache_from_source(source, debug_override=True))
234234
unlink(imp.cache_from_source(source, debug_override=False))
235235

236+
# On some platforms, should not run gui test even if it is allowed
237+
# in `use_resources'.
238+
if sys.platform.startswith('win'):
239+
import ctypes
240+
import ctypes.wintypes
241+
def _is_gui_available():
242+
UOI_FLAGS = 1
243+
WSF_VISIBLE = 0x0001
244+
class USEROBJECTFLAGS(ctypes.Structure):
245+
_fields_ = [("fInherit", ctypes.wintypes.BOOL),
246+
("fReserved", ctypes.wintypes.BOOL),
247+
("dwFlags", ctypes.wintypes.DWORD)]
248+
dll = ctypes.windll.user32
249+
h = dll.GetProcessWindowStation()
250+
if not h:
251+
raise ctypes.WinError()
252+
uof = USEROBJECTFLAGS()
253+
needed = ctypes.wintypes.DWORD()
254+
res = dll.GetUserObjectInformationW(h,
255+
UOI_FLAGS,
256+
ctypes.byref(uof),
257+
ctypes.sizeof(uof),
258+
ctypes.byref(needed))
259+
if not res:
260+
raise ctypes.WinError()
261+
return bool(uof.dwFlags & WSF_VISIBLE)
262+
else:
263+
def _is_gui_available():
264+
return True
265+
236266
def is_resource_enabled(resource):
237267
"""Test whether a resource is enabled. Known resources are set by
238268
regrtest.py."""
@@ -245,6 +275,8 @@ def requires(resource, msg=None):
245275
possibility of False being returned occurs when regrtest.py is
246276
executing.
247277
"""
278+
if resource == 'gui' and not _is_gui_available():
279+
raise unittest.SkipTest("Cannot use the 'gui' resource")
248280
# see if the caller's module is __main__ - if so, treat as if
249281
# the resource was set
250282
if sys._getframe(1).f_globals.get("__name__") == "__main__":
@@ -1063,6 +1095,8 @@ def _id(obj):
10631095
return obj
10641096

10651097
def requires_resource(resource):
1098+
if resource == 'gui' and not _is_gui_available():
1099+
return unittest.skip("resource 'gui' is not available")
10661100
if is_resource_enabled(resource):
10671101
return _id
10681102
else:

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ Build
5555
Tests
5656
-----
5757

58+
- Issue #9931: Fix hangs in GUI tests under Windows in certain conditions.
59+
Patch by Hirokazu Yamamoto.
60+
5861
- Issue #10826: Prevent sporadic failure in test_subprocess on Solaris due
5962
to open door files.
6063

0 commit comments

Comments
 (0)