def test_news_file_item_text_formatting(self): with mock.patch("ci_scripts.sync_board_database.Path", autospec=True) as mock_path: mock_path().exists.return_value = False text = sync_board_database.create_news_item_text( "New boards added:", Boards([ Board.from_online_board_entry(BOARD_1), Board.from_online_board_entry(BOARD_2) ]), ) self.assertEqual( text, "New boards added: u-blox NINA-B1, Multitech xDOT", "Text is formatted correctly.")
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)
def test_empty_database_entry(self): """Given no data, a Board is created with no information.""" board = Board.from_online_board_entry({}) self.assertEqual("", board.board_type) self.assertEqual("", board.board_name) self.assertEqual((), board.mbed_os_support) self.assertEqual((), board.mbed_enabled) self.assertEqual("", board.product_code) self.assertEqual("", board.target_type) self.assertEqual("", board.slug)
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"])
def make_board( board_type="BoardType", board_name="BoardName", mbed_os_support=None, mbed_enabled=None, product_code="9999", slug="BoardSlug", target_type="TargetType", ): return Board( board_type=board_type, product_code=product_code, board_name=board_name, target_type=target_type, slug=slug, mbed_os_support=mbed_os_support if mbed_os_support else (), mbed_enabled=mbed_enabled if mbed_enabled else (), build_variant=(), )
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)
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 _make_mbed_boards_for_diff(boards_a, boards_b): return ( Boards(Board.from_online_board_entry(b) for b in boards_a), Boards(Board.from_online_board_entry(b) for b in boards_b), )
def test_online_database_entry(self): online_data = { "type": "target", "id": "1", "attributes": { "features": { "mbed_enabled": ["Advanced"], "mbed_os_support": [ "Mbed OS 5.10", "Mbed OS 5.11", "Mbed OS 5.12", "Mbed OS 5.13", "Mbed OS 5.14", "Mbed OS 5.15", "Mbed OS 5.8", "Mbed OS 5.9", ], "antenna": ["Connector", "Onboard"], "certification": [ "Anatel (Brazil)", "AS/NZS (Australia and New Zealand)", "CE (Europe)", "FCC/CFR (USA)", "IC RSS (Canada)", "ICASA (South Africa)", "KCC (South Korea)", "MIC (Japan)", "NCC (Taiwan)", "RoHS (Europe)", ], "communication": ["Bluetooth & BLE"], "interface_firmware": ["DAPLink", "J-Link"], "target_core": ["Cortex-M4"], "mbed_studio_support": ["Build and run"], }, "board_type": "k64f", "flash_size": 512, "name": "u-blox NINA-B1", "product_code": "0455", "ram_size": 64, "target_type": "module", "hidden": False, "device_name": "nRF52832_xxAA", "slug": "u-blox-nina-b1", }, } board = Board.from_online_board_entry(online_data) self.assertEqual(online_data["attributes"]["board_type"].upper(), board.board_type) self.assertEqual(online_data["attributes"]["name"], board.board_name) self.assertEqual( tuple(online_data["attributes"]["features"]["mbed_os_support"]), board.mbed_os_support) self.assertEqual( tuple(online_data["attributes"]["features"]["mbed_enabled"]), board.mbed_enabled) self.assertEqual(online_data["attributes"]["product_code"], board.product_code) self.assertEqual(online_data["attributes"]["target_type"], board.target_type) self.assertEqual(online_data["attributes"]["slug"], board.slug) self.assertEqual(tuple(), board.build_variant)