Ejemplo n.º 1
0
    def test_Error(self):
        context = Mock()
        r = Error(123, context, "Test Error")

        self.assertEquals(123, r.id_)
        self.assertEquals("malcolm:core/Error:1.0", r.typeid)
        self.assertEquals(context, r.context)

        r.set_message("Test Error 2")
        self.assertEquals("Test Error 2", r.message)
Ejemplo n.º 2
0
    def test_callback_error(self):
        t = Task("testTask", self.proc)
        resp = Error(0, None, None)
        resp.set_message('error')
        t.q.put(resp)
        t.stop()

        t.subscribe(self.attr, self._callback, 3, 5)
        f1 = Future(t)
        t._futures = {1: f1}
        self.assertRaises(RuntimeError, t.wait_all, f1, 0)
Ejemplo n.º 3
0
    def test_callback_error(self):
        t = Task("testTask", self.proc)
        resp = Error(0, None, None)
        resp.set_message('error')
        t.q.put(resp)
        t.stop()

        t.subscribe(self.attr, self._callback, 3, 5)
        f1 = Future(t)
        t._futures = {1: f1}
        self.assertRaises(RuntimeError, t.wait_all, f1, 0)
Ejemplo n.º 4
0
 def test_exception(self):
     # timeout due to no response arriving
     f0 = Future(self.task)
     f1 = Future(self.task)
     self.task._futures = {0: f0, 1: f1}
     self.assertRaises(queue.Empty, f0.exception, 0)
     # return after waiting for response object
     resp0 = Return(0, None, None)
     resp0.set_value('testVal')
     resp1 = Error(1, None, None)
     resp1.set_message('test Error')
     self.task.q.put(resp0)
     self.task.q.put(resp1)
     self.assertEqual(f1.exception(), 'test Error')
Ejemplo n.º 5
0
 def test_result(self):
     # timeout due to no response arriving
     f0 = Future(self.task)
     f1 = Future(self.task)
     self.task._futures = {0: f0, 1: f1}
     self.assertRaises(queue.Empty, f0.result, 0)
     # return after waiting for response object
     resp0 = Return(0, None, None)
     resp0.set_value('testVal')
     resp1 = Error(1, None, "test Error")
     resp1.set_message('test Error')
     self.task.q.put(resp0)
     self.task.q.put(resp1)
     self.assertEqual(f0.result(), 'testVal')
Ejemplo n.º 6
0
 def test_exception(self):
     # timeout due to no response arriving
     f0 = Future(self.task)
     f1 = Future(self.task)
     self.task._futures = {0: f0, 1: f1}
     self.assertRaises(queue.Empty, f0.exception, 0)
     # return after waiting for response object
     resp0 = Return(0, None, None)
     resp0.set_value('testVal')
     resp1 = Error(1, None, None)
     resp1.set_message('test Error')
     self.task.q.put(resp0)
     self.task.q.put(resp1)
     with self.assertRaises(ValueError) as cm:
         f1.exception()
     self.assertEqual(str(cm.exception), 'test Error')