def test_sample_rate_expect_sample_rate(self): test_configuration = Configuration() expected_sample_rate = '22050' actual_sample_rate = test_configuration.sample_rate() assert actual_sample_rate == expected_sample_rate
def test_gain_expect_gain(self): test_configuration = Configuration() expected_gain = '49.6' actual_gain = test_configuration.gain() assert actual_gain == expected_gain
def test_frequency_expect_frequency(self): test_configuration = Configuration() expected_frequency = '144390000' actual_frequency = test_configuration.frequency() assert actual_frequency == expected_frequency
def test_beacon_symbol_table_expect_beacon_symbol_table(self): mock_json = '{"beacon":{"symbol_table":"/"}}' test_configuration = Configuration() test_configuration.load_json(mock_json) beacon_symbol_table = test_configuration.beacon_symbol_table() assert beacon_symbol_table == "/"
def test_constructor_with_json_expect_constructed(self): mock_json = '{"listener":{"gain":"0"}}' test_configuration = Configuration() test_configuration.load_json(mock_json) actual_gain = test_configuration.gain() assert actual_gain == '0'
def test_ppm_error_expect_ppm_error(self): mock_json = '{"listener":{"ppm_error":"5"}}' test_configuration = Configuration() test_configuration.load_json(mock_json) ppm_error = test_configuration.ppm_error() assert ppm_error == '5'
def test_squelch_expect_squelch(self): mock_json = '{"listener":{"squelch_level":"5"}}' test_configuration = Configuration() test_configuration.load_json(mock_json) squelch_level = test_configuration.squelch_level() assert squelch_level == '5'
def test_version_expect_version(self): mock_json = '{"version":4.5}' test_configuration = Configuration() test_configuration.load_json(mock_json) version = test_configuration.version() assert version == 4.5
def test_beacon_interval_expect_beacon_interval(self): mock_json = '{"beacon":{"interval":30.0}}' test_configuration = Configuration() test_configuration.load_json(mock_json) beacon_interval = test_configuration.beacon_interval() assert beacon_interval == 30.0
def test_beacon_comment_expect_beacon_comment(self): mock_json = '{"beacon":{"comment":"hello, world"}}' test_configuration = Configuration() test_configuration.load_json(mock_json) beacon_comment = test_configuration.beacon_comment() assert beacon_comment == "hello, world"
def test_beacon_symbol_expect_beacon_symbol(self): mock_json = '{"beacon":{"symbol":"i"}}' test_configuration = Configuration() test_configuration.load_json(mock_json) beacon_symbol = test_configuration.beacon_symbol() assert beacon_symbol == "i"
def test_longitude_expect_username(self): self.env = patch.dict('os.environ', {'PYPACKET_LONGITUDE': '-42'}) with self.env: test_configuration = Configuration() longitude = test_configuration.longitude() assert longitude == '-42'
def test_username_expect_username(self): self.env = patch.dict('os.environ', {'PYPACKET_USERNAME': '******'}) with self.env: test_configuration = Configuration() username = test_configuration.username() assert username == 'test'
def test_password_expect_username(self): self.env = patch.dict('os.environ', {'PYPACKET_PASSWORD': '******'}) with self.env: test_configuration = Configuration() password = test_configuration.password() assert password == 'supersecure'
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) test_receiver = Receiver(log_handler, runtime_configuration) test_receiver.start() assert test_receiver.is_running is True
def test_handler_expect_handled_without_error(self): mock_packet = 'AAA123>BBB123,APRS-1*,WIDE1*,APRS-10*,WIDE2*:!4252.29NT07538.40W&PHG7130 Yes hello, testing.' test_logger = Logger() test_configuration = Configuration() cli_processor = CliProcessor() cli_processor.load(test_configuration, test_logger) cli_processor.handle(mock_packet)
def test_load_env_vars_not_set_expect_not_connected(self, mock_connect): test_configuration = Configuration() test_logger = Logger() processor = AprsIsProcessor() processor.load(test_configuration, test_logger) mock_connect.assert_not_called()
def test_load_expect_loaded(self): test_logger = Logger() test_configuration = Configuration() cli_processor = CliProcessor() cli_processor.load(test_configuration, test_logger) assert cli_processor.config == test_configuration assert cli_processor.log_handler == test_logger
def test_init_expect_initialized(self): log_handler = Logger() runtime_configuration = Configuration() test_receiver = Receiver(log_handler, runtime_configuration) assert test_receiver.is_running is False assert test_receiver.sub_processes == {} assert test_receiver.log_handler == log_handler assert test_receiver.config == runtime_configuration
def test_load_expect_connected(self, mock_connect): environ["PYPACKET_USERNAME"] = "******" environ["PYPACKET_PASSWORD"] = "******" test_configuration = Configuration() test_logger = Logger() processor = AprsIsProcessor() processor.load(test_configuration, test_logger) mock_connect.assert_called_once()
def test_clean_decoded_packet_no_aprs_expect_none(self): log_handler = Logger() runtime_configuration = Configuration() mock_packet = 'blah' test_receiver = Receiver(log_handler, runtime_configuration) actual_packet = test_receiver._Receiver__clean_decoded_packet( mock_packet) assert actual_packet is None
def test_stop_expect_sys_exit(self): log_handler = Logger() runtime_configuration = Configuration() test_receiver = Receiver(log_handler, runtime_configuration) try: test_receiver.stop() except SystemExit: return pytest.fail('Expected a SystemExit to be raised.')
def test_clean_decoded_packet_with_aprs_expect_cleaned(self): log_handler = Logger() runtime_configuration = Configuration() expected_cleaned_packet = 'Woo' mock_packet = 'APRS: ' + expected_cleaned_packet test_receiver = Receiver(log_handler, runtime_configuration) actual_packet = test_receiver._Receiver__clean_decoded_packet( mock_packet) assert actual_packet == expected_cleaned_packet
def test_beacon_expect_beacon(self): self.env = patch.dict('os.environ', { 'PYPACKET_LATITUDE': '42', 'PYPACKET_LONGITUDE': '-42' }) with self.env: test_configuration = Configuration() beacon = Beacon(test_configuration) assert beacon.latitude == 42.0 assert beacon.longitude == -42.0
def test_handle_expect_handled(self, mock_handle): environ["PYPACKET_USERNAME"] = "******" environ["PYPACKET_PASSWORD"] = "******" test_configuration = Configuration() test_logger = Logger() processor = AprsIsProcessor() processor.is_connected = True processor.load(test_configuration, test_logger) processor.handle(None) mock_handle.assert_called_once()
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 test_decoder_expect_decoder(self): test_configuration = Configuration() actual_decoder = test_configuration.decoder() assert actual_decoder is not None
def test_listener_expect_listener(self): test_configuration = Configuration() actual_listener = test_configuration.listener() assert actual_listener is not None