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

37 statements  

« prev     ^ index     » next       coverage.py v7.13.5, created at 2026-03-25 02:31 +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_FPGAS = """ 

7{ 

8 "custom-ice40hx4k-bg121": { 

9 "part-num": "CUSTOM-ICE40HX4K-BG121", 

10 "arch": "ice40", 

11 "size": "4k", 

12 "ice40-params": { 

13 "type": "hx4k", 

14 "package": "bg121" 

15 } 

16 }, 

17 "ice40hx4k-tq144-8k": { 

18 "part-num": "MODIFIED-ICE40HX4K-TQ144", 

19 "arch": "ice40", 

20 "size": "8k", 

21 "ice40-params": { 

22 "type": "hx8k", 

23 "package": "tq144:4k" 

24 } 

25 } 

26} 

27""" 

28 

29 

30def test_fpgas_ok(apio_runner: ApioRunner): 

31 """Test "apio fpgas" command with standard fpgas.jsonc.""" 

32 

33 with apio_runner.in_sandbox() as sb: 

34 

35 # -- Execute "apio fpgas" 

36 result = sb.invoke_apio_cmd(apio, ["fpgas"]) 

37 sb.assert_result_ok(result) 

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

39 # -- Run 'apio fpgas' | cat' to reproduce it. 

40 assert "Loading custom 'fpgas.jsonc'" not in result.output 

41 assert "ice40hx4k-tq144-8k" in result.output 

42 assert "my_custom_fpga" not in result.output 

43 assert "─────┐" in result.output # Graphic table border 

44 assert ":---" not in result.output # Graphic table border 

45 

46 # -- Execute "apio fpgas --docs" 

47 result = sb.invoke_apio_cmd(apio, ["fpgas", "--docs"]) 

48 sb.assert_result_ok(result) 

49 assert "Loading custom 'fpgas.jsonc'" not in result.output 

50 assert "ice40hx4k-tq144-8k" in result.output 

51 assert "my_custom_fpga" not in result.output 

52 assert "─────┐" not in result.output # Graphic table border 

53 assert ":---" in result.output # Graphic table border 

54 

55 

56def test_custom_fpga(apio_runner: ApioRunner): 

57 """Test "apio fpgas" command with a custom fpgas.jsonc.""" 

58 

59 with apio_runner.in_sandbox() as sb: 

60 

61 # -- Write apio.ini for apio to pick the project's default 

62 # -- fpgas.jsonc. 

63 sb.write_default_apio_ini() 

64 

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

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

67 

68 # -- Execute "apio fpgas". It should include the customization. 

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

70 sb.assert_result_ok(result) 

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

72 # -- Run 'apio build' | cat' to reproduce it. 

73 assert "Loading custom 'fpgas.jsonc'" in result.output 

74 assert "gw1nz-lv1qn48c6-i5" in result.output 

75 assert "custom-ice40hx4k-bg121" in result.output 

76 assert "ice40hx4k-tq144-8k" in result.output 

77 assert "CUSTOM-ICE40HX4K-BG121" in result.output 

78 

79 # -- Execute "apio fpgas --docs". It should not include the 

80 # -- customization. 

81 result = sb.invoke_apio_cmd(apio, ["fpgas", "--docs"]) 

82 sb.assert_result_ok(result) 

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

84 # -- Run 'apio build' | cat' to reproduce it. 

85 assert "Loading custom 'fpgas.jsonc'" not in result.output 

86 assert "gw1nz-lv1qn48c6-i5" in result.output 

87 assert "custom-ice40hx4k-bg121" not in result.output 

88 assert "ice40hx4k-tq144-8k" in result.output 

89 assert "CUSTOM-ICE40HX4K-BG121" not in result.output