Beispiel #1
0
    def test_raises_when_board_not_found(self, get_board_by_product_code,
                                         read_online_id, read_product_code,
                                         _get_all_htm_files_contents):
        get_board_by_product_code.side_effect = UnknownBoard
        candidate = CandidateDeviceFactory()

        with self.assertRaises(NoBoardForCandidate):
            resolve_board(candidate)
Beispiel #2
0
    def test_raises_when_board_not_found(self, get_board_by_online_id,
                                         read_online_id, read_product_code,
                                         _get_all_htm_files_contents):
        read_online_id.return_value = OnlineId(target_type="hat", slug="boat")
        get_board_by_online_id.side_effect = UnknownBoard
        candidate = CandidateDeviceFactory()

        with self.assertRaises(NoBoardForCandidate):
            resolve_board(candidate)
Beispiel #3
0
    def test_resolves_board_using_product_code_when_available(
            self, get_board_by_product_code, read_online_id, read_product_code,
            _get_all_htm_files_contents):
        candidate = CandidateDeviceFactory()

        subject = resolve_board(candidate)

        self.assertEqual(subject, get_board_by_product_code.return_value)
        get_board_by_product_code.assert_called_once_with(
            candidate.serial_number[:4])
Beispiel #4
0
    def test_returns_resolved_board(self, get_board_by_online_id,
                                    read_online_id, read_product_code,
                                    _get_all_htm_files_contents):
        online_id = OnlineId(target_type="hat", slug="boat")
        read_online_id.return_value = online_id
        candidate = CandidateDeviceFactory()

        subject = resolve_board(candidate)

        self.assertEqual(subject, get_board_by_online_id.return_value)
        read_online_id.assert_called_with(
            _get_all_htm_files_contents.return_value[0])
        get_board_by_online_id.assert_called_once_with(
            target_type=online_id.target_type, slug=online_id.slug)
Beispiel #5
0
    def test_returns_resolved_target(self, get_board_by_product_code,
                                     read_product_code,
                                     _get_all_htm_files_contents):
        read_product_code.return_value = "0123"
        candidate = CandidateDeviceFactory()

        subject = resolve_board(candidate)

        self.assertEqual(subject, get_board_by_product_code.return_value)
        get_board_by_product_code.assert_called_once_with(
            read_product_code.return_value)
        read_product_code.assert_called_once_with(
            _get_all_htm_files_contents.return_value[0])
        _get_all_htm_files_contents.assert_called_once_with(
            candidate.mount_points)
Beispiel #6
0
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.

    Raises:
        DeviceLookupFailed: If there is a problem with the process of identifying Mbed Boards from connected devices.
    """
    connected_devices = ConnectedDevices()

    for candidate_device in detect_candidate_devices():
        try:
            board = resolve_board(candidate_device)
        except NoBoardForCandidate:
            board = None
        except MbedTargetsError as err:
            raise DeviceLookupFailed("A problem occurred when looking up board data for connected devices.") from err

        connected_devices.add_device(candidate_device, board)

    return connected_devices