]> granicus.if.org Git - python/commitdiff
(Merge 3.2) Close #12230: Mac OS X Tiger (10.4) has a kernel bug: sometimes,
authorVictor Stinner <victor.stinner@haypocalc.com>
Wed, 1 Jun 2011 11:19:07 +0000 (13:19 +0200)
committerVictor Stinner <victor.stinner@haypocalc.com>
Wed, 1 Jun 2011 11:19:07 +0000 (13:19 +0200)
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).

1  2 
Lib/test/support.py
Lib/test/test_math.py
Lib/test/test_subprocess.py

index 1bf9ca5237d9e1440fd2af0c471f5bd37a08d65d,2aedf24846ee4986d4dedffcba039dd9bc9cb981..d3f7f4c5e5eab18964c508132233c8b844cef16d
@@@ -292,33 -289,33 +292,42 @@@ def requires(resource, msg=None)
              msg = "Use of the `%s' resource not enabled" % resource
          raise ResourceDenied(msg)
  
 +def linux_version():
 +    try:
 +        # platform.release() is something like '2.6.33.7-desktop-2mnb'
 +        version_string = platform.release().split('-')[0]
 +        return tuple(map(int, version_string.split('.')))
 +    except ValueError:
 +        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'
  
  def find_unused_port(family=socket.AF_INET, socktype=socket.SOCK_STREAM):
index 636ff2c4927f86f97d06f20569996c4399bb19bb,dddc889375cf4291eee9663ac5d20feb9d36a737..715003af0517f9578935ac7fae098597bd6842c0
@@@ -651,34 -650,6 +651,33 @@@ class MathTests(unittest.TestCase)
          n= 2**90
          self.assertAlmostEqual(math.log1p(n), math.log1p(float(n)))
  
-         # log2() is not accurate enough on Mac OS X Tiger (10.4)
-         support.requires_mac_ver(10, 5)
 +    @requires_IEEE_754
 +    def testLog2(self):
 +        self.assertRaises(TypeError, math.log2)
 +
 +        # Check some integer values
 +        self.assertEqual(math.log2(1), 0.0)
 +        self.assertEqual(math.log2(2), 1.0)
 +        self.assertEqual(math.log2(4), 2.0)
 +
 +        # Large integer values
 +        self.assertEqual(math.log2(2**1023), 1023.0)
 +        self.assertEqual(math.log2(2**1024), 1024.0)
 +        self.assertEqual(math.log2(2**2000), 2000.0)
 +
 +        self.assertRaises(ValueError, math.log2, -1.5)
 +        self.assertRaises(ValueError, math.log2, NINF)
 +        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):
 +        # 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)]
 +        self.assertEqual(actual, expected)
 +
      def testLog10(self):
          self.assertRaises(TypeError, math.log10)
          self.ftest('log10(0.1)', math.log10(0.1), -1)
Simple merge