def test_inOutPort_basic(self): inPort = InPort(PortTest.UNIX_FIRST_ADDR) inOutPort = Port(PortTest.UNIX_FIRST_ADDR, PortTest.UNIX_SECOND_ADDR) outPort = OutPort(PortTest.UNIX_SECOND_ADDR) inPort.listen() inOutPort.initialize() outPort.connect() event = 'foo' outPort.send(event) self.assertEqual(event, inOutPort.receive(1.0)) event2 = 'bar' inOutPort.send(event2) self.assertEqual(event2, inPort.receive(1.0)) inPort.dispose() inOutPort.dispose()
class TimeMock(object): '''Object of this class encapsulates original time module interface''' def __init__(self, outUnixAddr, inUnixAddr): self._inOutPort = Port(outUnixAddr, inUnixAddr) def initialize(self): self._inOutPort.initialize() def dispose(self): self._inOutPort.dispose() def __getattr__(self, item): if hasattr(time, item): def rpcWrapper(*args, **kw): operation = item self._inOutPort.send({'method' : item, 'args' : args, 'kw' : kw}) ret = self._inOutPort.receive(2.0) return ret return rpcWrapper return getattr(self, item)
def test_inOutPort_basic(self): inPort = InPort(PortTest.UNIX_FIRST_ADDR) inOutPort = Port(PortTest.UNIX_FIRST_ADDR, PortTest.UNIX_SECOND_ADDR) outPort = OutPort(PortTest.UNIX_SECOND_ADDR) inPort.listen() inOutPort.initialize() outPort.connect() event = "foo" outPort.send(event) self.assertEqual(event, inOutPort.receive(1.0)) event2 = "bar" inOutPort.send(event2) self.assertEqual(event2, inPort.receive(1.0)) inPort.dispose() inOutPort.dispose()