[3.8] bpo-41009: fix requires_OS_version() class decorator (GH-20942) (GH-20948)

Signed-off-by: Christian Heimes <christian@python.org>

Automerge-Triggered-By: @tiran.
(cherry picked from commit bb6ec14479)

Co-authored-by: Christian Heimes <christian@python.org>
This commit is contained in:
Christian Heimes 2020-06-25 14:18:43 +02:00 committed by GitHub
parent f547d06ea7
commit 8075fe199b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 19 deletions

View File

@ -586,25 +586,25 @@ def _requires_unix_version(sysname, min_version):
For example, @_requires_unix_version('FreeBSD', (7, 2)) raises SkipTest if
the FreeBSD version is less than 7.2.
"""
def decorator(func):
@functools.wraps(func)
def wrapper(*args, **kw):
if platform.system() == sysname:
version_txt = platform.release().split('-', 1)[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(
"%s version %s or higher required, not %s"
% (sysname, min_version_txt, version_txt))
return func(*args, **kw)
wrapper.min_version = min_version
return wrapper
return decorator
import platform
min_version_txt = '.'.join(map(str, min_version))
version_txt = platform.release().split('-', 1)[0]
if platform.system() == sysname:
try:
version = tuple(map(int, version_txt.split('.')))
except ValueError:
skip = False
else:
skip = version < min_version
else:
skip = False
return unittest.skipIf(
skip,
f"{sysname} version {min_version_txt} or higher required, not "
f"{version_txt}"
)
def requires_freebsd_version(*min_version):
"""Decorator raising SkipTest if the OS is FreeBSD and the FreeBSD version is

View File

@ -0,0 +1,2 @@
Fix use of ``support.require_{linux|mac|freebsd}_version()`` decorators as
class decorator.