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

37 statements  

« prev     ^ index     » next       coverage.py v7.17.2, created at 2026-11-07 05:08 +0000

1# This file is part of the Apio project 

2# (C) 2016-present FPGAwars 

3# Project authors: 

4# * Jesús Arroyo (Jesus89) (2016-2019) 

5# * Juan Gonzalez (obijuan) (2019-2024) 

6# * The Apio Team (2024-present) 

7# License: GPLv2 

8 

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

10 

11from tests.conftest import ApioRunner 

12from apio.commands.apio import apio_top_cli as apio 

13 

14CUSTOM_FPGAS = """ 

15{ 

16 "custom-ice40hx4k-bg121": { 

17 "arch": "ice40", 

18 "vendor-part": "CUSTOM-ICE40HX4K-BG121", 

19 "size": "4k", 

20 "ice40-params": { 

21 "nextpnr-type": "hx4k", 

22 "nextpnr-package": "bg121" 

23 } 

24 }, 

25 "ice40hx4k-tq144-8k": { 

26 "arch": "ice40", 

27 "vendor-part": "ICE40HX4K-TQ144", 

28 "size": "8k", 

29 "ice40-params": { 

30 "nextpnr-type": "modified-hx8k", 

31 "nextpnr-package": "tq144:4k" 

32 } 

33 } 

34} 

35""" 

36 

37 

38def test_fpgas_ok(apio_runner: ApioRunner): 

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

40 

41 with apio_runner.in_sandbox() as sb: 

42 

43 # -- Execute "apio fpgas" 

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

45 sb.assert_result_ok(result) 

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

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

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

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

50 assert "my_custom_fpga" not in result.output 

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

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

53 

54 # -- Execute "apio fpgas --docs" 

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

56 sb.assert_result_ok(result) 

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

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

59 assert "my_custom_fpga" not in result.output 

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

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

62 

63 

64def test_custom_fpga(apio_runner: ApioRunner): 

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

66 

67 with apio_runner.in_sandbox() as sb: 

68 

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

70 # -- fpgas.jsonc. 

71 sb.write_default_apio_ini() 

72 

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

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

75 

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

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

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'" in result.output 

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

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

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

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

86 

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

88 # -- customization. 

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

90 sb.assert_result_ok(result) 

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

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

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

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

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

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

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