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