summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNasser Grainawi <nasser.grainawi@oss.qualcomm.com>2026-04-15 10:50:05 -0700
committergerrit-scoped@luci-project-accounts.iam.gserviceaccount.com <gerrit-scoped@luci-project-accounts.iam.gserviceaccount.com>2026-04-22 17:05:55 -0700
commit03fb18109fb0db2522f36309242d16d0f83f17d2 (patch)
treec2ee646907f144db82acc8ba8f05f396725c5ac4
parent5af71ce907848a546199f0d64a5dfba1db8adca0 (diff)
downloadgit-repo-03fb18109fb0db2522f36309242d16d0f83f17d2.tar.gz
color: type SetDefaultColoring and drop bool states
Also add a test fixture to always disable coloring so that we get reproducible test behavior. The few tests that want to check color behavior (e.g. test_color.py) can still reset/change color values as needed. Change-Id: I1808139a63e0862c29bf81d7097e885ca8561040 Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/573621 Reviewed-by: Gavin Mak <gavinmak@google.com> Reviewed-by: Mike Frysinger <vapier@google.com> Commit-Queue: Nasser Grainawi <nasser.grainawi@oss.qualcomm.com> Tested-by: Nasser Grainawi <nasser.grainawi@oss.qualcomm.com>
-rw-r--r--color.py7
-rw-r--r--tests/conftest.py11
2 files changed, 15 insertions, 3 deletions
diff --git a/color.py b/color.py
index 9d0ce7c36..03fb65537 100644
--- a/color.py
+++ b/color.py
@@ -14,6 +14,7 @@
14 14
15import os 15import os
16import sys 16import sys
17from typing import Optional
17 18
18import pager 19import pager
19 20
@@ -84,7 +85,7 @@ def _Color(fg=None, bg=None, attr=None):
84DEFAULT = None 85DEFAULT = None
85 86
86 87
87def SetDefaultColoring(state): 88def SetDefaultColoring(state: Optional[str]) -> None:
88 """Set coloring behavior to |state|. 89 """Set coloring behavior to |state|.
89 90
90 This is useful for overriding config options via the command line. 91 This is useful for overriding config options via the command line.
@@ -97,9 +98,9 @@ def SetDefaultColoring(state):
97 state = state.lower() 98 state = state.lower()
98 if state in ("auto",): 99 if state in ("auto",):
99 DEFAULT = state 100 DEFAULT = state
100 elif state in ("always", "yes", "true", True): 101 elif state in ("always", "yes", "true"):
101 DEFAULT = "always" 102 DEFAULT = "always"
102 elif state in ("never", "no", "false", False): 103 elif state in ("never", "no", "false"):
103 DEFAULT = "never" 104 DEFAULT = "never"
104 105
105 106
diff --git a/tests/conftest.py b/tests/conftest.py
index a13edd7af..ce3c3d6ce 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -18,6 +18,7 @@ import pathlib
18 18
19import pytest 19import pytest
20 20
21import color
21import platform_utils 22import platform_utils
22import repo_trace 23import repo_trace
23 24
@@ -28,6 +29,16 @@ def disable_repo_trace(tmp_path):
28 repo_trace._TRACE_FILE = str(tmp_path / "TRACE_FILE_from_test") 29 repo_trace._TRACE_FILE = str(tmp_path / "TRACE_FILE_from_test")
29 30
30 31
32@pytest.fixture(autouse=True)
33def restore_default_coloring() -> None:
34 """Force disable color for reproducible test behavior.
35
36 The few tests that cover color behavior can still reset/change the color as
37 needed.
38 """
39 color.SetDefaultColoring("never")
40
41
31# adapted from pytest-home 0.5.1 42# adapted from pytest-home 0.5.1
32def _set_home(monkeypatch, path: pathlib.Path): 43def _set_home(monkeypatch, path: pathlib.Path):
33 """ 44 """