Coverage for tests/unit_tests/commands/test_apio_create.py: 100%
34 statements
« prev ^ index » next coverage.py v7.16.1, created at 2026-09-23 03:53 +0000
« prev ^ index » next coverage.py v7.16.1, created at 2026-09-23 03:53 +0000
1"""Test for the "apio create" command."""
3from pathlib import Path
4from os.path import isfile, exists
5from configobj import ConfigObj
6from tests.conftest import ApioRunner
7from apio.commands.apio import apio_top_cli as apio
10def _check_ini_file(apio_ini: Path, expected_vars: dict[str, str]) -> None:
11 """Assert that apio.ini contains exactly the given vars."""
12 # Read the ini file.
13 assert isfile(apio_ini)
14 conf = ConfigObj(str(apio_ini))
15 # Check the expected comment at the top.
16 assert "# APIO project configuration file" in conf.initial_comment[0]
17 # Check the expected vars.
18 assert conf.dict() == {"env:default": expected_vars}
21def test_create(apio_runner: ApioRunner):
22 """Test "apio create" with different parameters"""
24 with apio_runner.in_sandbox() as sb:
26 apio_ini = Path("apio.ini")
27 assert not exists(apio_ini)
29 # -- Execute "apio create"
30 result = sb.invoke_apio_cmd(apio, ["create"])
31 assert result.exit_code != 0, result.output
32 assert "Error: Missing option" in result.output
33 assert not exists(apio_ini)
35 # -- Execute "apio create --board no-such-board"
36 result = sb.invoke_apio_cmd(
37 apio, ["create", "--board", "no-such-board"]
38 )
39 assert result.exit_code == 1, result.output
40 assert "Error: Unknown board id 'no-such-board'" in result.output
41 assert not exists(apio_ini)
43 # -- Execute "apio create --board alhambra-ii"
44 result = sb.invoke_apio_cmd(apio, ["create", "--board", "alhambra-ii"])
45 sb.assert_result_ok(result)
46 assert "was created successfully." in result.output
47 _check_ini_file(
48 apio_ini, {"board": "alhambra-ii", "top-module": "main"}
49 )
51 # -- Execute "apio create --board alhambra-ii
52 # -- --top-module my_module" with 'y' input"
53 result = sb.invoke_apio_cmd(
54 apio,
55 [
56 "create",
57 "--board",
58 "alhambra-ii",
59 "--top-module",
60 "my_module",
61 ],
62 )
63 assert result.exit_code != 0
64 assert "Error: The file apio.ini already exists." in result.output
65 _check_ini_file(
66 apio_ini, {"board": "alhambra-ii", "top-module": "main"}
67 )
69 # -- Execute "apio create --board alhambra-ii -p aa/bb"
70 result = sb.invoke_apio_cmd(
71 apio, ["create", "--board", "alhambra-ii", "-p", "aa/bb"]
72 )
73 sb.assert_result_ok(result)
74 assert "was created successfully." in result.output
75 _check_ini_file(
76 Path("aa/bb") / apio_ini,
77 {"board": "alhambra-ii", "top-module": "main"},
78 )