Coverage for tests / unit_tests / commands / test_apio_boards.py: 100%

45 statements  

« prev     ^ index     » next       coverage.py v7.13.5, created at 2026-03-26 02:38 +0000

1"""Test for the "apio boards" command.""" 

2 

3from tests.conftest import ApioRunner 

4from apio.commands.apio import apio_top_cli as apio 

5 

6CUSTOM_BOARDS = """ 

7{ 

8 "my_custom_board": { 

9 "description": "My description", 

10 "fpga-id": "ice40up5k-sg48", 

11 "programmer": { 

12 "id": "iceprog" 

13 }, 

14 "usb": { 

15 "vid": "0403", 

16 "pid": "6010", 

17 "product-regex": "^My Custom Board" 

18 } 

19 }, 

20 "icebreaker": { 

21 "description": "iCEBreaker", 

22 "fpga-id": "custom-fpga", 

23 "programmer": { 

24 "id": "iceprog" 

25 }, 

26 "usb": { 

27 "vid": "0403", 

28 "pid": "6010", 

29 "product-regex": "^(Dual RS232-HS)|(iCEBreaker.*)" 

30 } 

31 } 

32} 

33""" 

34 

35CUSTOM_FPGAS = """ 

36{ 

37 "custom-fpga": { 

38 "part-num": "CUSTOM-FPGA", 

39 "arch": "ice40", 

40 "size": "5k", 

41 "ice40-params": { 

42 "type": "up5k", 

43 "package": "sg48" 

44 } 

45 } 

46} 

47""" 

48 

49 

50def test_boards_custom_board(apio_runner: ApioRunner): 

51 """Test boards listing with a custom boards.jsonc file.""" 

52 

53 with apio_runner.in_sandbox() as sb: 

54 

55 # -- Write a custom boards.jsonc file in the project's directory. 

56 sb.write_file("fpgas.jsonc", CUSTOM_FPGAS) 

57 sb.write_file("boards.jsonc", CUSTOM_BOARDS) 

58 

59 # -- Write an apio.ini file with the custom board. 

60 sb.write_apio_ini( 

61 { 

62 "[env:default]": { 

63 "board": "my_custom_board", 

64 "top-module": "main", 

65 } 

66 } 

67 ) 

68 

69 # -- Execute "apio boards". 

70 # -- We should see also the custom board and the modified board.. 

71 result = sb.invoke_apio_cmd(apio, ["boards"]) 

72 sb.assert_result_ok(result) 

73 # -- Note: pytest sees the piped version of the command's output. 

74 assert "Loading custom 'boards.jsonc'" in result.output 

75 assert "alhambra-ii" in result.output 

76 assert "icebreaker" in result.output 

77 assert "my_custom_board" in result.output 

78 assert "CUSTOM-FPGA" in result.output 

79 

80 # -- Execute "apio boards --docs" 

81 # -- With the --docs flag we ignore the custom board. 

82 result = sb.invoke_apio_cmd(apio, ["boards", "--docs"]) 

83 sb.assert_result_ok(result) 

84 assert "Loading custom 'boards.jsonc'" not in result.output 

85 assert "FPGA" in result.output 

86 assert "alhambra-ii" in result.output 

87 assert "CUSTOM-FPGA" not in result.output 

88 

89 

90def test_boards_list_ok(apio_runner: ApioRunner): 

91 """Test normal board listing with the apio's boards.jsonc.""" 

92 

93 with apio_runner.in_sandbox() as sb: 

94 

95 # -- Run 'apio boards' 

96 result = sb.invoke_apio_cmd(apio, ["boards"]) 

97 sb.assert_result_ok(result) 

98 assert "Loading custom 'boards.jsonc'" not in result.output 

99 assert "FPGA-ID" not in result.output 

100 assert "alhambra-ii" in result.output 

101 assert "my_custom_board" not in result.output 

102 assert "Total of 1 board" not in result.output 

103 

104 # -- Run 'apio boards -v' 

105 result = sb.invoke_apio_cmd(apio, ["boards", "-v"]) 

106 sb.assert_result_ok(result) 

107 assert "Loading custom 'boards.jsonc'" not in result.output 

108 assert "FPGA-ID" in result.output 

109 assert "alhambra-ii" in result.output 

110 assert "my_custom_board" not in result.output 

111 assert "Total of 1 board" not in result.output 

112 

113 # -- Run 'apio boards --docs' 

114 result = sb.invoke_apio_cmd(apio, ["boards", "--docs"]) 

115 sb.assert_result_ok(result) 

116 assert "Loading custom 'boards.jsonc'" not in result.output 

117 assert "FPGA" in result.output 

118 assert "alhambra-ii" in result.output 

119 assert "my_custom_board" not in result.output 

120 assert "Total of 1 board" not in result.output