Coverage for tests/unit_tests/test_main.py: 100%
19 statements
« prev ^ index » next coverage.py v7.15.4, created at 2026-08-09 01:55 +0000
« prev ^ index » next coverage.py v7.15.4, created at 2026-08-09 01:55 +0000
1"""
2Tests of apio's __main__.py entry point.
3"""
5import os
6import sys
7import subprocess
8from subprocess import CompletedProcess
9from tests.conftest import ApioRunner
10from apio import __main__ as apio_main
13def _run_apio_version(extra_env: dict) -> CompletedProcess:
14 """Runs 'apio --version' in a fresh process with the given extra env
15 vars."""
16 return subprocess.run(
17 [sys.executable, apio_main.__file__, "--version"],
18 env={**os.environ, **extra_env},
19 capture_output=True,
20 encoding="utf-8",
21 text=True,
22 check=False,
23 )
26def test_apio_debug_env_var_values(apio_runner: ApioRunner):
27 """Tests that malformed APIO_DEBUG values don't crash the apio entry
28 point. It used to crash with an unhandled ValueError on every command."""
30 with apio_runner.in_sandbox():
32 # -- Malformed values should be tolerated (debug off).
33 for value in ["x", "", "1.5", '"x"', '"']:
34 result = _run_apio_version({"APIO_DEBUG": value})
35 assert result.returncode == 0, result.stderr
36 assert "Apio CLI version" in result.stdout, result.stdout
37 assert "Traceback" not in result.stderr, result.stderr
39 # -- Valid values, including windows style quoted values, should
40 # -- work as before.
41 for value in ["0", "1", '"2"']:
42 result = _run_apio_version({"APIO_DEBUG": value})
43 assert result.returncode == 0, result.stderr
44 assert "Apio CLI version" in result.stdout, result.stdout