def test_wrong_version(): device_manager = DeviceManager( None, {DeviceType.TANTALUS_STAGE_1_FLARE: 'RequiredVersion'}) full_address_1 = FullAddress(connection_name='TantalusStage1Connection', device_address='TantalusStage1Address') with pytest.raises(InvalidDeviceVersion): device_manager.register_device(DeviceType.TANTALUS_STAGE_1_FLARE, 'OtherVersion', full_address_1) assert device_manager.get_full_address( DeviceType.TANTALUS_STAGE_1_FLARE) is None
def test_unregistered_device(full_device_manager): full_command_parser = CommandParser(full_device_manager) all_commands = full_command_parser.available_commands() device_manager = DeviceManager(None, None) device_manager.register_device( DeviceType.TANTALUS_STAGE_1_FLARE, None, ('CONNECTION', DeviceType.TANTALUS_STAGE_1_FLARE.name)) command_parser = CommandParser(device_manager) for command in all_commands: (device, _, _) = full_command_parser.pase_command(command) if device == DeviceType.TANTALUS_STAGE_1_FLARE: assert command_parser.pase_command(command) is not None else: with pytest.raises(CommandParsingError): command_parser.pase_command(command)
def test_num_expected(): device_manager = DeviceManager([DeviceType.TANTALUS_STAGE_1_FLARE], None) full_address_1 = FullAddress(connection_name='TantalusStage1Connection', device_address='TantalusStage1Address') full_address_2 = FullAddress(connection_name='TantalusStage2Connection', device_address='TantalusStage2Address') device_manager.register_device(DeviceType.TANTALUS_STAGE_2_FLARE, None, full_address_2) assert device_manager.num_expected_registered() == 0 device_manager.register_device(DeviceType.TANTALUS_STAGE_1_FLARE, None, full_address_1) assert device_manager.num_expected_registered() == 1
def test_existing_full_address(): device_manager = DeviceManager(None, None) full_address_1 = FullAddress(connection_name='TantalusStage1Connection', device_address='TantalusStage1Address') device_manager.register_device(DeviceType.TANTALUS_STAGE_1_FLARE, None, full_address_1) with pytest.raises(InvalidRegistration): device_manager.register_device(DeviceType.TANTALUS_STAGE_2_FLARE, None, full_address_1) assert device_manager.get_full_address( DeviceType.TANTALUS_STAGE_1_FLARE) == full_address_1
def test_normal_registration(): device_manager = DeviceManager(None, None) full_address_1 = FullAddress(connection_name='TantalusStage1Connection', device_address='TantalusStage1Address') full_address_2 = FullAddress(connection_name='TantalusStage2Connection', device_address='TantalusStage2Address') snapshot = get_event_stats_snapshot() device_manager.register_device(DeviceType.TANTALUS_STAGE_1_FLARE, None, full_address_1) device_manager.register_device(DeviceType.TANTALUS_STAGE_2_FLARE, None, full_address_2) assert DEVICE_REGISTERED_EVENT.wait(snapshot, num_expected=2, timeout=0) == 2 assert device_manager.get_full_address( DeviceType.TANTALUS_STAGE_1_FLARE) == full_address_1 assert device_manager.get_full_address( DeviceType.TANTALUS_STAGE_2_FLARE) == full_address_2
def __init__(self, connections: Dict[str, Connection], rocket_profile: RocketProfile) -> None: """ :param connection: :type connection: Connection :param rocket_profile: :type rocket_profile: RocketProfile """ # Prints constructor arguments, leave at top of constructor LOGGER.debug(f"Starting MainApp with {locals()}") if connections is None: raise Exception("Invalid connections provided") QtWidgets.QMainWindow.__init__(self) self.setupUi(self) self.connections = connections self.rocket_profile = rocket_profile self.device_manager = DeviceManager( self.rocket_profile.expected_devices, self.rocket_profile.required_device_versions, strict_versions=False) self.rocket_data = RocketData(self.device_manager) self.command_parser = CommandParser(self.device_manager) packet_parser = self.rocket_profile.construct_packet_parser() # Init and connection of ReadThread self.ReadThread = ReadThread(self.connections, self.rocket_data, packet_parser, self.device_manager) self.ReadThread.sig_received.connect(self.receive_data) self.ReadThread.start() # Init and connection of SendThread self.SendThread = SendThread(self.connections, self.device_manager, self.command_parser) self.sig_send.connect(self.SendThread.queueMessage) self.SendThread.start()
def full_device_manager(): device_manager = DeviceManager(None, None) for device in DeviceType: device_manager.register_device(device, None, ('CONNECTION', device.name)) return device_manager