Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
@with_signature(new_sig)
def depends_on(*steps, **kwargs):
"""
Decorates a test step object so as to automatically mark it as skipped (default) or failed if the dependency
has not succeeded.
:param steps: a list of test steps that this step depends on. They can be anything, but typically they are non-test
(not prefixed with 'test') functions.
:param fail_instead_of_skip: if set to True, the test will be marked as failed instead of skipped when the
dependencies have not succeeded.
:return:
"""
# python 2 compatibility: no keyword arguments can follow an *args.
fail_instead_of_skip = kwargs.pop('fail_instead_of_skip', _FAIL_INSTEAD_OF_SKIP_DEFAULT)
if len(kwargs) > 0:
raise ValueError("Invalid argument(s): " + str(kwargs.keys()))
@with_signature("%s(%s)" % (root_fixture_name, argnames))
def _root_fixture(**kwargs):
return tuple(kwargs[k] for k in argnames_lst)
@with_signature("%s(%s, request)" % (name, ', '.join(f_names_args)))
def _new_fixture(request, **all_fixtures):
if not is_used_request(request):
return NOT_USED
else:
alternative = request.param
if isinstance(alternative, UnionFixtureAlternative):
fixture_to_use = alternative.fixture_name
return all_fixtures[fixture_to_use]
else:
raise TypeError("Union Fixture %s received invalid parameter type: %s. Please report this issue."
"" % (name, alternative.__class__))
@with_signature("%s(%s)" % (root_fixture_name, argnames))
def _root_fixture(**_kwargs):
return tuple(_kwargs[k] for k in argnames_lst)
@makefun.with_signature(f"__init__(self, {', '.join(param_names)}, name='value')")
def dist_init(self, *args, **kwargs):
return Distribution2.__init__(self, *tuple(kwargs.values())[:-1], name=kwargs['name'])
@with_signature(None,
func_name=function_for_metadata.__name__,
doc=function_for_metadata.__doc__,
module_name=function_for_metadata.__module__)
def new_decorator(*_):
"""
Code for your decorator, generated by decopatch to handle the case when it is called without parenthesis
"""
if len(_) == 0:
# called with no args BUT parenthesis: @foo_decorator().
return with_parenthesis_usage(decorator_function, *_)
elif len(_) == 1:
first_arg_value = _[0]
if can_arg_be_a_decorator_target(first_arg_value):
# called with no arg NOR parenthesis: @foo_decorator
return no_parenthesis_usage(decorator_function, first_arg_value)
@with_signature(new_sig)
def validate_out(*validation_func, # type: ValidationFuncs
**kwargs):
# type: (...) -> Callable
"""
A decorator to apply function output validation to this function's output, with the provided base validation
function(s). You may use several such decorators on a given function as long as they are stacked on top of each
other (no external decorator in the middle)
:param validation_func: the base validation function or list of base validation functions to use. A callable, a
tuple(callable, help_msg_str), a tuple(callable, failure_type), tuple(callable, help_msg_str, failure_type)
or a list of several such elements.
Tuples indicate an implicit `failure_raiser`.
[mini_lambda](https://smarie.github.io/python-mini-lambda/) expressions can be used instead
of callables, they will be transformed to functions automatically.
:param error_type: a subclass of ValidationError to raise in case of validation failure. By default a
ValidationError will be raised with the provided help_msg
@with_signature(None if sig_info.use_signature_trick else sig_info.exposed_signature,
func_name=function_for_metadata.__name__,
doc=function_for_metadata.__doc__,
module_name=function_for_metadata.__module__)
def new_decorator(*args, **kwargs):
"""
Code for your decorator, generated by decopatch to handle the case when it is called without parenthesis
"""
# disambiguate
dk = DecoratorUsageInfo(sig_info, args, kwargs)
disambiguation_result = disambiguate_call(dk, disambiguator)
# call
return call_in_appropriate_mode(impl_function, dk, disambiguation_result)
@with_signature(new_sig)
def assert_valid(name, # type: str
value, # type: Any
*validation_func, # type: ValidationFuncs
**kwargs):
"""
Validates value `value` using validation function(s) `base_validator_s`.
As opposed to `is_valid`, this function raises a `ValidationError` if validation fails.
It is therefore designed to be used for defensive programming, in an independent statement before the code that you
intent to protect.
```python
assert_valid(x, isfinite):
...
```