def test_to_readable_output_nonsense_packet_expect_raw_returned(self): test_deserialization = Deserialization() expected_return = 'this is not a proper aprs packet' actual_value = test_deserialization.to_readable_output(expected_return) assert actual_value == expected_return
def test_to_readable_output_reale_packet_expect_readable_returned(self): test_deserialization = Deserialization() test_packet = 'AAA123>BBB123,APRS-1*,WIDE1*,APRS-10*,WIDE2*:!4252.29NT07538.40W&PHG7130 Yes hello, testing.' actual_value = test_deserialization.to_readable_output(test_packet) assert actual_value is not 'this is not a proper aprs packet'
class CliProcessor(Processor): def __init__(self): """Sets up the functionality we will be using.""" self.log_handler = None self.config = None self.deserializer = Deserialization() def get_name(self): """Gets the name of this processor to match against the config.""" return "cli" def load(self, config, log_handler): """Initializes the processor, assigning the params locally.. Args: packet: A decoded packet to output to the CLI. """ self.config = config self.log_handler = log_handler def handle(self, packet): """Handles a single packet, outputting it to the CLI in a human-readable format. Args: packet: A decoded packet to output to the CLI. """ print_friendly_packet = self.deserializer.to_readable_output(packet) self.log_handler.log_packet(packet, print_friendly_packet)
def test_init_expect_initialized(self): log_handler = Logger() runtime_configuration = Configuration() deserializer = Deserialization() test_receiver = Receiver(log_handler, deserializer, runtime_configuration) assert test_receiver.is_running is False assert test_receiver.sub_processes == {} assert test_receiver.log_handler == log_handler assert test_receiver.deserializer == deserializer assert test_receiver.config == runtime_configuration
def test_clean_decoded_packet_no_aprs_expect_none(self): log_handler = Logger() runtime_configuration = Configuration() deserializer = Deserialization() mock_packet = 'blah' test_receiver = Receiver(log_handler, deserializer, runtime_configuration) actual_packet = test_receiver._Receiver__clean_decoded_packet( mock_packet) assert actual_packet is None
def test_clean_decoded_packet_with_aprs_expect_cleaned(self): log_handler = Logger() runtime_configuration = Configuration() deserializer = Deserialization() expected_cleaned_packet = 'Woo' mock_packet = 'APRS: ' + expected_cleaned_packet test_receiver = Receiver(log_handler, deserializer, runtime_configuration) actual_packet = test_receiver._Receiver__clean_decoded_packet( mock_packet) assert actual_packet == expected_cleaned_packet
def test_stop_expect_sys_exit(self): log_handler = Logger() runtime_configuration = Configuration() deserializer = Deserialization() test_receiver = Receiver(log_handler, deserializer, runtime_configuration) try: test_receiver.stop() except SystemExit: return pytest.fail('Expected a SystemExit to be raised.')
def test_start_with_mock_instances_expect_started(self): mock_json = '{"listener":{"implementation": "pypacket.mocks.mock_listener.MockListener"},' + \ '"decoder":{"implementation": "pypacket.mocks.mock_decoder.MockDecoder"}, ' + \ '"processors": [{"name": "mock", "implementation": "pypacket.mocks.mock_processor.MockProcessor"}]}' log_handler = Logger() runtime_configuration = Configuration() runtime_configuration.load_json(mock_json) deserializer = Deserialization() test_receiver = Receiver(log_handler, deserializer, runtime_configuration) test_receiver.start() assert test_receiver.is_running is True
from pypacket.base.configuration import Configuration from pypacket.util.colors import Colors print(Colors.GREEN + """ ___ ___ _ _ | _ \_ _| _ \__ _ __| |_____| |_ | _/ || | _/ _` / _| / / -_) _| |_| \_, |_| \__,_\__|_\_\___|\__| |__/ """ + Colors.RESET) # Configure logging. log_handler = Logger() # Initialize configuration. runtime_configuration = Configuration() # Initialize deserialization. deserializer = Deserialization() # The main runner. pypacket_receiver = Receiver(log_handler, deserializer, runtime_configuration) pypacket_receiver.start() # Handles Control+c interrupts, existing the main loop and threads. try: while True: time.sleep(.05) except KeyboardInterrupt: pypacket_receiver.stop()
def __init__(self): """Sets up the functionality we will be using.""" self.log_handler = None self.config = None self.deserializer = Deserialization()