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

45 statements  

« prev     ^ index     » next       coverage.py v7.13.0, created at 2025-12-24 01:53 +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 "type": "up5k", 

42 "pack": "sg48" 

43 } 

44} 

45""" 

46 

47 

48def test_boards_custom_board(apio_runner: ApioRunner): 

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

50 

51 with apio_runner.in_sandbox() as sb: 

52 

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

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

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

56 

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

58 sb.write_apio_ini( 

59 { 

60 "[env:default]": { 

61 "board": "my_custom_board", 

62 "top-module": "main", 

63 } 

64 } 

65 ) 

66 

67 # -- Execute "apio boards". 

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

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

70 sb.assert_result_ok(result) 

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

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

73 assert "alhambra-ii" in result.output 

74 assert "icebreaker" in result.output 

75 assert "my_custom_board" in result.output 

76 assert "CUSTOM-FPGA" in result.output 

77 

78 # -- Execute "apio boards --docs" 

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

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

81 sb.assert_result_ok(result) 

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

83 assert "FPGA" in result.output 

84 assert "alhambra-ii" in result.output 

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

86 

87 

88def test_boards_list_ok(apio_runner: ApioRunner): 

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

90 

91 with apio_runner.in_sandbox() as sb: 

92 

93 # -- Run 'apio boards' 

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

95 sb.assert_result_ok(result) 

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

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

98 assert "alhambra-ii" in result.output 

99 assert "my_custom_board" not in result.output 

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

101 

102 # -- Run 'apio boards -v' 

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

104 sb.assert_result_ok(result) 

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

106 assert "FPGA-ID" in result.output 

107 assert "alhambra-ii" in result.output 

108 assert "my_custom_board" not in result.output 

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

110 

111 # -- Run 'apio boards --docs' 

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

113 sb.assert_result_ok(result) 

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

115 assert "FPGA" in result.output 

116 assert "alhambra-ii" in result.output 

117 assert "my_custom_board" not in result.output 

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