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'))
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"))
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)
def test_dispatch_terminator(self): message = codec.encode_message(1, ['L'], 'ascii') self.dispatcher(message) self.assertTrue(self.dispatcher.dispatch['L'].was_called)
def test_dispatch_manufacturer_info(self): message = codec.encode_message(1, ['M'], 'ascii') self.dispatcher(message) self.assertTrue(self.dispatcher.dispatch['M'].was_called)
def test_dispatch_scientific(self): message = codec.encode_message(1, ['S'], 'ascii') self.dispatcher(message) self.assertTrue(self.dispatcher.dispatch['S'].was_called)
def test_dispatch_result(self): message = codec.encode_message(1, ['R'], 'ascii') self.dispatcher(message) self.assertTrue(self.dispatcher.dispatch['R'].was_called)