def test_bad_arguments(self, args): # Can't put lazy fixture in a list inside of parametrize... if not isinstance(args, list): args = [args] with pytest.raises(PluginParamError): parameters(*args)
def test_equivalence(self, param_definition): # We need two separate copies of _cmd here so just invoke cwd() directly func1 = parameter(cmd(), **param_definition) func2 = parameters([param_definition], cmd()) assert_parameter_equal(func1._command.parameters[0], func2._command.parameters[0])
def test_dict_values(self, cmd, param_definition, wrap_functions): test_mock = Mock() wrapped = parameters({"foo": param_definition}.values(), cmd) assert len(cmd._command.parameters) == 1 assert cmd._command.parameters[0].key == "foo" assert wrapped(self, test_mock) == test_mock
def test_bad_application(self): """I don't even know how you would do this. Something like: .. code-block:: python @parameters([{"key": "foo", ...}]) some non-callable thing Which isn't valid syntax. But if it WERE, it would be handled! """ with pytest.raises(PluginParamError, match=r"callable"): partial = parameters([{"key": "foo"}]) partial("not a callable")
def test_equivalence(self, param_definition): # We need two separate copies of _cmd here, but pytest doesn't like you calling # fixtures directly. So just re-define the function here: def cmd(_, foo): """Docstring""" return foo func1 = parameter(cmd, **param_definition) func2 = parameters([param_definition], cmd) assert_parameter_equal( func1._command.parameters[0], func2._command.parameters[0] )
def test_parameters(self, cmd): with warnings.catch_warnings(record=True): partial = parameters([{"key": "foo"}]) cmd = partial(cmd) assert _parse_method(cmd) is not None
def test_parameters_wrapper(self, cmd, param_definition, wrap_functions): test_mock = Mock() wrapped = parameters([param_definition], cmd) assert wrapped(self, test_mock) == test_mock
def test_bad_args(self, arg1, arg2): with pytest.raises(PluginParamError): parameters(arg1, arg2)
def test_bad_arity(self, args): # Must be called with either just one arg, or one arg + the function with pytest.raises(PluginParamError) as ex: parameters(*args) assert "single argument" in str(ex)