示例#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)
示例#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)
示例#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)
示例#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'))
示例#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)
示例#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"))
示例#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)
示例#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)
示例#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)
示例#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)
示例#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)
示例#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)
示例#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)
示例#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)
示例#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)
示例#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)