Exemplo n.º 1
0
    def test_recreate(self):
        @method_takes(
            "arg1",
            StringMeta("Arg1"),
            REQUIRED,
            "extra",
            StringMeta(),
            REQUIRED,
        )
        def method1():
            pass

        @method_takes(
            "arg8",
            StringMeta("Arg8"),
            REQUIRED,
            "arg3",
            StringMeta("Arg3"),
            "32",
            "arg4",
            StringMeta("Arg4"),
            OPTIONAL,
        )
        def method2():
            pass

        @method_takes(
            "arg8",
            StringMeta("Arg8"),
            "2",
            "arg3",
            StringMeta("Arg3"),
            "33",
        )
        def method3():
            pass

        m = MethodModel("Test")
        m.recreate_from_others(
            [method1.MethodModel, method2.MethodModel, method3.MethodModel],
            without=["extra"])

        itakes = MapMeta()
        elements = OrderedDict()
        elements["arg1"] = StringMeta("Arg1")
        elements["arg8"] = StringMeta("Arg8")
        elements["arg3"] = StringMeta("Arg3")
        elements["arg4"] = StringMeta("Arg4")
        itakes.set_elements(elements)
        itakes.set_required(["arg1"])
        defaults = OrderedDict()
        defaults["arg8"] = "2"
        defaults["arg3"] = "33"
        assert m.takes.to_dict() == itakes.to_dict()
        assert m.returns.to_dict() == MapMeta().to_dict()
        assert m.defaults == defaults
Exemplo n.º 2
0
    def test_make_view(self):
        method_view = self.o._make_appropriate_view(self.context,
                                                    self.part.my_method)
        attribute_view = self.o._make_appropriate_view(self.context,
                                                       self.part.myAttribute)
        dict_view = self.o._make_appropriate_view(self.context, {
            'a': self.part.myAttribute,
            'm': self.part.my_method
        })
        list_view = self.o._make_appropriate_view(
            self.context, [self.part.myAttribute, self.part.my_method])

        model = Model()
        model_view = self.o._make_appropriate_view(self.context, model)

        none_view = self.o._make_appropriate_view(self.context, None)

        block_data = BlockModel()
        block_data.set_endpoint_data("attr",
                                     StringMeta().create_attribute_model())
        block_data.set_endpoint_data("method", MethodModel())
        block_data.set_notifier_path(MagicMock(), ["block"])
        block_view = self.o._make_appropriate_view(self.context, block_data)

        # Todo check create_part_contexts worked
        self.o.create_part_contexts()

        # using __call__
        assert method_view().ret == 'world'
        assert attribute_view.value == "hello_block"
        assert dict_view['a'].value == "hello_block"
        assert list_view[0].value == "hello_block"
Exemplo n.º 3
0
 def test_from_dict(self):
     m = MethodModel.from_dict(self.serialized)
     assert m.takes.to_dict() == self.takes.to_dict()
     assert m.defaults == self.serialized["defaults"]
     assert m.tags == ()
     assert m.writeable == True
     assert m.label == ""
     assert m.returns.to_dict() == MapMeta().to_dict()
Exemplo n.º 4
0
 def setUp(self):
     self.data = BlockModel()
     self.data.set_endpoint_data("attr",
                                 StringMeta().create_attribute_model())
     self.data.set_endpoint_data("method", MethodModel())
     self.data.set_notifier_path(Mock(), ["block"])
     self.controller = Mock()
     self.context = Mock()
     self.o = make_block_view(self.controller, self.context, self.data)
Exemplo n.º 5
0
 def test_to_dict(self):
     m = MethodModel("test_description")
     m.set_takes(self.takes)
     m.set_defaults(self.serialized["defaults"])
     assert m.to_dict() == self.serialized
Exemplo n.º 6
0
 def test_set_label(self):
     m = MethodModel("test_description")
     m.set_label("new_label")
     assert "new_label" == m.label
Exemplo n.º 7
0
 def test_init(self):
     m = MethodModel("test_description")
     assert "test_description" == m.description
     assert "malcolm:core/Method:1.0" == m.typeid
     assert "" == m.label
Exemplo n.º 8
0
 def setUp(self):
     self.attr = StringMeta().create_attribute_model()
     self.method = MethodModel()
     self.o = BlockModel()
     self.o.set_endpoint_data("attr", self.attr)
     self.o.set_endpoint_data("method", self.method)