[Python-Dev] [Python-checkins] cpython: test.support: add requires_mac_ver() function

Ezio Melotti ezio.melotti at gmail.com
Wed Jun 1 12:37:09 CEST 2011


Hi,

On 01/06/2011 13.28, victor.stinner wrote:
> http://hg.python.org/cpython/rev/35212b113730
> changeset:   70574:35212b113730
> user:        Victor Stinner<victor.stinner at haypocalc.com>
> date:        Wed Jun 01 12:28:04 2011 +0200
> summary:
>    test.support: add requires_mac_ver() function

I would expect this to be a decorator, similar to requires_IEEE_754 and 
requires_zlib.

> Add also linux_version() to __all__.

For consistency, this should be a decorator too, possibly named 
requires_linux_ver().
A requires_windows(_ver) sounds like a useful addition too, given the 
number of tests that are specific to Windows.

> files:
>    Lib/test/support.py   |  22 +++++++++++++++++++++-
>    Lib/test/test_math.py |   7 ++++---
>    2 files changed, 25 insertions(+), 4 deletions(-)
>
>
> diff --git a/Lib/test/support.py b/Lib/test/support.py
> --- a/Lib/test/support.py
> +++ b/Lib/test/support.py
> @@ -37,7 +37,8 @@
>       "Error", "TestFailed", "ResourceDenied", "import_module",
>       "verbose", "use_resources", "max_memuse", "record_original_stdout",
>       "get_original_stdout", "unload", "unlink", "rmtree", "forget",
> -    "is_resource_enabled", "requires", "find_unused_port", "bind_port",
> +    "is_resource_enabled", "requires", "linux_version", "requires_mac_ver",
> +    "find_unused_port", "bind_port",
>       "IPV6_ENABLED", "is_jython", "TESTFN", "HOST", "SAVEDCWD", "temp_cwd",
>       "findfile", "sortdict", "check_syntax_error", "open_urlresource",
>       "check_warnings", "CleanImport", "EnvironmentVarGuard", "TransientResource",
> @@ -299,6 +300,25 @@
>       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.
> +
> +    For example, support.requires_linux_version(10, 5) raises SkipTest if the

This should be requires_mac_ver

> +    version is less 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))
> +
>   HOST = 'localhost'
>
>   def find_unused_port(family=socket.AF_INET, socktype=socket.SOCK_STREAM):
> 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
> @@ -2,6 +2,7 @@
>   # XXXX Should not do tests around zero only
>
>   from test.support import run_unittest, verbose, requires_IEEE_754
> +from test import support
>   import unittest
>   import math
>   import os
> @@ -669,10 +670,10 @@
>           self.assertTrue(math.isnan(math.log2(NAN)))
>
>       @requires_IEEE_754
> -    @unittest.skipIf(sys.platform == 'darwin'
> -                     and platform.mac_ver()[0].startswith('10.4.'),
> -                     'Mac OS X Tiger log2() is not accurate enough')
>       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)]
>

Best Regards,
Ezio Melotti


More information about the Python-Dev mailing list