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

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

7{ 

8 "ice40hx4k-tq144-8k": { 

9 "part-num": "MY-CUSTOM_PART-NUM", 

10 "arch": "ice40", 

11 "size": "8k", 

12 "type": "hx8k", 

13 "pack": "tq144:4k" 

14 } 

15} 

16""" 

17 

18 

19def test_fpgas_ok(apio_runner: ApioRunner): 

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

21 

22 with apio_runner.in_sandbox() as sb: 

23 

24 # -- Execute "apio fpgas" 

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

26 sb.assert_result_ok(result) 

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

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

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

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

31 assert "my_custom_fpga" not in result.output 

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

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

34 

35 # -- Execute "apio fpgas --docs" 

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

37 sb.assert_result_ok(result) 

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

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

40 assert "my_custom_fpga" not in result.output 

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

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

43 

44 

45def test_custom_fpga(apio_runner: ApioRunner): 

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

47 

48 with apio_runner.in_sandbox() as sb: 

49 

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

51 # -- fpgas.jsonc. 

52 sb.write_default_apio_ini() 

53 

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

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

56 

57 # -- Execute "apio boards" 

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

59 sb.assert_result_ok(result) 

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

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

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

63 assert "MY-CUSTOM_PART-NUM" in result.output 

64 assert "Total of 1 fpga" in result.output 

65 

66 # -- Execute "apio fpgas --docs" 

67 # -- When running with --docs, 'apio boards' ignores custom fpgas. 

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

69 sb.assert_result_ok(result) 

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

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

72 assert "my_custom_fpga" not in result.output 

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

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