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

60 statements  

« prev     ^ index     » next       coverage.py v7.16.1, created at 2026-09-23 03:53 +0000

1"""Test for the "apio system" command.""" 

2 

3import re 

4from tests.conftest import ApioRunner 

5from apio.commands.apio import apio_top_cli as apio 

6from apio.common.apio_console import cunstyle, cwidth 

7 

8 

9def test_apio_info(apio_runner: ApioRunner): 

10 """Test 'apio info'""" 

11 

12 with apio_runner.in_sandbox() as sb: 

13 # -- For debugging table column truncation in github testing. 

14 print(f"Apio console width = {cwidth()}") 

15 

16 # -- Execute "apio info" 

17 result = sb.invoke_apio_cmd(apio, ["info"]) 

18 sb.assert_result_ok(result) 

19 assert "system" in result.output 

20 assert "platforms" in result.output 

21 assert "commands" in result.output 

22 

23 

24def test_apio_info_system(apio_runner: ApioRunner): 

25 """Test 'apio info system'""" 

26 

27 with apio_runner.in_sandbox() as sb: 

28 # -- For debugging table column truncation in github testing. 

29 print(f"Apio console width = {cwidth()}") 

30 

31 # -- Execute "apio info system" 

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

33 sb.assert_result_ok(result) 

34 assert "Platform id" in result.output 

35 # -- The these env options are set by the apio text fixture. We 

36 # -- relax the expression to allow additional env vars that are 

37 # -- injected to the test such as APIO_REMOTE_URL_CONFIG 

38 assert re.search( 

39 r"Active env options \[[^]]*APIO_HOME[^]]*\]", result.output 

40 ) 

41 

42 

43def test_apio_info_project(apio_runner: ApioRunner): 

44 """Test 'apio info project'""" 

45 

46 with apio_runner.in_sandbox() as sb: 

47 # -- For debugging table column truncation in github testing. 

48 print(f"Apio console width = {cwidth()}") 

49 

50 # -- Execute "apio examples fetch alhambra-ii/blinky" 

51 # -- This will create a valid project in the current directory. 

52 result = sb.invoke_apio_cmd( 

53 apio, ["examples", "fetch", "alhambra-ii/blinky"] 

54 ) 

55 sb.assert_result_ok(result) 

56 assert "'alhambra-ii/blinky' fetched successfully" in result.output 

57 

58 # -- Execute "apio info project" 

59 result = sb.invoke_apio_cmd(apio, ["info", "project"]) 

60 sb.assert_result_ok(result) 

61 assert re.search(r"Active project env.*│.*default", result.output) 

62 

63 

64def test_apio_info_platforms(apio_runner: ApioRunner): 

65 """Test "apio info platforms'""" 

66 

67 with apio_runner.in_sandbox() as sb: 

68 # -- For debugging table column truncation in github testing. 

69 print(f"Apio console width = {cwidth()}") 

70 

71 # -- Execute "apio info platforms" 

72 result = sb.invoke_apio_cmd(apio, ["info", "platforms"]) 

73 sb.assert_result_ok(result) 

74 assert "darwin-arm64" in result.output 

75 assert "Mac OSX" in result.output 

76 assert "ARM 64 bit (Apple Silicon)" in result.output 

77 

78 

79def test_apio_info_colors(apio_runner: ApioRunner): 

80 """Test 'apio info colors'""" 

81 

82 with apio_runner.in_sandbox() as sb: 

83 # -- For debugging table column truncation in github testing. 

84 print(f"Apio console width = {cwidth()}") 

85 

86 # -- Execute "apio info colors" 

87 result = sb.invoke_apio_cmd(apio, ["info", "colors"]) 

88 sb.assert_result_ok(result) 

89 assert result.output != cunstyle(result.output) # Colored 

90 assert "ANSI Colors" in result.output 

91 assert "\x1b[31m 1 red \x1b[0m" in result.output 

92 

93 

94def test_apio_info_themes(apio_runner: ApioRunner): 

95 """Test 'apio info theme'""" 

96 

97 with apio_runner.in_sandbox() as sb: 

98 # -- For debugging table column truncation in github testing. 

99 print(f"Apio console width = {cwidth()}") 

100 

101 # -- Execute "apio info themes" 

102 result = sb.invoke_apio_cmd(apio, ["info", "themes"]) 

103 # -- It's normal to have 'error' in the output text. 

104 sb.assert_result_ok(result, bad_words=[]) 

105 assert result.output != cunstyle(result.output) # Colored 

106 assert "NO-COLORS" in result.output 

107 assert "apio.cmd_name\x1b[0m" in result.output 

108 

109 

110def test_apio_info_commands(apio_runner: ApioRunner): 

111 """Test 'apio commands'""" 

112 

113 with apio_runner.in_sandbox() as sb: 

114 # -- For debugging table column truncation in github testing. 

115 print(f"Apio console width = {cwidth()}") 

116 

117 # -- Execute "apio info commands" 

118 result = sb.invoke_apio_cmd(apio, ["info", "commands"]) 

119 sb.assert_result_ok(result) 

120 assert " build " in cunstyle(result.output) 

121 assert "Synthesize the bitstream." in result.output 

122 assert "[build](cmd-apio-build.md)" not in result.output