def setUp(self): p = MagicMock() # Serialized version of the block we want source = Hello(p, dict(mri="blockname"))[0] self.serialized = source.to_dict() # Setup client controller prerequisites self.p = MagicMock() self.p.name = "process" self.comms = MagicMock() params = ClientController.MethodMeta.prepare_input_map(mri="blockname") self.cc = ClientController(self.p, {}, params) self.b = self.cc.block # get process to give us comms self.p.get_client_comms.return_value = self.comms # tell our controller which blocks the process can talk to response = MagicMock(id=self.cc.REMOTE_BLOCKS_ID, value=["blockname"]) self.cc.put(response) # tell our controller the serialized state of the block response = MagicMock(id=self.cc.BLOCK_ID, changes=[[[], self.serialized]]) self.cc.put(response)
def setUp(self): sf = SyncFactory("sync") self.process = Process("proc", sf) Hello(self.process, dict(mri="hello")) Counter(self.process, dict(mri="counter")) self.process.add_comms( WebsocketServerComms(self.process, dict(port=self.socket))) self.process.start() # If we don't wait long enough, sometimes the websocket_connect() # in process2 will hang... time.sleep(0.1) self.process2 = Process("proc2", sf) self.process2.add_comms( WebsocketClientComms(self.process2, dict(hostname="localhost", port=self.socket))) self.process2.start()
def test_hello_with_process(self): sync_factory = SyncFactory("sched") process = Process("proc", sync_factory) b = Hello(process, dict(mri="hello"))[0] process.start() # wait until block is Ready task = Task("hello_ready_task", process) task.when_matches(b["state"], "Ready", timeout=1) q = sync_factory.create_queue() req = Post(response_queue=q, context="ClientConnection", endpoint=["hello", "greet"], parameters=dict(name="thing")) req.set_id(44) process.q.put(req) resp = q.get(timeout=1) self.assertEqual(resp.id, 44) self.assertEqual(resp.context, "ClientConnection") self.assertEqual(resp.typeid, "malcolm:core/Return:1.0") self.assertEqual(resp.value["greeting"], "Hello thing") process.stop()
class TestBlockModel(unittest.TestCase): def setUp(self): self.process = MagicMock() self.block = Hello(self.process, dict(mri="hello"))[0] self.m = BlockModel(self.process, self.block) def test_init(self): self.assertEqual(self.process.q.put.call_count, 1) req = self.process.q.put.call_args_list[0][0][0] self.assertEqual(req.endpoint, ['hello']) self.assertEqual(self.m.root_item.endpoint, ('hello',)) self.assertEqual(len(self.m.root_item.children), 0) def test_find_item(self): m1, m2 = MagicMock(), MagicMock() BlockItem.items[("foo", "bar")] = m1 BlockItem.items[("foo",)] = m2 item, path = self.m.find_item(('foo', 'bar', 'bat')) self.assertEqual(item, m1) self.assertEqual(path, ['bat']) def test_update_root(self): d = self.block.to_dict() self.m.handle_changes([[[], d]]) b_item = self.m.root_item self.assertEqual(len(b_item.children), 6) m_item = b_item.children[5] self.assertEqual(m_item.endpoint, ('hello', 'greet')) self.assertEqual(len(m_item.children), 2) n_item = m_item.children[0] self.assertEqual(n_item.endpoint, ('hello', 'greet', 'takes', 'elements', 'name')) self.assertEqual(n_item.children, []) n_item = m_item.children[1] self.assertEqual(n_item.endpoint, ('hello', 'greet', 'takes', 'elements', 'sleep')) self.assertEqual(n_item.children, [])
def setUp(self): self.process = Process("proc", SyncFactory("sync")) Hello(self.process, dict(mri="hello")) self.process.add_comms( WebsocketServerComms(self.process, dict(port=self.socket))) self.process.start()
def test_all_yamls(self): from malcolm.blocks.demo import Hello process = Mock() blocks = Hello(process, dict(mri="boo")) self.assertEqual(len(blocks), 1) process.add_block.assert_called_once_with(blocks[0], ANY)
def test_hello_good_input(self): p = MagicMock() block = Hello(p, dict(mri="hello"))[0] block.reset() result = block.greet(name="me") self.assertEquals(result.greeting, "Hello me")
def setUp(self): self.process = MagicMock() self.block = Hello(self.process, dict(mri="hello"))[0] self.m = BlockModel(self.process, self.block)