Exemple #1
0
    def test_getattr(self):
        b = Block()
        a = NumberMeta("int32").make_attribute()
        b.replace_endpoints(dict(a=a))

        def f(meta, value):
            a.set_value(value)

        b.set_writeable_functions(dict(a=f))
        b.a = 32
        self.assertEqual(b.a, 32)
 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
Exemple #3
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
Exemple #4
0
 def test_handle_request_fails(self):
     parent = MagicMock()
     child = MagicMock(spec=Attribute)
     func = MagicMock()
     child.handle_request.side_effect = Exception("Test exception")
     b = Block()
     b.replace_endpoints({"child": child})
     b.set_writeable_functions({"child": func})
     b.set_parent(parent, "name")
     request = MagicMock(spec=Put,
                         id=12345,
                         response_queue=MagicMock(),
                         context=MagicMock(),
                         endpoint=["name", "child", "irrelevant"])
     b.handle_request(request)
     calls = parent.block_respond.call_args_list
     self.assertEquals(1, len(calls))
     response = calls[0][0][0]
     self.assertIsInstance(response, Error)
     self.assertEquals(request.id, response.id)
     self.assertEquals(request.context, response.context)
     self.assertEquals("Test exception", response.message)
     self.assertEquals(request.response_queue, calls[0][0][1])
Exemple #5
0
 def test_handle_post_request(self):
     parent = MagicMock()
     child = MagicMock(spec=Attribute)
     func = MagicMock()
     b = Block()
     b.replace_endpoints({"child": child})
     b.set_writeable_functions({"child": func})
     b.set_parent(parent, "name")
     request = MagicMock(spec=Post,
                         id=12345,
                         response_queue=MagicMock(),
                         context=MagicMock(),
                         endpoint=["name", "child", "irrelevant"])
     b.handle_request(request)
     calls = parent.block_respond.call_args_list
     self.assertEquals(1, len(calls))
     response = calls[0][0][0]
     self.assertIsInstance(response, Return)
     self.assertEquals(request.id, response.id)
     self.assertEquals(request.context, response.context)
     self.assertEquals(child.handle_request.return_value.to_dict(),
                       response.value)
     self.assertEquals(request.response_queue, calls[0][0][1])
Exemple #6
0
 def test_getattr_raises(self):
     b = Block()
     self.assertRaises(AttributeError, getattr, b, "_does_not_exist")
Exemple #7
0
 def test_init(self):
     b = Block()
     self.assertEqual(list(b), [])
     self.assertEqual("malcolm:core/Block:1.0", b.typeid)