Coverage for tests/unit_tests/test_main.py: 100%
18 statements
« prev ^ index » next coverage.py v7.17.2, created at 2026-11-07 05:08 +0000
« prev ^ index » next coverage.py v7.17.2, created at 2026-11-07 05:08 +0000
1# This file is part of the Apio project
2# (C) 2016-present FPGAwars
3# Project authors:
4# * Jesús Arroyo (Jesus89) (2016-2019)
5# * Juan Gonzalez (obijuan) (2019-2024)
6# * The Apio Team (2024-present)
7# License: GPLv2
9"""
10Tests of apio's __main__.py entry point.
11"""
13import os
14import sys
15import subprocess
16from subprocess import CompletedProcess
17from tests.conftest import ApioRunner
18from apio import __main__ as apio_main
21def _run_apio_version(extra_env: dict) -> CompletedProcess:
22 """Runs 'apio --version' in a fresh process with the given extra env
23 vars."""
24 return subprocess.run(
25 [sys.executable, apio_main.__file__, "--version"],
26 env={**os.environ, **extra_env},
27 capture_output=True,
28 encoding="utf-8",
29 text=True,
30 check=False,
31 )
34def test_apio_debug_env_var_values(apio_runner: ApioRunner):
35 """Tests that malformed APIO_DEBUG values don't crash the apio entry
36 point. It used to crash with an unhandled ValueError on every command."""
38 with apio_runner.in_sandbox():
40 # -- Malformed values should be tolerated (debug off).
41 for value in ["x", "", "1.5", '"x"', '"']:
42 result = _run_apio_version({"APIO_DEBUG": value})
43 assert result.returncode != 0, result.stderr
44 assert (
45 "Error: env value APIO_DEBUG" in result.stdout
46 ), result.stdout
48 # -- Valid values, including windows style quoted values, should
49 # -- work as before.
50 for value in ["0", "1", '"2"']:
51 result = _run_apio_version({"APIO_DEBUG": value})
52 assert result.returncode == 0, result.stderr
53 assert "Apio CLI version" in result.stdout, result.stdout