Skip to content

Commit

Permalink
Fix bug in REQUIRES for platform_implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Erotemic committed Aug 22, 2021
1 parent a5b264f commit 5f2786b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

## Version 0.15.7 - Unreleased

### Fixed
* Bug in REQUIRES state did not respect `python_implementation` arguments

## Version 0.15.6 - Released 2021-08-08

Expand Down
15 changes: 11 additions & 4 deletions xdoctest/directive.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,12 @@ def extract(cls, text):
directive pattern. Because ``xdoctest`` is parsing the text, this issue
does not occur.
Example:
>>> from xdoctest.directive import Directive, RuntimeState
>>> state = RuntimeState()
>>> state.update(Directive.extract('# xdoctest: +REQUIRES(CPYTHON)'))
>>> list([0].effects()[0]
Example:
>>> from xdoctest.directive import Directive
>>> text = '# xdoc: + SKIP'
Expand Down Expand Up @@ -409,7 +415,7 @@ def __nice__(self):
return '{}{}'.format(prefix, self.name)

def _unpack_args(self, num):
warnings.warning('Deprecated and will be removed', DeprecationWarning)
warnings.warn('Deprecated and will be removed', DeprecationWarning)
nargs = self.args
if len(nargs) != 1:
raise TypeError(
Expand All @@ -418,7 +424,7 @@ def _unpack_args(self, num):
return self.args

def effect(self, argv=None, environ=None):
warnings.warning('Deprecated use effects', DeprecationWarning)
warnings.warn('Deprecated use effects', DeprecationWarning)
effects = self.effects(argv=argv, environ=environ)
if len(effects) > 1:
raise Exception('Old method cannot hanldle multiple effects')
Expand Down Expand Up @@ -572,6 +578,7 @@ def _is_requires_satisfied(arg, argv=None, environ=None):
bool: flag - True if the requirement is met
Example:
>>> from xdoctest.directive import * # NOQA
>>> _is_requires_satisfied('PY2', argv=[])
>>> _is_requires_satisfied('PY3', argv=[])
>>> _is_requires_satisfied('cpython', argv=[])
Expand Down Expand Up @@ -651,12 +658,12 @@ def _is_requires_satisfied(arg, argv=None, environ=None):
else:
raise ValueError('Too many expr_parts={}'.format(expr_parts))
elif arg_lower in SYS_PLATFORM_TAGS:
flag = sys.platform.startswith(arg_lower)
flag = sys.platform.lower().startswith(arg_lower)
elif arg_lower in OS_NAME_TAGS:
flag = os.name.startswith(arg_lower)
elif arg_lower in PY_IMPL_TAGS:
import platform
flag = platform.python_implementation().startswith(arg_lower)
flag = platform.python_implementation().lower().startswith(arg_lower)
elif arg_lower in PY_VER_TAGS:
if sys.version_info[0] == 2: # nocover
flag = arg_lower == 'py2'
Expand Down

0 comments on commit 5f2786b

Please sign in to comment.