Coverage for tests/unit_tests/commands/test_apio_create.py: 100%
34 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"""Test for the "apio create" command."""
11from pathlib import Path
12from os.path import isfile, exists
13from configobj import ConfigObj
14from tests.conftest import ApioRunner
15from apio.commands.apio import apio_top_cli as apio
18def _check_ini_file(apio_ini: Path, expected_vars: dict[str, str]) -> None:
19 """Assert that apio.ini contains exactly the given vars."""
20 # Read the ini file.
21 assert isfile(apio_ini)
22 conf = ConfigObj(str(apio_ini))
23 # Check the expected comment at the top.
24 assert "# APIO project configuration file" in conf.initial_comment[0]
25 # Check the expected vars.
26 assert conf.dict() == {"env:default": expected_vars}
29def test_create(apio_runner: ApioRunner):
30 """Test "apio create" with different parameters"""
32 with apio_runner.in_sandbox() as sb:
34 apio_ini = Path("apio.ini")
35 assert not exists(apio_ini)
37 # -- Execute "apio create"
38 result = sb.invoke_apio_cmd(apio, ["create"])
39 assert result.exit_code != 0, result.output
40 assert "Error: Missing option" in result.output
41 assert not exists(apio_ini)
43 # -- Execute "apio create --board no-such-board"
44 result = sb.invoke_apio_cmd(
45 apio, ["create", "--board", "no-such-board"]
46 )
47 assert result.exit_code == 1, result.output
48 assert "Error: Unknown board id 'no-such-board'" in result.output
49 assert not exists(apio_ini)
51 # -- Execute "apio create --board alhambra-ii"
52 result = sb.invoke_apio_cmd(apio, ["create", "--board", "alhambra-ii"])
53 sb.assert_result_ok(result)
54 assert "was created successfully." in result.output
55 _check_ini_file(
56 apio_ini, {"board": "alhambra-ii", "top-module": "main"}
57 )
59 # -- Execute "apio create --board alhambra-ii
60 # -- --top-module my_module" with 'y' input"
61 result = sb.invoke_apio_cmd(
62 apio,
63 [
64 "create",
65 "--board",
66 "alhambra-ii",
67 "--top-module",
68 "my_module",
69 ],
70 )
71 assert result.exit_code != 0
72 assert "Error: The file apio.ini already exists." in result.output
73 _check_ini_file(
74 apio_ini, {"board": "alhambra-ii", "top-module": "main"}
75 )
77 # -- Execute "apio create --board alhambra-ii -p aa/bb"
78 result = sb.invoke_apio_cmd(
79 apio, ["create", "--board", "alhambra-ii", "-p", "aa/bb"]
80 )
81 sb.assert_result_ok(result)
82 assert "was created successfully." in result.output
83 _check_ini_file(
84 Path("aa/bb") / apio_ini,
85 {"board": "alhambra-ii", "top-module": "main"},
86 )