diff options
| author | Nasser Grainawi <nasser.grainawi@oss.qualcomm.com> | 2026-04-15 10:50:05 -0700 |
|---|---|---|
| committer | gerrit-scoped@luci-project-accounts.iam.gserviceaccount.com <gerrit-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2026-04-22 17:05:55 -0700 |
| commit | 03fb18109fb0db2522f36309242d16d0f83f17d2 (patch) | |
| tree | c2ee646907f144db82acc8ba8f05f396725c5ac4 | |
| parent | 5af71ce907848a546199f0d64a5dfba1db8adca0 (diff) | |
| download | git-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.py | 7 | ||||
| -rw-r--r-- | tests/conftest.py | 11 |
2 files changed, 15 insertions, 3 deletions
| @@ -14,6 +14,7 @@ | |||
| 14 | 14 | ||
| 15 | import os | 15 | import os |
| 16 | import sys | 16 | import sys |
| 17 | from typing import Optional | ||
| 17 | 18 | ||
| 18 | import pager | 19 | import pager |
| 19 | 20 | ||
| @@ -84,7 +85,7 @@ def _Color(fg=None, bg=None, attr=None): | |||
| 84 | DEFAULT = None | 85 | DEFAULT = None |
| 85 | 86 | ||
| 86 | 87 | ||
| 87 | def SetDefaultColoring(state): | 88 | def 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 | ||
| 19 | import pytest | 19 | import pytest |
| 20 | 20 | ||
| 21 | import color | ||
| 21 | import platform_utils | 22 | import platform_utils |
| 22 | import repo_trace | 23 | import 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) | ||
| 33 | def 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 |
| 32 | def _set_home(monkeypatch, path: pathlib.Path): | 43 | def _set_home(monkeypatch, path: pathlib.Path): |
| 33 | """ | 44 | """ |
