コード例 #1
0
ファイル: test_context.py プロジェクト: nsob1c12/pymalcolm
 def test_when_matches(self):
     self.o._q.put(Update(1, "value1"))
     self.o._q.put(Return(1))
     self.o.when_matches(["block", "attr", "value"], "value1", timeout=0.01)
     assert self.controller.handle_request.call_args_list == [
         call(Subscribe(1, ["block", "attr", "value"])),
         call(Unsubscribe(1))
     ]
コード例 #2
0
ファイル: test_context.py プロジェクト: nsob1c12/pymalcolm
 def test_post(self):
     self.controller.validate_result.return_value = 22
     self.o._q.put(Return(1, dict(a=2)))
     result = self.o.post(["block", "method"], dict(b=32))
     self.controller.handle_request.assert_called_once_with(
         Post(1, ["block", "method"], dict(b=32)))
     self.controller.validate_result.assert_called_once_with(
         "method", dict(a=2))
     assert result == 22
コード例 #3
0
ファイル: test_context.py プロジェクト: nsob1c12/pymalcolm
 def test_many_puts(self):
     fs = [
         self.o.put_async(["block", "attr", "value"], 32),
         self.o.put_async(["block", "attr2", "value"], 32)
     ]
     with self.assertRaises(TimeoutError):
         self.o.wait_all_futures(fs, 0.01)
     assert [f.done() for f in fs] == [False, False]
     self.o._q.put(Return(2, None))
     assert [f.done() for f in fs] == [False, False]
     with self.assertRaises(TimeoutError):
         self.o.wait_all_futures(fs, 0.01)
     assert [f.done() for f in fs] == [False, True]
     self.o._q.put(Return(1, None))
     self.o.wait_all_futures(fs, 0.01)
     assert [f.done() for f in fs] == [True, True]
     self.o.wait_all_futures(fs, 0.01)
     assert [f.done() for f in fs] == [True, True]
コード例 #4
0
    def test_respond_with_return(self):

        self.request.respond_with_return(value=5)

        call_arg = self.response_queue.put.call_args_list[0][0][0].to_dict()

        expected_response = Return(self.request.id_, self.request.context, value=5).to_dict()

        self.assertEqual(call_arg, expected_response)
コード例 #5
0
 def test_pva_rpc_implementation(self):
     server = MagicMock()
     request = {"method": "test_method"}
     pva = PvaRpcImplementation(1, request, "test.block", server)
     self.assertEqual(pva._id, 1)
     self.assertEqual(pva._block, "test.block")
     self.assertEqual(pva._request, request)
     self.assertEqual(pva._server, server)
     self.assertEqual(pva._method, "test_method")
     pre_parse = {
         "dict1": {"item1", 1},
         "list1": [1, 2, 3],
         "tuple1": ({
             "item2": 2,
             "item3": 3
         }, 2)
     }
     post_parse = {
         "dict1": {"item1", 1},
         "list1": [1, 2, 3],
         "tuple1": {
             "item2": 2,
             "item3": 3
         }
     }
     self.assertEqual(pva.parse_variants(pre_parse), post_parse)
     response = Return(id_=2, value="test.value")
     pva.notify_reply(response)
     pv = MagicMock()
     pva.execute(pv)
     server.process.q.put.assert_called_once()
     pv.toDict.assert_called_once()
     pva._lock = MagicMock()
     pva.check_lock()
     pva._lock.acquire.assert_has_calls([call(False)])
     pva._event = MagicMock()
     pva.wait_for_reply()
     pva._event.wait.assert_called_once()
コード例 #6
0
    def test_pva_rpc_implementation(self):
        self.p = MagicMock()
        self.p = MagicMock()
        pva = PvaRpcImplementation(1, self.p, "test.block", "test.method")
        self.assertEqual(pva._id, 1)
        self.assertEqual(pva._block, "test.block")
        self.assertEqual(pva._method, "test.method")
        self.assertEqual(pva._server, self.p)

        response = Return(id_=2, value="test.value")
        pva.notify_reply(response)
        self.pv = MagicMock()
        pva.execute(self.pv)
        self.p.process.q.put.assert_called_once()
        self.pv.toDict.assert_called_once()

        pva._lock = MagicMock()
        pva.check_lock()
        pva._lock.acquire.assert_has_calls([call(False)])

        pva._event = MagicMock()
        pva.wait_for_reply()
        pva._event.wait.assert_called_once()