def testRepeatWithHandle(self): class repeatWithMemory(repeatingproxy.repeatWithHandle): def __init__(self, repeat): self.x = None repeatingproxy.repeatWithHandle.__init__(self, repeat) def first_time(self, fail): self.x = fail def check(repeater, i, expected_return, expected_x): ret = repeater(i) if ret != expected_return: assert False, "repeater(i) is %s and not %s as expected." % (ret, expected_return) if repeater.x != expected_x: assert False, "repeater.x is %s and not %s as expected." % (repeater.x, expected_x) repeater = repeatWithMemory(repeatingproxy.repeatTimes(6)) assert repeater.x is None check(repeater, 0, True, 0) check(repeater, 1, True, 0) repeater.x = None for i in range(4): check(repeater, 2+i, True, None) check(repeater, 7, False, None) try: check(repeater, 8, False, 0) raise Exception("Failure was expected.") except AssertionError: pass try: check(repeater, 8, True, None) raise Exception("Failure was expected.") except AssertionError: pass
def testRepeatTimes(self): repeat6Times = repeatingproxy.repeatTimes(6) try: for i in range(6): assert repeat6Times(i) assert not repeat6Times(7) finally: del repeat6Times
def test01Serializing(self): reactor.callLater(5, self.startServer) p = self.proxy self.rem_call(p, 'test', True) self.rem_call(p, 'test', True) self.rem_call(p, 'test2', False) self.rem_call(p, 'test_exc', False) self.rem_call(p, 'test_exc2', False) self.rem_call(p, 'test_long_call', True, (p.LONG_CALL,)) self.rem_call(p, 'test_long_call', True, (p.LONG_CALL,)) self.rem_call(p, 'test_long_call', True, (2*p.LONG_CALL,)) self.rem_call(p, 'retry_set', True, (2,)) self.rem_call(p, 'retry', True, args=(), repeat=repeatingproxy.repeatAlways) self.rem_call(p, 'retry_set', True, (3,)) self.rem_call(p, 'retry', False, args=(), repeat=repeatingproxy.repeatTimes(2)) return p.when_idle()