def test_signature(self): params = interface._MethodParameters([ { "name": "zebra", "type": "string", "optional": False, "description": "test parameter", }, { "name": "aardvark", "type": "string", "optional": False, "description": "test parameter", }, { "name": "xenopus", "type": "string", "optional": True, "description": "test parameter", }, { "name": "bullfrog", "type": "string", "optional": True, "description": "test parameter", }, ]) assert params.signature == \ "self, aardvark, zebra, bullfrog=None, xenopus=None"
def test_ignore_key(self): params = interface._MethodParameters([ { "name": "key", "type": "string", "optional": False, "description": "test parameter", }, ]) assert "key" not in params
def test_validate_skip_missing_optional(self): params = interface._MethodParameters([ { "name": "test", "type": "string", "optional": True, "description": "test parameter", }, ]) assert params.validate(test=None) == {}
def test_validate_missing_mandatory(self): params = interface._MethodParameters([ { "name": "test", "type": "string", "optional": False, "description": "test parameter", }, ]) with pytest.raises(TypeError): params.validate()
def test_missing_description(self): params = interface._MethodParameters([ { "name": "test", "type": "string", "optional": False, }, ]) param = params["test"] assert param["name"] == "test" assert param["type"] == "string" assert param["optional"] is False assert param["description"] == ""
def test_unknown_type(self): params = interface._MethodParameters([ { "name": "test", "type": "", "optional": False, "description": "test parameter", }, ]) param = params["test"] assert param["name"] == "test" assert param["type"] == "string" assert param["optional"] is False assert param["description"] == "test parameter"
def test_validate_type_conversion(self, monkeypatch): validator = mock.Mock() monkeypatch.setattr(interface, "PARAMETER_TYPES", {"string": validator}) params = interface._MethodParameters([ { "name": "test", "type": "string", "optional": False, "description": "test parameter", }, ]) assert params.validate(test="raw value") == { "test": validator.return_value} assert validator.called assert validator.call_args[0][0] == "raw value"
def test_sorted(self): params = interface._MethodParameters([ { "name": "zebra", "type": "string", "optional": False, "description": "test parameter", }, { "name": "aardvark", "type": "string", "optional": False, "description": "test parameter", }, ]) assert list(params.keys()) == ["aardvark", "zebra"]
def test_duplicate_name(self): with pytest.raises(NameError): params = interface._MethodParameters([ { "name": "test", "type": "string", "optional": False, "description": "test parameter", }, { "name": "test", "type": "string", "optional": False, "description": "test parameter", } ])
def test_validate_type_conversion(self, monkeypatch): validator = mock.Mock() monkeypatch.setattr(interface, "PARAMETER_TYPES", {"string": validator}) params = interface._MethodParameters([ { "name": "test", "type": "string", "optional": False, "description": "test parameter", }, ]) assert params.validate(test="raw value") == { "test": validator.return_value } assert validator.called assert validator.call_args[0][0] == "raw value"
def test_duplicate_name(self): with pytest.raises(NameError): params = interface._MethodParameters([{ "name": "test", "type": "string", "optional": False, "description": "test parameter", }, { "name": "test", "type": "string", "optional": False, "description": "test parameter", }])
def test_signature_no_params(self): params = interface._MethodParameters([]) assert params.signature == "self"