Coverage for tests/unit_tests/commands/test_apio_fpgas.py: 100%
35 statements
« prev ^ index » next coverage.py v7.11.0, created at 2025-11-06 10:20 +0000
« prev ^ index » next coverage.py v7.11.0, created at 2025-11-06 10:20 +0000
1"""Test for the "apio boards" command."""
3from tests.conftest import ApioRunner
4from apio.commands.apio import apio_top_cli as apio
6CUSTOM_FPGAS = """
7{
8 "ice40hx4k-tq144-8k": {
9 "part-num": "MY-CUSTOM_PART-NUM",
10 "arch": "ice40",
11 "size": "8k",
12 "type": "hx8k",
13 "pack": "tq144:4k"
14 }
15}
16"""
19def test_fpgas_ok(apio_runner: ApioRunner):
20 """Test "apio fpgas" command with standard fpgas.jsonc."""
22 with apio_runner.in_sandbox() as sb:
24 # -- Execute "apio fpgas"
25 result = sb.invoke_apio_cmd(apio, ["fpgas"])
26 sb.assert_result_ok(result)
27 # -- Note: pytest sees the piped version of the command's output.
28 # -- Run 'apio fpgas' | cat' to reproduce it.
29 assert "Loading custom 'fpgas.jsonc'" not in result.output
30 assert "ice40hx4k-tq144-8k" in result.output
31 assert "my_custom_fpga" not in result.output
32 assert "─────┐" in result.output # Graphic table border
33 assert ":---" not in result.output # Graphic table border
35 # -- Execute "apio fpgas --docs"
36 result = sb.invoke_apio_cmd(apio, ["fpgas", "--docs"])
37 sb.assert_result_ok(result)
38 assert "Loading custom 'fpgas.jsonc'" not in result.output
39 assert "ice40hx4k-tq144-8k" in result.output
40 assert "my_custom_fpga" not in result.output
41 assert "─────┐" not in result.output # Graphic table border
42 assert ":---" in result.output # Graphic table border
45def test_custom_fpga(apio_runner: ApioRunner):
46 """Test "apio fpgas" command with a custom fpgas.jsonc."""
48 with apio_runner.in_sandbox() as sb:
50 # -- Write apio.ini for apio to pick the project's default
51 # -- fpgas.jsonc.
52 sb.write_default_apio_ini()
54 # -- Write a custom boards.jsonc file in the project's directory.
55 sb.write_file("fpgas.jsonc", CUSTOM_FPGAS)
57 # -- Execute "apio boards"
58 result = sb.invoke_apio_cmd(apio, ["fpgas"])
59 sb.assert_result_ok(result)
60 # -- Note: pytest sees the piped version of the command's output.
61 # -- Run 'apio build' | cat' to reproduce it.
62 assert "Loading custom 'fpgas.jsonc'" in result.output
63 assert "MY-CUSTOM_PART-NUM" in result.output
64 assert "Total of 1 fpga" in result.output
66 # -- Execute "apio fpgas --docs"
67 # -- When running with --docs, 'apio boards' ignores custom fpgas.
68 result = sb.invoke_apio_cmd(apio, ["fpgas", "--docs"])
69 sb.assert_result_ok(result)
70 assert "Loading custom 'fpgas.jsonc'" not in result.output
71 assert "ice40hx4k-tq144-8k" in result.output
72 assert "my_custom_fpga" not in result.output
73 assert "─────┐" not in result.output # Graphic table border
74 assert ":---" in result.output # Graphic table border