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

13 statements  

« prev     ^ index     » next       coverage.py v7.11.0, created at 2025-11-06 10:20 +0000

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

2 

3from tests.conftest import ApioRunner 

4from apio.commands.apio import apio_top_cli as apio 

5 

6 

7def test_format_without_apio_ini(apio_runner: ApioRunner): 

8 """Tests the apio format command with a missing apio.ini file.""" 

9 

10 with apio_runner.in_sandbox() as sb: 

11 

12 # -- Run "apio format" with no apio.ini 

13 result = sb.invoke_apio_cmd(apio, ["format"]) 

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

15 assert "Error: Missing project file apio.ini" in result.output 

16 

17 

18def test_format_with_env_arg_error(apio_runner: ApioRunner): 

19 """Tests the command with an invalid --env value. This error message 

20 confirms that the --env arg was propagated to the apio.ini loading 

21 logic.""" 

22 

23 with apio_runner.in_sandbox() as sb: 

24 

25 # -- Run "apio format --env no-such-env" 

26 sb.write_apio_ini({"[env:default]": {"top-module": "main"}}) 

27 result = sb.invoke_apio_cmd(apio, ["format", "--env", "no-such-env"]) 

28 assert result.exit_code == 1, result.output 

29 assert ( 

30 "Error: Env 'no-such-env' not found in apio.ini" in result.output 

31 )