示例#1
0
 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"
示例#2
0
 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"
示例#3
0
 def test_ignore_key(self):
     params = interface._MethodParameters([
         {
             "name": "key",
             "type": "string",
             "optional": False,
             "description": "test parameter",
         },
     ])
     assert "key" not in params
示例#4
0
 def test_ignore_key(self):
     params = interface._MethodParameters([
         {
             "name": "key",
             "type": "string",
             "optional": False,
             "description": "test parameter",
         },
     ])
     assert "key" not in params
示例#5
0
 def test_validate_skip_missing_optional(self):
     params = interface._MethodParameters([
         {
             "name": "test",
             "type": "string",
             "optional": True,
             "description": "test parameter",
         },
     ])
     assert params.validate(test=None) == {}
示例#6
0
 def test_validate_skip_missing_optional(self):
     params = interface._MethodParameters([
         {
             "name": "test",
             "type": "string",
             "optional": True,
             "description": "test parameter",
         },
     ])
     assert params.validate(test=None) == {}
示例#7
0
 def test_validate_missing_mandatory(self):
     params = interface._MethodParameters([
         {
             "name": "test",
             "type": "string",
             "optional": False,
             "description": "test parameter",
         },
     ])
     with pytest.raises(TypeError):
         params.validate()
示例#8
0
 def test_validate_missing_mandatory(self):
     params = interface._MethodParameters([
         {
             "name": "test",
             "type": "string",
             "optional": False,
             "description": "test parameter",
         },
     ])
     with pytest.raises(TypeError):
         params.validate()
示例#9
0
 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"] == ""
示例#10
0
 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"] == ""
示例#11
0
 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"
示例#12
0
 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"
示例#13
0
 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"
示例#14
0
 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"]
示例#15
0
 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",
             }
         ])
示例#16
0
 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"]
示例#17
0
 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"
示例#18
0
 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",
         }])
示例#19
0
 def test_signature_no_params(self):
     params = interface._MethodParameters([])
     assert params.signature == "self"
示例#20
0
 def test_signature_no_params(self):
     params = interface._MethodParameters([])
     assert params.signature == "self"