Coverage for tests/unit_tests/commands/test_apio_preferences.py: 100%

32 statements  

« prev     ^ index     » next       coverage.py v7.11.0, created at 2025-11-06 10:20 +0000

1"""Test for the "apio preferences" command.""" 

2 

3import re 

4from tests.conftest import ApioRunner 

5from apio.common.apio_console import cunstyle 

6from apio.commands.apio import apio_top_cli as apio 

7 

8 

9def test_colors_on_off(apio_runner: ApioRunner): 

10 """Test "apio preferences" with different parameters""" 

11 

12 with apio_runner.in_sandbox() as sb: 

13 

14 # -- Execute "apio preferences" 

15 result = sb.invoke_apio_cmd(apio, ["preferences"]) 

16 sb.assert_result_ok(result) 

17 assert "'apio preferences' allows" in cunstyle(result.output) 

18 assert "-t, --theme [light|dark|no-colors]" in result.output 

19 assert result.output != cunstyle(result.output) # Colored. 

20 

21 # -- Execute "apio preferences --theme dark" 

22 result = sb.invoke_apio_cmd(apio, ["preferences", "--theme", "dark"]) 

23 sb.assert_result_ok(result) 

24 assert "Theme set to [dark]" in result.output 

25 assert result.output != cunstyle(result.output) # Colored. 

26 

27 # -- Execute "apio preferences --list". It should reports the dark 

28 # -- theme. 

29 result = sb.invoke_apio_cmd(apio, ["preferences", "--list"]) 

30 sb.assert_result_ok(result) 

31 assert result.output != cunstyle(result.output) # Colored. 

32 assert "dark" in result.output 

33 

34 # -- Execute "apio system info". It should emit colors. 

35 result = sb.invoke_apio_cmd(apio, ["info", "system"]) 

36 sb.assert_result_ok(result) 

37 assert result.output != cunstyle(result.output) # Colored. 

38 

39 # -- Execute "apio preferences --theme no-colors" 

40 result = sb.invoke_apio_cmd( 

41 apio, ["preferences", "--theme", "no-colors"] 

42 ) 

43 sb.assert_result_ok(result) 

44 assert "Theme set to [no-colors]" in result.output 

45 

46 # -- Execute "apio preferences --list". It should reports the 

47 # -- no-colors theme. 

48 result = sb.invoke_apio_cmd(apio, ["preferences", "--list"]) 

49 sb.assert_result_ok(result) 

50 assert re.search(r"Theme.*no-colors", result.output), result.output 

51 assert result.output == cunstyle(result.output) # Non colored.. 

52 

53 # -- Execute "apio preferences --colors". 

54 result = sb.invoke_apio_cmd(apio, ["preferences", "--colors"]) 

55 # -- It's normal to have 'error' in the output test. 

56 sb.assert_result_ok(result, bad_words=[]) 

57 assert result.output != cunstyle(result.output) # Colored.. 

58 # -- Ideally we would like to have this assertion enabled but 

59 # -- when running on github workflows we sometimes get different 

60 # -- colors. 

61 # assert "\x1b[38;5;237mbar.back " in result.output