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

37 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_FPGAS = """ 

7{ 

8 "custom-ice40hx4k-bg121": { 

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

10 "arch": "ice40", 

11 "size": "4k", 

12 "type": "hx4k", 

13 "pack": "bg121" 

14 }, 

15 "ice40hx4k-tq144-8k": { 

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

17 "arch": "ice40", 

18 "size": "8k", 

19 "type": "hx8k", 

20 "pack": "tq144:4k" 

21 } 

22} 

23""" 

24 

25 

26def test_fpgas_ok(apio_runner: ApioRunner): 

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

28 

29 with apio_runner.in_sandbox() as sb: 

30 

31 # -- Execute "apio fpgas" 

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

33 sb.assert_result_ok(result) 

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

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

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

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

38 assert "my_custom_fpga" not in result.output 

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

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

41 

42 # -- Execute "apio fpgas --docs" 

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

44 sb.assert_result_ok(result) 

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

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

47 assert "my_custom_fpga" not in result.output 

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

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

50 

51 

52def test_custom_fpga(apio_runner: ApioRunner): 

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

54 

55 with apio_runner.in_sandbox() as sb: 

56 

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

58 # -- fpgas.jsonc. 

59 sb.write_default_apio_ini() 

60 

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

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

63 

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

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

66 sb.assert_result_ok(result) 

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

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

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

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

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

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

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

74 

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

76 # -- customization. 

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

78 sb.assert_result_ok(result) 

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

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

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

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

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

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

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