Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3.7] bpo-41009: fix requires_OS_version() class decorator (GH-20942) #20949

Merged
merged 1 commit into from
Jun 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 19 additions & 19 deletions Lib/test/support/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -560,25 +560,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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix use of ``support.require_{linux|mac|freebsd}_version()`` decorators as
class decorator.