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

25 statements  

« prev     ^ index     » next       coverage.py v7.14.3, created at 2026-06-24 03:51 +0000

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

2 

3from tests.conftest import ApioRunner 

4from apio.commands.apio import apio_top_cli as apio 

5 

6 

7def test_raw(apio_runner: ApioRunner): 

8 """Test "apio raw" with different parameters""" 

9 

10 with apio_runner.in_sandbox() as sb: 

11 

12 # -- NOTE: We run the apio raw command in a sub process to have a 

13 # -- proper sys.argv for it for the '--' separator validation. 

14 

15 # -- Execute "apio raw" 

16 result = sb.invoke_apio_cmd(apio, ["raw"], in_subprocess=True) 

17 assert result.exit_code != 0, result.output 

18 assert ( 

19 "at least one of --verbose or COMMAND must be specified" 

20 in result.output 

21 ) 

22 

23 # -- Execute "apio raw -v" 

24 result = sb.invoke_apio_cmd(apio, ["raw", "-v"], in_subprocess=True) 

25 sb.assert_result_ok(result) 

26 assert "Environment settings:" in result.output 

27 assert "PATH" in result.output 

28 assert "YOSYS_LIB" in result.output 

29 

30 # -- Run 'apio raw -- echo hello'. 

31 result = sb.invoke_apio_cmd( 

32 apio, ["raw", "--", "echo", "hello"], in_subprocess=True 

33 ) 

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

35 assert "hello" in result.output 

36 

37 # -- Run a command without the required '--' 

38 result = sb.invoke_apio_cmd(apio, ["raw", "echo"], in_subprocess=True) 

39 assert result.exit_code != 0, result.output 

40 assert "command separator '--' was not found" in result.output 

41 

42 # -- Run a command with a token before the '--' separator. 

43 result = sb.invoke_apio_cmd( 

44 apio, ["raw", "echo", "--", "--help"], in_subprocess=True 

45 ) 

46 assert result.exit_code != 0, result.output 

47 assert "Invalid arguments: ['echo']" in result.output 

48 

49 # -- Run 'apio raw -v' 

50 result = sb.invoke_apio_cmd(apio, ["raw", "-v"], in_subprocess=True) 

51 sb.assert_result_ok(result) 

52 assert "Environment settings:" in result.output 

53 assert "YOSYS_LIB" in result.output