Coverage for tests/unit_tests/commands/test_apio_boards.py: 100%
45 statements
« prev ^ index » next coverage.py v7.17.2, created at 2026-11-07 05:08 +0000
« prev ^ index » next coverage.py v7.17.2, created at 2026-11-07 05:08 +0000
1# This file is part of the Apio project
2# (C) 2016-present FPGAwars
3# Project authors:
4# * Jesús Arroyo (Jesus89) (2016-2019)
5# * Juan Gonzalez (obijuan) (2019-2024)
6# * The Apio Team (2024-present)
7# License: GPLv2
9"""Test for the "apio boards" command."""
11from tests.conftest import ApioRunner
12from apio.commands.apio import apio_top_cli as apio
14CUSTOM_BOARDS = """
15{
16 "my-custom-board": {
17 "description": "My description",
18 "fpga-id": "ice40up5k-sg48",
19 "programmer": {
20 "id": "iceprog"
21 },
22 "usb": {
23 "vid": "0403",
24 "pid": "6010",
25 "product-regex": "^My Custom Board"
26 }
27 },
28 "icebreaker": {
29 "description": "iCEBreaker",
30 "fpga-id": "custom-fpga",
31 "programmer": {
32 "id": "iceprog"
33 },
34 "usb": {
35 "vid": "0403",
36 "pid": "6010",
37 "product-regex": "^(Dual RS232-HS)|(iCEBreaker.*)"
38 }
39 }
40}
41"""
43CUSTOM_FPGAS = """
44{
45 "custom-fpga": {
46 "arch": "ice40",
47 "vendor-part": "CUSTOM-FPGA",
48 "size": "5k",
49 "ice40-params": {
50 "nextpnr-type": "up5k",
51 "nextpnr-package": "sg48"
52 }
53 }
54}
55"""
58def test_boards_custom_board(apio_runner: ApioRunner):
59 """Test boards listing with a custom boards.jsonc file."""
61 with apio_runner.in_sandbox() as sb:
63 # -- Write a custom boards.jsonc file in the project's directory.
64 sb.write_file("fpgas.jsonc", CUSTOM_FPGAS)
65 sb.write_file("boards.jsonc", CUSTOM_BOARDS)
67 # -- Write an apio.ini file with the custom board.
68 sb.write_apio_ini(
69 {
70 "[env:default]": {
71 "board": "my-custom-board",
72 "top-module": "main",
73 }
74 }
75 )
77 # -- Execute "apio boards".
78 # -- We should see also the custom board and the modified board..
79 result = sb.invoke_apio_cmd(apio, ["boards"])
80 sb.assert_result_ok(result)
81 # -- Note: pytest sees the piped version of the command's output.
82 assert "Loading custom 'boards.jsonc'" in result.output
83 assert "alhambra-ii" in result.output
84 assert "icebreaker" in result.output
85 assert "my-custom-board" in result.output
86 assert "CUSTOM-FPGA" in result.output
88 # -- Execute "apio boards --docs"
89 # -- With the --docs flag we ignore the custom board.
90 result = sb.invoke_apio_cmd(apio, ["boards", "--docs"])
91 sb.assert_result_ok(result)
92 assert "Loading custom 'boards.jsonc'" not in result.output
93 assert "FPGA" in result.output
94 assert "alhambra-ii" in result.output
95 assert "CUSTOM-FPGA" not in result.output
98def test_boards_list_ok(apio_runner: ApioRunner):
99 """Test normal board listing with the apio's boards.jsonc."""
101 with apio_runner.in_sandbox() as sb:
103 # -- Run 'apio boards'
104 result = sb.invoke_apio_cmd(apio, ["boards"])
105 sb.assert_result_ok(result)
106 assert "Loading custom 'boards.jsonc'" not in result.output
107 assert "FPGA-ID" not in result.output
108 assert "alhambra-ii" in result.output
109 assert "my-custom-board" not in result.output
110 assert "Total of 1 board" not in result.output
112 # -- Run 'apio boards -v'
113 result = sb.invoke_apio_cmd(apio, ["boards", "-v"])
114 sb.assert_result_ok(result)
115 assert "Loading custom 'boards.jsonc'" not in result.output
116 assert "FPGA-ID" in result.output
117 assert "alhambra-ii" in result.output
118 assert "my-custom-board" not in result.output
119 assert "Total of 1 board" not in result.output
121 # -- Run 'apio boards --docs'
122 result = sb.invoke_apio_cmd(apio, ["boards", "--docs"])
123 sb.assert_result_ok(result)
124 assert "Loading custom 'boards.jsonc'" not in result.output
125 assert "FPGA" in result.output
126 assert "alhambra-ii" in result.output
127 assert "my-custom-board" not in result.output
128 assert "Total of 1 board" not in result.output