[Python-checkins] cpython (merge 3.2 -> default): (Merge 3.2) Close #12230: Mac OS X Tiger (10.4) has a kernel bug: sometimes,

victor.stinner python-checkins at python.org
Wed Jun 1 13:19:48 CEST 2011


http://hg.python.org/cpython/rev/566c42b0e750
changeset:   70576:566c42b0e750
parent:      70574:35212b113730
parent:      70575:22457ac2c2df
user:        Victor Stinner <victor.stinner at haypocalc.com>
date:        Wed Jun 01 13:19:07 2011 +0200
summary:
  (Merge 3.2) 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.

test.support.requires_mac_ver() is now a decorator, as suggested by Ezio
Melotti, and its docstring is fixed (linux_version => mac_ver).

files:
  Lib/test/support.py         |  39 +++++++++++++++---------
  Lib/test/test_math.py       |   5 +-
  Lib/test/test_subprocess.py |   5 +++
  3 files changed, 31 insertions(+), 18 deletions(-)


diff --git a/Lib/test/support.py b/Lib/test/support.py
--- a/Lib/test/support.py
+++ b/Lib/test/support.py
@@ -301,23 +301,32 @@
         return 0, 0, 0
 
 def requires_mac_ver(*min_version):
-    """Raise SkipTest if the OS is Mac OS X and the OS X version if less than
-    min_version.
+    """Decorator raising SkipTest if the OS is Mac OS X and the OS X
+    version if less than min_version.
 
-    For example, support.requires_linux_version(10, 5) raises SkipTest if the
-    version is less than 10.5.
+    For example, @requires_mac_ver(10, 5) raises SkipTest if the OS X version
+    is lesser than 10.5.
     """
-    if sys.platform != 'darwin':
-        return
-    version_txt = platform.mac_ver()[0]
-    try:
-        version = tuple(map(int, version_txt.split('.')))
-    except ValueError:
-        return
-    if version < min_version:
-        min_version_txt = '.'.join(map(str, min_version))
-        raise unittest.SkipTest("Mac OS X %s or higher required, not %s"
-                                % (min_version_txt, version_txt))
+    def decorator(func):
+        @functools.wraps(func)
+        def wrapper(*args, **kw):
+            if sys.platform == 'darwin':
+                version_txt = platform.mac_ver()[0]
+                try:
+                    version = tuple(map(int, version_txt.split('.')))
+                except ValueError:
+                    pass
+                else:
+                    if version < min_version:
+                        min_version_txt = '.'.join(map(str, min_version))
+                        raise unittest.SkipTest(
+                            "Mac OS X %s or higher required, not %s"
+                            % (min_version_txt, version_txt))
+            return func(*args, **kw)
+        wrapper.min_version = min_version
+        return wrapper
+    return decorator
+
 
 HOST = 'localhost'
 
diff --git a/Lib/test/test_math.py b/Lib/test/test_math.py
--- a/Lib/test/test_math.py
+++ b/Lib/test/test_math.py
@@ -670,10 +670,9 @@
         self.assertTrue(math.isnan(math.log2(NAN)))
 
     @requires_IEEE_754
+    # log2() is not accurate enough on Mac OS X Tiger (10.4)
+    @support.requires_mac_ver(10, 5)
     def testLog2Exact(self):
-        # log2() is not accurate enough on Mac OS X Tiger (10.4)
-        support.requires_mac_ver(10, 5)
-
         # Check that we get exact equality for log2 of powers of 2.
         actual = [math.log2(math.ldexp(1.0, n)) for n in range(-1074, 1024)]
         expected = [float(n) for n in range(-1074, 1024)]
diff --git a/Lib/test/test_subprocess.py b/Lib/test/test_subprocess.py
--- a/Lib/test/test_subprocess.py
+++ b/Lib/test/test_subprocess.py
@@ -1281,6 +1281,11 @@
                          "Some fds were left open")
         self.assertIn(1, remaining_fds, "Subprocess failed")
 
+    # 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.
+    @support.requires_mac_ver(10, 5)
     def test_pass_fds(self):
         fd_status = support.findfile("fd_status.py", subdir="subprocessdata")
 

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


More information about the Python-checkins mailing list