Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_construct_arguments_with_kwargs_for_posargs_does_not_raise():
Signature(bariza).construct_arguments([], {'a': 4, 'b': 3, 'c': 2}, {})
s = Signature(FunCTIonWithCAPItals)
s.construct_arguments([], {'a': 4, 'b': 3, 'c': 2, 'd': 6}, {})
def test_construct_arguments_with_kwargswildcard_doesnt_raise():
kwargs = {'zimbabwe': 23}
Signature(__double_underscore__).construct_arguments([1, 2], kwargs, {})
Signature(FunCTIonWithCAPItals).construct_arguments(
[1, 2, 3], kwargs, {})
def test_constructor_extract_function_name(function, name):
s = Signature(function)
assert s.name == name
def test_unicode_(func, expected):
assert str(Signature(func)) == expected
def test_construct_arguments_does_not_overwrite_args_and_kwargs():
s = Signature(bariza)
args, kwargs = s.construct_arguments([1, 2], {'c': 3},
{'a': 6, 'b': 6, 'c': 6})
assert args == [1, 2]
assert kwargs == {'c': 3}
def test_unicode_special():
str_signature = "complex_function_name(a=5, b='fo', c=9)"
assert str_signature in str(Signature(complex_function_name))
def test_construct_arguments_completes_kwargs_from_options():
s = Signature(bariza)
args, kwargs = s.construct_arguments([2, 4], {}, {"c": 6})
assert args == [2, 4]
assert kwargs == {"c": 6}
s = Signature(complex_function_name)
args, kwargs = s.construct_arguments([], {"c": 6, "b": 7}, {"a": 1})
assert args == []
assert kwargs == {"a": 1, "c": 6, "b": 7}
s = Signature(_name_with_underscore_)
args, kwargs = s.construct_arguments([], {}, {"fo": 7, "bar": 6})
assert args == []
assert kwargs == {"fo": 7, "bar": 6}
def test_construct_arguments_with_duplicate_args_raises_typeerror():
multiple_values = re.compile(".*multiple values.*")
with pytest.raises(TypeError) as excinfo:
s = Signature(bariza)
s.construct_arguments([1, 2, 3], {'a': 4, 'b': 5}, {})
assert multiple_values.match(excinfo.value.args[0])
with pytest.raises(TypeError) as excinfo:
s = Signature(complex_function_name)
s.construct_arguments([1], {'a': 4}, {})
assert multiple_values.match(excinfo.value.args[0])
with pytest.raises(TypeError) as excinfo:
s = Signature(FunCTIonWithCAPItals)
s.construct_arguments([1, 2, 3], {'c': 6}, {})
assert multiple_values.match(excinfo.value.args[0])
def test_construct_arguments_with_expected_kwargs_does_not_raise():
s = Signature(complex_function_name)
s.construct_arguments([], {'a': 4, 'b': 3, 'c': 2}, {})
s = Signature(FunCTIonWithCAPItals)
s.construct_arguments([1, 2], {'c': 5}, {})
Decorator for adding an option hook function.
An option hook is a function that is called right before a run
is created. It receives (and potentially modifies) the options
dictionary. That is, the dictionary of commandline options used for
this run.
Notes
-----
The decorated function MUST have an argument called options.
The options also contain ``'COMMAND'`` and ``'UPDATE'`` entries,
but changing them has no effect. Only modification on
flags (entries starting with ``'--'``) are considered.
"""
sig = Signature(function)
if "options" not in sig.arguments:
raise KeyError(
"option_hook functions must have an argument called"
" 'options', but got {}".format(sig.arguments)
)
self.option_hooks.append(function)
return function