Esempio n. 1
0
 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.")
Esempio n. 2
0
    def test_json_dump_from_raw_and_filtered_data(self, mocked_get_offline_board_data, mocked_get_online_board_data):
        raw_board_data = [
            {"attributes": {"product_code": "0200", "board": "test"}},
            {"attributes": {"product_code": "0100", "board": "test2"}},
        ]
        mocked_get_online_board_data.return_value = raw_board_data

        boards = [Board.from_online_board_entry(b) for b in raw_board_data]
        filtered_board_data = [asdict(board) for board in boards]
        mocked_get_offline_board_data.return_value = filtered_board_data

        # Boards.from_online_database handles "raw" board entries from the online db
        boards = Boards.from_online_database()
        json_str_from_raw = boards.json_dump()
        t1_raw, t2_raw = boards

        # Boards.from_offline_database expects the data to have been "filtered" through the Boards interface
        offline_boards = Boards.from_offline_database()
        json_str_from_filtered = offline_boards.json_dump()
        t1_filt, t2_filt = offline_boards

        self.assertEqual(
            json_str_from_raw,
            json.dumps([asdict(t1_raw), asdict(t2_raw)], indent=4),
            "JSON string should match serialised board __dict__.",
        )

        self.assertEqual(json_str_from_filtered, json.dumps([t1_filt.__dict__, t2_filt.__dict__], indent=4))
Esempio n. 3
0
    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)
Esempio n. 4
0
    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)
Esempio n. 5
0
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),
    )