def get_connected_devices() -> ConnectedDevices: """Returns Mbed Devices connected to host computer. Connected devices which have been identified as Mbed Boards and also connected devices which are potentially Mbed Boards (but not could not be identified in the database) are returned. """ connected_devices = ConnectedDevices() for candidate_device in detect_candidate_devices(): device = Device.from_candidate(candidate_device) connected_devices.add_device(device) return connected_devices
def test_skips_candidates_without_a_board(self, board, resolve_board, detect_candidate_devices): candidate = CandidateDeviceFactory() resolve_board.side_effect = NoBoardForCandidate detect_candidate_devices.return_value = [candidate] board.return_value = None connected_devices = get_connected_devices() assert connected_devices.identified_devices == [] assert connected_devices.unidentified_devices == [ Device( serial_port=candidate.serial_port, serial_number=candidate.serial_number, mount_points=candidate.mount_points, mbed_board=None, ) ]
def test_builds_devices_from_candidates(self, resolve_board, detect_candidate_devices): candidate = CandidateDeviceFactory() detect_candidate_devices.return_value = [candidate] connected_devices = get_connected_devices() self.assertEqual( connected_devices.identified_devices, [ Device( serial_port=candidate.serial_port, serial_number=candidate.serial_number, mount_points=candidate.mount_points, mbed_board=resolve_board.return_value, ) ], ) self.assertEqual(connected_devices.unidentified_devices, []) resolve_board.assert_called_once_with(candidate)
def test_builds_devices_from_candidates(self, read_device_files, resolve_board, detect_candidate_devices): candidate = CandidateDeviceFactory() detect_candidate_devices.return_value = [candidate] iface_details = {"Version": "0222"} read_device_files.return_value = mock.Mock(interface_details=iface_details) connected_devices = get_connected_devices() assert connected_devices.identified_devices == [ Device( serial_port=candidate.serial_port, serial_number=candidate.serial_number, mount_points=candidate.mount_points, mbed_board=resolve_board.return_value, mbed_enabled=True, interface_version=iface_details["Version"], ) ] assert not connected_devices.unidentified_devices