Exemplo n.º 1
0
 def test_set_label(self):
     m = MethodMeta("test_description")
     m.process = Mock()
     m.set_label("new_label")
     self.assertEquals("new_label", m.label)
     m.process.report_changes.assert_called_once_with([["label"],
                                                       "new_label"])
Exemplo n.º 2
0
 def setUp(self):
     self.callback_result = 0
     self.callback_value = ''
     meta = VMeta("meta for unit tests")
     self.proc = MagicMock(q=queue.Queue())
     self.proc.create_queue = MagicMock(side_effect=queue.Queue)
     self.block = Block()
     self.block.set_parent(self.proc, "testBlock")
     self.attr = meta.make_attribute()
     self.attr.set_parent(self.block, "testAttr")
     self.attr2 = meta.make_attribute()
     self.attr2.set_parent(self.block, "testAttr2")
     self.method = MethodMeta("method for unit tests")
     self.method.set_parent(self.block, "testFunc")
     self.method2 = MethodMeta("method for unit tests")
     self.method2.set_parent(self.block, "testFunc")
     self.bad_called_back = False
Exemplo n.º 3
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 = MethodMeta("Test")
        m.recreate_from_others(
            [method1.MethodMeta, method2.MethodMeta, method3.MethodMeta],
            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(ElementMap(elements))
        itakes.set_required(["arg1"])
        defaults = OrderedDict()
        defaults["arg8"] = "2"
        defaults["arg3"] = "33"
        self.assertEqual(m.takes.to_dict(), itakes.to_dict())
        self.assertEqual(m.returns.to_dict(), MapMeta().to_dict())
        self.assertEqual(m.defaults, defaults)
Exemplo n.º 4
0
 def setUp(self):
     self.callback_result = 0
     self.callback_value = ''
     meta = StringMeta("meta for unit tests")
     self.proc = MagicMock(q=queue.Queue())
     self.proc.create_queue = MagicMock(side_effect=queue.Queue)
     self.block = Block()
     self.block.set_process_path(self.proc, ("testBlock", ))
     self.attr = meta.make_attribute()
     self.attr2 = meta.make_attribute()
     self.method = MethodMeta("method for unit tests")
     self.method.returns.set_elements(ElementMap(dict(ret=StringMeta())))
     self.method2 = MethodMeta("method for unit tests")
     self.block.replace_endpoints(
         dict(testFunc=self.method,
              testFunc2=self.method2,
              testAttr=self.attr,
              testAttr2=self.attr2))
     self.bad_called_back = False
Exemplo n.º 5
0
 def __init__(self, hook_queue, part, func_name, task, *args, **params):
     self.set_logger_name("HookRunner(%s)" % part.name)
     self.hook_queue = hook_queue
     self.part = part
     self.task = task
     self.args = args
     self.func = getattr(part, func_name)
     self.filtered_params = {}
     self.method_meta = part.method_metas.get(func_name, None)
     if self.method_meta is None:
         self.method_meta = MethodMeta()
         self.method_meta.set_logger_name("MethodMeta")
     for k, v in params.items():
         if k in self.method_meta.takes.elements:
             self.filtered_params[k] = v
Exemplo n.º 6
0
 def test_to_dict(self):
     m = MethodMeta("test_description")
     m.set_takes(self.takes)
     m.set_defaults(self.serialized["defaults"])
     self.assertEqual(m.to_dict(), self.serialized)
Exemplo n.º 7
0
 def test_init(self):
     m = MethodMeta("test_description")
     self.assertEquals("test_description", m.description)
     self.assertEquals("malcolm:core/MethodMeta:1.0", m.typeid)
     self.assertEquals("", m.label)