diff options
author | shadchin <[email protected]> | 2022-02-10 16:44:30 +0300 |
---|---|---|
committer | Daniil Cherednik <[email protected]> | 2022-02-10 16:44:30 +0300 |
commit | 2598ef1d0aee359b4b6d5fdd1758916d5907d04f (patch) | |
tree | 012bb94d777798f1f56ac1cec429509766d05181 /contrib/python/pytest/py2/_pytest/mark/structures.py | |
parent | 6751af0b0c1b952fede40b19b71da8025b5d8bcf (diff) |
Restoring authorship annotation for <[email protected]>. Commit 1 of 2.
Diffstat (limited to 'contrib/python/pytest/py2/_pytest/mark/structures.py')
-rw-r--r-- | contrib/python/pytest/py2/_pytest/mark/structures.py | 200 |
1 files changed, 100 insertions, 100 deletions
diff --git a/contrib/python/pytest/py2/_pytest/mark/structures.py b/contrib/python/pytest/py2/_pytest/mark/structures.py index aaebe927be7..71adac02bc6 100644 --- a/contrib/python/pytest/py2/_pytest/mark/structures.py +++ b/contrib/python/pytest/py2/_pytest/mark/structures.py @@ -1,20 +1,20 @@ -# -*- coding: utf-8 -*- +# -*- coding: utf-8 -*- import inspect import warnings from collections import namedtuple from operator import attrgetter import attr -import six +import six -from ..compat import ascii_escaped -from ..compat import ATTRS_EQ_FIELD +from ..compat import ascii_escaped +from ..compat import ATTRS_EQ_FIELD from ..compat import getfslineno from ..compat import MappingMixin from ..compat import NOTSET -from _pytest.deprecated import PYTEST_PARAM_UNKNOWN_KWARGS +from _pytest.deprecated import PYTEST_PARAM_UNKNOWN_KWARGS from _pytest.outcomes import fail -from _pytest.warning_types import PytestUnknownMarkWarning +from _pytest.warning_types import PytestUnknownMarkWarning EMPTY_PARAMETERSET_OPTION = "empty_parameter_set_mark" @@ -48,7 +48,7 @@ def get_empty_parameterset_mark(config, argnames, func): f_name = func.__name__ _, lineno = getfslineno(func) raise Collector.CollectError( - "Empty parameter set in '%s' at line %d" % (f_name, lineno + 1) + "Empty parameter set in '%s' at line %d" % (f_name, lineno + 1) ) else: raise LookupError(requested_mark) @@ -64,90 +64,90 @@ def get_empty_parameterset_mark(config, argnames, func): class ParameterSet(namedtuple("ParameterSet", "values, marks, id")): @classmethod - def param(cls, *values, **kwargs): - marks = kwargs.pop("marks", ()) + def param(cls, *values, **kwargs): + marks = kwargs.pop("marks", ()) if isinstance(marks, MarkDecorator): marks = (marks,) else: assert isinstance(marks, (tuple, list, set)) - id_ = kwargs.pop("id", None) - if id_ is not None: - if not isinstance(id_, six.string_types): - raise TypeError( - "Expected id to be a string, got {}: {!r}".format(type(id_), id_) - ) - id_ = ascii_escaped(id_) - - if kwargs: - warnings.warn( - PYTEST_PARAM_UNKNOWN_KWARGS.format(args=sorted(kwargs)), stacklevel=3 - ) + id_ = kwargs.pop("id", None) + if id_ is not None: + if not isinstance(id_, six.string_types): + raise TypeError( + "Expected id to be a string, got {}: {!r}".format(type(id_), id_) + ) + id_ = ascii_escaped(id_) + + if kwargs: + warnings.warn( + PYTEST_PARAM_UNKNOWN_KWARGS.format(args=sorted(kwargs)), stacklevel=3 + ) return cls(values, marks, id_) @classmethod - def extract_from(cls, parameterset, force_tuple=False): + def extract_from(cls, parameterset, force_tuple=False): """ :param parameterset: a legacy style parameterset that may or may not be a tuple, and may or may not be wrapped into a mess of mark objects - :param force_tuple: + :param force_tuple: enforce tuple wrapping so single argument tuple values don't get decomposed and break tests """ if isinstance(parameterset, cls): return parameterset - if force_tuple: + if force_tuple: return cls.param(parameterset) - else: - return cls(parameterset, marks=[], id=None) + else: + return cls(parameterset, marks=[], id=None) - @staticmethod - def _parse_parametrize_args(argnames, argvalues, *args, **kwargs): + @staticmethod + def _parse_parametrize_args(argnames, argvalues, *args, **kwargs): if not isinstance(argnames, (tuple, list)): argnames = [x.strip() for x in argnames.split(",") if x.strip()] force_tuple = len(argnames) == 1 else: force_tuple = False - return argnames, force_tuple - - @staticmethod - def _parse_parametrize_parameters(argvalues, force_tuple): - return [ - ParameterSet.extract_from(x, force_tuple=force_tuple) for x in argvalues + return argnames, force_tuple + + @staticmethod + def _parse_parametrize_parameters(argvalues, force_tuple): + return [ + ParameterSet.extract_from(x, force_tuple=force_tuple) for x in argvalues ] - - @classmethod - def _for_parametrize(cls, argnames, argvalues, func, config, function_definition): - argnames, force_tuple = cls._parse_parametrize_args(argnames, argvalues) - parameters = cls._parse_parametrize_parameters(argvalues, force_tuple) + + @classmethod + def _for_parametrize(cls, argnames, argvalues, func, config, function_definition): + argnames, force_tuple = cls._parse_parametrize_args(argnames, argvalues) + parameters = cls._parse_parametrize_parameters(argvalues, force_tuple) del argvalues if parameters: # check all parameter sets have the correct number of values for param in parameters: if len(param.values) != len(argnames): - msg = ( - '{nodeid}: in "parametrize" the number of names ({names_len}):\n' - " {names}\n" - "must be equal to the number of values ({values_len}):\n" - " {values}" - ) - fail( - msg.format( - nodeid=function_definition.nodeid, - values=param.values, - names=argnames, - names_len=len(argnames), - values_len=len(param.values), - ), - pytrace=False, + msg = ( + '{nodeid}: in "parametrize" the number of names ({names_len}):\n' + " {names}\n" + "must be equal to the number of values ({values_len}):\n" + " {values}" ) + fail( + msg.format( + nodeid=function_definition.nodeid, + values=param.values, + names=argnames, + names_len=len(argnames), + values_len=len(param.values), + ), + pytrace=False, + ) else: # empty parameter set (likely computed at runtime): create a single - # parameter set with NOTSET values, with the "empty parameter set" mark applied to it + # parameter set with NOTSET values, with the "empty parameter set" mark applied to it mark = get_empty_parameterset_mark(config, argnames, func) parameters.append( ParameterSet(values=(NOTSET,) * len(argnames), marks=[mark], id=None) @@ -160,9 +160,9 @@ class Mark(object): #: name of the mark name = attr.ib(type=str) #: positional arguments of the mark decorator - args = attr.ib() # List[object] + args = attr.ib() # List[object] #: keyword arguments of the mark decorator - kwargs = attr.ib() # Dict[str, object] + kwargs = attr.ib() # Dict[str, object] def combined_with(self, other): """ @@ -170,7 +170,7 @@ class Mark(object): :type other: Mark :rtype: Mark - combines by appending args and merging the mappings + combines by appending args and merging the mappings """ assert self.name == other.name return Mark( @@ -247,7 +247,7 @@ class MarkDecorator(object): func = args[0] is_class = inspect.isclass(func) if len(args) == 1 and (istestfunc(func) or is_class): - store_mark(func, self.mark) + store_mark(func, self.mark) return func return self.with_args(*args, **kwargs) @@ -269,13 +269,13 @@ def normalize_mark_list(mark_list): :type mark_list: List[Union[Mark, Markdecorator]] :rtype: List[Mark] """ - extracted = [ - getattr(mark, "mark", mark) for mark in mark_list - ] # unpack MarkDecorator - for mark in extracted: - if not isinstance(mark, Mark): - raise TypeError("got {!r} instead of Mark".format(mark)) - return [x for x in extracted if isinstance(x, Mark)] + extracted = [ + getattr(mark, "mark", mark) for mark in mark_list + ] # unpack MarkDecorator + for mark in extracted: + if not isinstance(mark, Mark): + raise TypeError("got {!r} instead of Mark".format(mark)) + return [x for x in extracted if isinstance(x, Mark)] def store_mark(obj, mark): @@ -301,43 +301,43 @@ class MarkGenerator(object): on the ``test_function`` object. """ _config = None - _markers = set() + _markers = set() def __getattr__(self, name): if name[0] == "_": raise AttributeError("Marker name must NOT start with underscore") - + if self._config is not None: - # We store a set of markers as a performance optimisation - if a mark - # name is in the set we definitely know it, but a mark may be known and - # not in the set. We therefore start by updating the set! - if name not in self._markers: - for line in self._config.getini("markers"): - # example lines: "skipif(condition): skip the given test if..." - # or "hypothesis: tests which use Hypothesis", so to get the - # marker name we split on both `:` and `(`. - if line == "ya:external": - marker = line - else: - marker = line.split(":")[0].split("(")[0].strip() - self._markers.add(marker) - - # If the name is not in the set of known marks after updating, - # then it really is time to issue a warning or an error. - if name not in self._markers: - if self._config.option.strict_markers: - fail( - "{!r} not found in `markers` configuration option".format(name), - pytrace=False, - ) - else: - warnings.warn( - "Unknown pytest.mark.%s - is this a typo? You can register " - "custom marks to avoid this warning - for details, see " - "https://docs.pytest.org/en/latest/mark.html" % name, - PytestUnknownMarkWarning, - ) - + # We store a set of markers as a performance optimisation - if a mark + # name is in the set we definitely know it, but a mark may be known and + # not in the set. We therefore start by updating the set! + if name not in self._markers: + for line in self._config.getini("markers"): + # example lines: "skipif(condition): skip the given test if..." + # or "hypothesis: tests which use Hypothesis", so to get the + # marker name we split on both `:` and `(`. + if line == "ya:external": + marker = line + else: + marker = line.split(":")[0].split("(")[0].strip() + self._markers.add(marker) + + # If the name is not in the set of known marks after updating, + # then it really is time to issue a warning or an error. + if name not in self._markers: + if self._config.option.strict_markers: + fail( + "{!r} not found in `markers` configuration option".format(name), + pytrace=False, + ) + else: + warnings.warn( + "Unknown pytest.mark.%s - is this a typo? You can register " + "custom marks to avoid this warning - for details, see " + "https://docs.pytest.org/en/latest/mark.html" % name, + PytestUnknownMarkWarning, + ) + return MarkDecorator(Mark(name, (), {})) @@ -381,8 +381,8 @@ class NodeKeywords(MappingMixin): return "<NodeKeywords for node %s>" % (self.node,) -# mypy cannot find this overload, remove when on attrs>=19.2 [email protected](hash=False, **{ATTRS_EQ_FIELD: False}) # type: ignore +# mypy cannot find this overload, remove when on attrs>=19.2 [email protected](hash=False, **{ATTRS_EQ_FIELD: False}) # type: ignore class NodeMarkers(object): """ internal structure for storing marks belonging to a node |