def test_found_terminator_skip_empty(self): obj = DummyProto() obj.dispatch = track_call(obj.dispatch) obj.inbox.append('') obj.inbox.append(None) obj.found_terminator() self.assertTrue(not obj.dispatch.was_called)
def test_reject_message_on_dispatch_error(self): def dispatcher(message): codec.decode_message(message, 'latin-1') req = DummyRequestHandler(track_call(dispatcher)) req.on_enq() req._last_recv_data = '|foo'.encode() self.assertEqual(req.on_message(), constants.NAK) self.assertTrue(req.dispatcher.was_called)
def test_found_terminator(self): obj = DummyProto() obj.dispatch = track_call(obj.dispatch) obj.found_terminator() self.assertTrue(not obj.dispatch.was_called) obj.inbox.append(constants.ENQ) obj.found_terminator() self.assertTrue(obj.dispatch.was_called)
def test_wrap_before_dispatch(self): class Thing(object): def __init__(self, *args): self.args = args def handler(record): assert isinstance(record, Thing) message = codec.encode_message(1, ['H'], 'ascii') self.dispatcher.wrappers['H'] = Thing self.dispatcher.dispatch['H'] = track_call(handler) self.dispatcher(message) self.assertTrue(self.dispatcher.dispatch['H'].was_called)
def setUp(self): self.req = DummyRequestHandler() self.req.dispatcher = track_call(self.req.dispatcher) self.stderr = sys.stderr sys.stderr = open(os.devnull, 'w')
def setUp(self): d = BaseRecordsDispatcher() for key, value in d.dispatch.items(): d.dispatch[key] = track_call(value) d.on_unknown = track_call(d.on_unknown) self.dispatcher = d
def test_on_message(self): obj = DummyProto() obj.on_message = track_call(obj.on_message) obj.dispatch(constants.STX) self.assertTrue(obj.on_message.was_called)
def test_on_nak(self): obj = DummyProto() obj.on_nak = track_call(obj.on_nak) obj.dispatch(constants.NAK) self.assertTrue(obj.on_nak.was_called)
def test_on_enq(self): obj = DummyProto() obj.on_enq = track_call(obj.on_enq) obj.dispatch(constants.ENQ) self.assertTrue(obj.on_enq.was_called)
def test_on_eot(self): obj = DummyProto() obj.on_eot = track_call(obj.on_eot) obj.dispatch(constants.EOT) self.assertTrue(obj.on_eot.was_called)
def test_default_hanlder(self): obj = DummyProto() obj.default_handler = track_call(obj.default_handler) self.assertRaises(ValueError, obj.dispatch, b'foo') self.assertTrue(obj.default_handler.was_called)
def test_close_on_timeout(self): self.req.close = track_call(self.req.close) self.req.on_timeout() self.assertTrue(self.req.close.was_called)