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 TimeController(object): '''Object of this class is used by test suite to set current time''' def __init__(self, outUnixAddr, inUnixAddr): self._inOutPort = Port(outUnixAddr, inUnixAddr) self.finished = False self.timeReturn = 17 self._lock = threading.Lock() def initialize(self): self._inOutPort.initialize() def finalize(self): self.finished = True def dispose(self): print("TimeController::dispose()" + `self._inOutPort`) self._inOutPort.dispose() def lock(self): self._lock.acquire() def unlock(self): self._lock.release() def handle(self, event): args = event['args'] kw = event['kw'] method = event['method'] try: self._lock.acquire() ret = getattr(self, method)(*args, **kw) print("TimeMock::" + method + "(...) -> {ret}".format(ret=str(ret))) except Exception, e: ret = getattr(time, method)(*args, **kw) print("time." + method + "(...) -> " + str(ret)) finally:
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 __init__(self, outUnixAddr, inUnixAddr): self._inOutPort = Port(outUnixAddr, inUnixAddr) self.finished = False self.timeReturn = 17 self._lock = threading.Lock()
def __init__(self, outUnixAddr, inUnixAddr): self._inOutPort = Port(outUnixAddr, inUnixAddr)