Exemplo n.º 1
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)
Exemplo n.º 2
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)
Exemplo n.º 3
0
 def test_encode_as_single_message(self):
     res = codec.encode_message(2, [['A', 0]], 'ascii')
     self.assertEqual(f('{STX}2A|0{CR}{ETX}2F{CRLF}'), res)
Exemplo n.º 4
0
 def test_encode_message(self):
     msg = f('{STX}1A|B|C|D{CR}{ETX}BF{CRLF}')
     seq, data, cs = codec.decode_message(msg, 'ascii')
     self.assertEqual(msg, codec.encode_message(seq, data, 'ascii'))
Exemplo n.º 5
0
 def test_encode_as_single_message(self):
     res = codec.encode_message(2, [["A", 0]], "ascii")
     self.assertEqual(f("{STX}2A|0{CR}{ETX}2F{CRLF}"), res)
Exemplo n.º 6
0
 def test_encode_message(self):
     msg = f("{STX}1A|B|C|D{CR}{ETX}BF{CRLF}")
     seq, data, cs = codec.decode_message(msg, "ascii")
     self.assertEqual(msg, codec.encode_message(seq, data, "ascii"))
Exemplo n.º 7
0
 def test_provide_default_handler_for_unknown_message_type(self):
     message = codec.encode_message(1, ['FOO'], 'ascii')
     self.dispatcher(message)
     self.assertTrue(self.dispatcher.on_unknown.was_called)
Exemplo n.º 8
0
 def test_dispatch_terminator(self):
     message = codec.encode_message(1, ['L'], 'ascii')
     self.dispatcher(message)
     self.assertTrue(self.dispatcher.dispatch['L'].was_called)
Exemplo n.º 9
0
 def test_dispatch_manufacturer_info(self):
     message = codec.encode_message(1, ['M'], 'ascii')
     self.dispatcher(message)
     self.assertTrue(self.dispatcher.dispatch['M'].was_called)
Exemplo n.º 10
0
 def test_dispatch_scientific(self):
     message = codec.encode_message(1, ['S'], 'ascii')
     self.dispatcher(message)
     self.assertTrue(self.dispatcher.dispatch['S'].was_called)
Exemplo n.º 11
0
 def test_dispatch_result(self):
     message = codec.encode_message(1, ['R'], 'ascii')
     self.dispatcher(message)
     self.assertTrue(self.dispatcher.dispatch['R'].was_called)
Exemplo n.º 12
0
 def test_provide_default_handler_for_unknown_message_type(self):
     message = codec.encode_message(1, ['FOO'], 'ascii')
     self.dispatcher(message)
     self.assertTrue(self.dispatcher.on_unknown.was_called)
Exemplo n.º 13
0
 def test_dispatch_terminator(self):
     message = codec.encode_message(1, ['L'], 'ascii')
     self.dispatcher(message)
     self.assertTrue(self.dispatcher.dispatch['L'].was_called)
Exemplo n.º 14
0
 def test_dispatch_result(self):
     message = codec.encode_message(1, ['R'], 'ascii')
     self.dispatcher(message)
     self.assertTrue(self.dispatcher.dispatch['R'].was_called)
Exemplo n.º 15
0
 def test_dispatch_manufacturer_info(self):
     message = codec.encode_message(1, ['M'], 'ascii')
     self.dispatcher(message)
     self.assertTrue(self.dispatcher.dispatch['M'].was_called)
Exemplo n.º 16
0
 def test_dispatch_scientific(self):
     message = codec.encode_message(1, ['S'], 'ascii')
     self.dispatcher(message)
     self.assertTrue(self.dispatcher.dispatch['S'].was_called)