Coverage for tests/unit_tests/commands/test_apio_clean.py: 100%
39 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 clean" command."""
11import os
12from pathlib import Path
13from tests.conftest import ApioRunner
14from apio.commands.apio import apio_top_cli as apio
17def test_clean(apio_runner: ApioRunner):
18 """Tests the 'apio clean' with two envs. It should delete _build."""
20 with apio_runner.in_sandbox() as sb:
22 sb.write_apio_ini(
23 {
24 "[env:env1]": {
25 "board": "alhambra-ii",
26 "top-module": "main",
27 },
28 "[env:env2]": {
29 "board": "alhambra-ii",
30 "top-module": "main",
31 },
32 }
33 )
35 sb.write_file("_build/env1/hardware.out", "dummy text")
36 sb.write_file("_build/env2/hardware.out", "dummy text")
38 assert Path("_build/env1/hardware.out").exists()
39 assert Path("_build/env2/hardware.out").exists()
41 result = sb.invoke_apio_cmd(apio, ["clean"])
43 sb.assert_result_ok(result)
44 assert "Removed _build" in result.output
45 assert not Path("_build").exists()
48def test_clean_from_remote_dir(apio_runner: ApioRunner):
49 """Tests the 'apio clean' with two envs. It should delete _build."""
51 with apio_runner.in_sandbox() as sb:
53 # -- Cache directories values.
54 proj_dir: Path = sb.proj_dir
55 remote_dir: Path = sb.sandbox_dir
57 sb.write_apio_ini(
58 {
59 "[env:env1]": {
60 "board": "alhambra-ii",
61 "top-module": "main",
62 },
63 "[env:env2]": {
64 "board": "alhambra-ii",
65 "top-module": "main",
66 },
67 }
68 )
70 sb.write_file("_build/env1/hardware.out", "dummy text")
71 sb.write_file("_build/env2/hardware.out", "dummy text")
73 assert Path("_build/env1/hardware.out").exists()
74 assert Path("_build/env2/hardware.out").exists()
76 # -- Run the clean command from a remote dir.
77 os.chdir(remote_dir)
78 assert not Path("apio.ini").exists()
79 result = sb.invoke_apio_cmd(
80 apio, ["clean", "--project-dir", str(proj_dir)]
81 )
82 sb.assert_result_ok(result)
83 assert "Removed _build" in result.output
84 os.chdir(proj_dir)
85 assert not Path("_build").exists()
88def test_clean_no_build(apio_runner: ApioRunner):
89 """Tests the 'apio clean' command with nothing to delete."""
91 with apio_runner.in_sandbox() as sb:
93 sb.write_default_apio_ini()
95 assert not Path("_build").exists()
97 result = sb.invoke_apio_cmd(apio, ["clean"])
98 sb.assert_result_ok(result)
99 assert "Removed" not in result.output
100 assert "Already clean" in result.output