Coverage for tests/unit_tests/test_resources.py: 100%
22 statements
« prev ^ index » next coverage.py v7.16.1, created at 2026-09-23 03:53 +0000
« prev ^ index » next coverage.py v7.16.1, created at 2026-09-23 03:53 +0000
1"""
2Tests of apio_context.py
3"""
5from tests.conftest import ApioRunner
6from apio.apio_context import (
7 ApioContext,
8 PackagesPolicy,
9 ProjectPolicy,
10 RemoteConfigPolicy,
11)
12from apio.utils.resource_util import validate_config, validate_packages
15def test_resources_references(apio_runner: ApioRunner):
16 """Tests the consistency of the board references to fpgas and
17 programmers."""
19 with apio_runner.in_sandbox():
21 # -- Create an apio context so we can access the resources.
22 apio_ctx = ApioContext(
23 project_policy=ProjectPolicy.NO_PROJECT,
24 remote_config_policy=RemoteConfigPolicy.CACHED_OK,
25 packages_policy=PackagesPolicy.ENSURE_PACKAGES,
26 )
27 assert apio_ctx.definitions is not None
29 unused_programmers = set(apio_ctx.definitions.programmers.keys())
31 for board_id, board_definition in apio_ctx.definitions.boards.items():
32 # -- Prepare a context message for failing assertions.
33 board_msg = f"While testing board {board_id}"
35 # -- Check that the fpga exists.
36 board_fpga_id = board_definition.fpga_id
37 assert apio_ctx.definitions.fpgas[board_fpga_id], board_msg
39 # -- Check that the programmer exists.
40 board_programmer_id = board_definition.programmer.id
41 assert apio_ctx.definitions.programmers[
42 board_programmer_id
43 ], board_msg
45 # -- Track unused programmers. Since a programmer may be used
46 # -- by more than one board, it may already be removed.
47 if board_programmer_id in unused_programmers:
48 unused_programmers.remove(board_programmer_id)
50 # -- We should end up with an empty set of unused programmers.
51 assert not unused_programmers, unused_programmers
54def test_resources_are_valid(apio_runner: ApioRunner):
55 """Validate resources against a schema."""
56 with apio_runner.in_sandbox():
58 apio_ctx = ApioContext(
59 project_policy=ProjectPolicy.NO_PROJECT,
60 remote_config_policy=RemoteConfigPolicy.CACHED_OK,
61 packages_policy=PackagesPolicy.ENSURE_PACKAGES,
62 )
64 validate_config(apio_ctx.config)
65 validate_packages(apio_ctx.all_packages)