class ProcessTest(unittest.TestCase): def setUp(self): self.p = Process(["tst://socket"], "The Process") self.p.run(block=False) self.s = self.p._server_socks["tst://socket"] def test_gc(self): msgs = [] def log_debug(msg): msgs.append(msg) self.p.log_debug = log_debug self.s = None self.p = None self.assertEqual(msgs, ['Garbage collecting loop', 'Stopping loop', 'Waiting for loop to finish', 'Confirming loop stopped', 'Loop garbage collected']) def test_create_device(self): self.assertEqual(self.p.device_types, [ 'Device', 'RunnableDevice', 'PausableDevice', 'DummyDet', 'DeviceClient', 'Process', 'MockDevice']) d = self.p.create_MockDevice("MD") self.assertIsInstance(d, MockDevice) self.assertEqual(d.name, "MD") def test_call_on_device(self): d = self.p.create_MockDevice("MD") self.s.inq.Signal((SType.Call, dict(endpoint="MD", method="run"))) self.assertEqual(d.runcalled, False) # Yield to let socket recv cothread.Yield() # Yield to let process retrieve from inq cothread.Yield() # Yield to let spawned do_func run cothread.Yield() self.assertEqual(d.runcalled, True) self.assertIsNot(self.s.send, None) self.s.send.assert_called_once_with(SType.Return, 32) def test_get_on_device(self): d = self.p.create_MockDevice("MD") self.s.inq.Signal((SType.Get, dict(endpoint="MD.methods"))) # Yield to let socket recv cothread.Yield() # Yield to let process retrieve from inq cothread.Yield() self.assertIsNot(self.s.send, None) self.s.send.assert_called_once_with(SType.Return, d.methods) def test_subscribe_on_device(self): d = self.p.create_MockDevice("MD") self.s.inq.Signal((SType.Subscribe, dict(endpoint="MD.methods.run"))) # Yield to let socket recv cothread.Yield() # Yield to let process retrieve from inq cothread.Yield() d.notify_listeners({"methods.run.descriptor": "new desc"}) # Yield to let subscription send back out cothread.Yield() self.assertIsNot(self.s.send, None) self.s.send.assert_called_once_with( SType.Value, d.methods["run"], changes=dict(descriptor="new desc")) self.s.send.reset_mock() self.s.inq.Signal((SType.Unsubscribe, {})) # Yield to let socket recv cothread.Yield() # Yield to let process retrieve from inq cothread.Yield() self.s.send.assert_called_once_with( SType.Return) # Yield to let subscription remove itself from parent cothread.Yield()