Skip to content

Commit fe6cadb

Browse files
author
Victor Stinner
committed
Close #12230: Mac OS X Tiger (10.4) has a kernel bug: sometimes, the file
descriptor of a pipe closed in the parent process is valid in the child process according to fstat(), but the mode of the file descriptor is invalid, and read or write raise an error. Add also requires_mac_ver() decorator to test.support.
1 parent 0ab20c3 commit fe6cadb

2 files changed

Lines changed: 34 additions & 1 deletion

File tree

Lib/test/support.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@
3232
"Error", "TestFailed", "ResourceDenied", "import_module",
3333
"verbose", "use_resources", "max_memuse", "record_original_stdout",
3434
"get_original_stdout", "unload", "unlink", "rmtree", "forget",
35-
"is_resource_enabled", "requires", "find_unused_port", "bind_port",
35+
"is_resource_enabled", "requires", "requires_mac_ver",
36+
"find_unused_port", "bind_port",
3637
"fcmp", "is_jython", "TESTFN", "HOST", "FUZZ", "SAVEDCWD", "temp_cwd",
3738
"findfile", "sortdict", "check_syntax_error", "open_urlresource",
3839
"check_warnings", "CleanImport", "EnvironmentVarGuard",
@@ -288,6 +289,33 @@ def requires(resource, msg=None):
288289
msg = "Use of the `%s' resource not enabled" % resource
289290
raise ResourceDenied(msg)
290291

292+
def requires_mac_ver(*min_version):
293+
"""Decorator raising SkipTest if the OS is Mac OS X and the OS X
294+
version if less than min_version.
295+
296+
For example, @requires_mac_ver(10, 5) raises SkipTest if the OS X version
297+
is lesser than 10.5.
298+
"""
299+
def decorator(func):
300+
@functools.wraps(func)
301+
def wrapper(*args, **kw):
302+
if sys.platform == 'darwin':
303+
version_txt = platform.mac_ver()[0]
304+
try:
305+
version = tuple(map(int, version_txt.split('.')))
306+
except ValueError:
307+
pass
308+
else:
309+
if version < min_version:
310+
min_version_txt = '.'.join(map(str, min_version))
311+
raise unittest.SkipTest(
312+
"Mac OS X %s or higher required, not %s"
313+
% (min_version_txt, version_txt))
314+
return func(*args, **kw)
315+
wrapper.min_version = min_version
316+
return wrapper
317+
return decorator
318+
291319
HOST = 'localhost'
292320

293321
def find_unused_port(family=socket.AF_INET, socktype=socket.SOCK_STREAM):

Lib/test/test_subprocess.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1185,6 +1185,11 @@ def test_close_fds(self):
11851185
"Some fds were left open")
11861186
self.assertIn(1, remaining_fds, "Subprocess failed")
11871187

1188+
# Mac OS X Tiger (10.4) has a kernel bug: sometimes, the file
1189+
# descriptor of a pipe closed in the parent process is valid in the
1190+
# child process according to fstat(), but the mode of the file
1191+
# descriptor is invalid, and read or write raise an error.
1192+
@support.requires_mac_ver(10, 5)
11881193
def test_pass_fds(self):
11891194
fd_status = support.findfile("fd_status.py", subdir="subprocessdata")
11901195

0 commit comments

Comments
 (0)