Ejemplo n.º 1
0
    def test_raises_when_resolve_board_fails(self, read_device_files, resolve_board, detect_candidate_devices):
        candidate = CandidateDeviceFactory()
        resolve_board.side_effect = ResolveBoardError
        detect_candidate_devices.return_value = [candidate]

        with pytest.raises(DeviceLookupFailed, match="candidate"):
            get_connected_devices()
Ejemplo n.º 2
0
    def test_raises_device_lookup_failed_on_internal_error(
            self, resolve_board, detect_candidate_devices):
        resolve_board.side_effect = MbedTargetsError
        detect_candidate_devices.return_value = [CandidateDeviceFactory()]

        with self.assertRaises(DeviceLookupFailed):
            get_connected_devices()
Ejemplo n.º 3
0
 def test_find_candidates_successful_build_yields_candidate(
         self, system_profiler, _build_candidate):
     device_data = {"some": "data"}
     system_profiler.get_end_usb_devices_data.return_value = [device_data]
     candidate = CandidateDeviceFactory()
     _build_candidate.return_value = candidate
     self.assertEqual(DarwinDeviceDetector().find_candidates(), [candidate])
     _build_candidate.assert_called_with(device_data)
Ejemplo n.º 4
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)
Ejemplo n.º 5
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)
Ejemplo n.º 6
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])
Ejemplo n.º 7
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)
Ejemplo n.º 8
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)
Ejemplo n.º 9
0
    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,
            )
        ]
Ejemplo n.º 10
0
    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)
Ejemplo n.º 11
0
    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