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

43 statements  

« prev     ^ index     » next       coverage.py v7.11.0, created at 2025-11-06 10:20 +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} 

21""" 

22 

23 

24def test_boards_custom_board(apio_runner: ApioRunner): 

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

26 

27 with apio_runner.in_sandbox() as sb: 

28 

29 # -- Write an apio.ini file. 

30 sb.write_apio_ini( 

31 { 

32 "[env:default]": { 

33 "board": "my_custom_board", 

34 "top-module": "main", 

35 } 

36 } 

37 ) 

38 

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

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

41 

42 # -- Execute "apio boards" 

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

44 sb.assert_result_ok(result) 

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

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

47 assert "alhambra-ii" not in result.output 

48 assert "my_custom_board" in result.output 

49 assert "Total of 1 board" in result.output 

50 

51 # -- Execute "apio boards --docs" 

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

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

54 sb.assert_result_ok(result) 

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

56 assert "FPGA" in result.output 

57 assert "alhambra-ii" in result.output 

58 assert "my_custom_board" not in result.output 

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

60 

61 

62def test_boards_list_ok(apio_runner: ApioRunner): 

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

64 

65 with apio_runner.in_sandbox() as sb: 

66 

67 # -- Run 'apio boards' 

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

69 sb.assert_result_ok(result) 

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

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

72 assert "alhambra-ii" in result.output 

73 assert "my_custom_board" not in result.output 

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

75 

76 # -- Run 'apio boards -v' 

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

78 sb.assert_result_ok(result) 

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

80 assert "FPGA-ID" in result.output 

81 assert "alhambra-ii" in result.output 

82 assert "my_custom_board" not in result.output 

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

84 

85 # -- Run 'apio boards --docs' 

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

87 sb.assert_result_ok(result) 

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

89 assert "FPGA" in result.output 

90 assert "alhambra-ii" in result.output 

91 assert "my_custom_board" not in result.output 

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