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