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

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 requiresmacver() function

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

Add also linuxversion() 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/testmath.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", "importmodule", "verbose", "useresources", "maxmemuse", "recordoriginalstdout", "getoriginalstdout", "unload", "unlink", "rmtree", "forget", - "isresourceenabled", "requires", "findunusedport", "bindport", + "isresourceenabled", "requires", "linuxversion", "requiresmacver", + "findunusedport", "bindport", "IPV6ENABLED", "isjython", "TESTFN", "HOST", "SAVEDCWD", "tempcwd", "findfile", "sortdict", "checksyntaxerror", "openurlresource", "checkwarnings", "CleanImport", "EnvironmentVarGuard", "TransientResource", @@ -299,6 +300,25 @@ except ValueError: return 0, 0, 0 +def requiresmacver(*minversion): + """Raise SkipTest if the OS is Mac OS X and the OS X version if less than + minversion. + + For example, support.requireslinuxversion(10, 5) raises SkipTest if the

This should be requires_mac_ver

+ version is less than 10.5. + """ + if sys.platform != 'darwin': + return + versiontxt = platform.macver()[0] + try: + version = tuple(map(int, versiontxt.split('.'))) + except ValueError: + return + if version< minversion: + minversiontxt = '.'.join(map(str, minversion)) + raise unittest.SkipTest("Mac OS X %s or higher required, not %s" + % (minversiontxt, versiontxt)) + HOST = 'localhost'

def findunusedport(family=socket.AFINET, socktype=socket.SOCKSTREAM): diff --git a/Lib/test/testmath.py b/Lib/test/testmath.py --- a/Lib/test/testmath.py +++ b/Lib/test/testmath.py @@ -2,6 +2,7 @@ # XXXX Should not do tests around zero only from test.support import rununittest, verbose, requiresIEEE754 +from test import support import unittest import math import os @@ -669,10 +670,10 @@ self.assertTrue(math.isnan(math.log2(NAN))) @requiresIEEE754 - @unittest.skipIf(sys.platform == 'darwin' - and platform.macver()[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.requiresmacver(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