Exemplo n.º 1
0
    def test_offline_database_entry(self):
        """Given an entry from the offline database, a Board is generated with the correct information."""
        board = Board.from_offline_board_entry({
            "mbed_os_support": ["Mbed OS 5.15"],
            "mbed_enabled": ["Basic"],
            "board_type":
            "B_1",
            "board_name":
            "Board 1",
            "product_code":
            "P1",
            "target_type":
            "platform",
            "slug":
            "Le Slug",
        })

        self.assertEqual("B_1", board.board_type)
        self.assertEqual("Board 1", board.board_name)
        self.assertEqual(("Mbed OS 5.15", ), board.mbed_os_support)
        self.assertEqual(("Basic", ), board.mbed_enabled)
        self.assertEqual("P1", board.product_code)
        self.assertEqual("platform", board.target_type)
        self.assertEqual("Le Slug", board.slug)
        self.assertEqual((), board.build_variant)
Exemplo n.º 2
0
    def from_candidate(cls, candidate: CandidateDevice) -> "Device":
        """Contruct a Device from a CandidateDevice.

        We try to resolve a board using data files that may be stored on the CandidateDevice.
        If this fails we set the board to `None` which means we couldn't verify this Device
        as being an Mbed enabled device.

        Args:
            candidate: The CandidateDevice we're using to create the Device.
        """
        device_file_info = read_device_files(candidate.mount_points)
        try:
            mbed_board = resolve_board(device_file_info.product_code,
                                       device_file_info.online_id,
                                       candidate.serial_number)
            mbed_enabled = True
        except NoBoardForCandidate:
            # Create an empty Board to ensure the device is fully populated and rendering is simple
            mbed_board = Board.from_offline_board_entry({})
            mbed_enabled = False
        except ResolveBoardError:
            raise DeviceLookupFailed(
                f"Failed to resolve the board for candidate device {candidate!r}. There was a problem looking up the "
                "board data in the database.")

        return Device(
            serial_port=candidate.serial_port,
            serial_number=candidate.serial_number,
            mount_points=candidate.mount_points,
            mbed_board=mbed_board,
            mbed_enabled=mbed_enabled,
            interface_version=device_file_info.interface_details.get(
                "Version"),
        )
    def test_empty_values_keys_are_always_present(self):
        """Asserts that keys are present even if value is None."""
        device = Device(
            mbed_board=Board.from_offline_board_entry({}),
            serial_number="foo",
            serial_port=None,
            mount_points=[],
        )

        output = json.loads(_build_json_output([device]))

        self.assertIsNone(output[0]["serial_port"])
Exemplo n.º 4
0
    def add_device(self, candidate_device: CandidateDevice, mbed_board: Optional[Board] = None) -> None:
        """Add a candidate device and optionally an Mbed Target to the connected devices.

        Args:
            candidate_device: a CandidateDevice object containing the device information.
            mbed_board: a Board object for identified devices, for unidentified devices this will be None.
        """
        new_device = Device(
            serial_port=candidate_device.serial_port,
            serial_number=candidate_device.serial_number,
            mount_points=candidate_device.mount_points,
            # Create an empty Board to ensure the device is fully populated and rendering is simple
            mbed_board=mbed_board if mbed_board is not None else Board.from_offline_board_entry({}),
        )

        if mbed_board is None:
            # Keep a list of devices that could not be identified but are Mbed Boards
            self.unidentified_devices.append(new_device)
        else:
            # Keep a list of devices that have been identified as Mbed Boards
            self.identified_devices.append(new_device)
    def test_displays_unknown_serial_port_value(self):
        device = Device(
            mbed_board=Board.from_offline_board_entry({}),
            serial_number="serial",
            serial_port=None,
            mount_points=[pathlib.Path("somepath")],
        )

        output = _build_tabular_output([device])

        expected_output = tabulate(
            [[
                "<unknown>",
                device.serial_number,
                "<unknown>",
                "\n".join(map(str, device.mount_points)),
                "\n".join(_get_build_targets(device.mbed_board)),
            ]],
            headers=[
                "Board name", "Serial number", "Serial port", "Mount point(s)",
                "Build target(s)"
            ],
        )
        self.assertEqual(output, expected_output)