Пример #1
0
 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)
Пример #2
0
 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)
Пример #3
0
 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)
Пример #4
0
    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)
Пример #5
0
    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)
Пример #6
0
    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)
Пример #7
0
 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)
Пример #8
0
    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)
Пример #9
0
 def setUp(self):
     self.req = DummyRequestHandler()
     self.req.dispatcher = track_call(self.req.dispatcher)
     self.stderr = sys.stderr
     sys.stderr = open(os.devnull, 'w')
Пример #10
0
 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
Пример #11
0
 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
Пример #12
0
 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)
Пример #13
0
 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)
Пример #14
0
 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)
Пример #15
0
 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)
Пример #16
0
 def setUp(self):
     self.req = DummyRequestHandler()
     self.req.dispatcher = track_call(self.req.dispatcher)
     self.stderr = sys.stderr
     sys.stderr = open(os.devnull, 'w')
Пример #17
0
 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)
Пример #18
0
 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)
Пример #19
0
 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)
Пример #20
0
 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)
Пример #21
0
 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)
Пример #22
0
 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)
Пример #23
0
 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)
Пример #24
0
 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)