Coverage for tests/unit_tests/commands/test_apio_preferences.py: 100%
32 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 preferences" command."""
11import re
12from tests.conftest import ApioRunner
13from apio.common.apio_console import cunstyle
14from apio.commands.apio import apio_top_cli as apio
17def test_colors_on_off(apio_runner: ApioRunner):
18 """Test "apio preferences" with different parameters"""
20 with apio_runner.in_sandbox() as sb:
22 # -- Execute "apio preferences"
23 result = sb.invoke_apio_cmd(apio, ["preferences"])
24 sb.assert_result_ok(result)
25 assert "'apio preferences' allows" in cunstyle(result.output)
26 assert "-t, --theme [light|dark|no-colors]" in result.output
27 assert result.output != cunstyle(result.output) # Colored.
29 # -- Execute "apio preferences --theme dark"
30 result = sb.invoke_apio_cmd(apio, ["preferences", "--theme", "dark"])
31 sb.assert_result_ok(result)
32 assert "Theme set to [dark]" in result.output
33 assert result.output != cunstyle(result.output) # Colored.
35 # -- Execute "apio preferences --list". It should reports the dark
36 # -- theme.
37 result = sb.invoke_apio_cmd(apio, ["preferences", "--list"])
38 sb.assert_result_ok(result)
39 assert result.output != cunstyle(result.output) # Colored.
40 assert "dark" in result.output
42 # -- Execute "apio system info". It should emit colors.
43 result = sb.invoke_apio_cmd(apio, ["info", "system"])
44 sb.assert_result_ok(result)
45 assert result.output != cunstyle(result.output) # Colored.
47 # -- Execute "apio preferences --theme no-colors"
48 result = sb.invoke_apio_cmd(
49 apio, ["preferences", "--theme", "no-colors"]
50 )
51 sb.assert_result_ok(result)
52 assert "Theme set to [no-colors]" in result.output
54 # -- Execute "apio preferences --list". It should reports the
55 # -- no-colors theme.
56 result = sb.invoke_apio_cmd(apio, ["preferences", "--list"])
57 sb.assert_result_ok(result)
58 assert re.search(r"Theme.*no-colors", result.output), result.output
59 assert result.output == cunstyle(result.output) # Non colored..
61 # -- Execute "apio preferences --colors".
62 result = sb.invoke_apio_cmd(apio, ["preferences", "--colors"])
63 # -- It's normal to have 'error' in the output test.
64 sb.assert_result_ok(result, bad_words=[])
65 assert result.output != cunstyle(result.output) # Colored..
66 # -- Ideally we would like to have this assertion enabled but
67 # -- when running on github workflows we sometimes get different
68 # -- colors.
69 # assert "\x1b[38;5;237mbar.back " in result.output