mirror of
https://gerrit.googlesource.com/git-repo
synced 2026-05-07 03:28:31 +00:00
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>
This commit is contained in:
committed by
gerrit-scoped@luci-project-accounts.iam.gserviceaccount.com
parent
5af71ce907
commit
03fb18109f
@@ -14,6 +14,7 @@
|
||||
|
||||
import os
|
||||
import sys
|
||||
from typing import Optional
|
||||
|
||||
import pager
|
||||
|
||||
@@ -84,7 +85,7 @@ def _Color(fg=None, bg=None, attr=None):
|
||||
DEFAULT = None
|
||||
|
||||
|
||||
def SetDefaultColoring(state):
|
||||
def SetDefaultColoring(state: Optional[str]) -> None:
|
||||
"""Set coloring behavior to |state|.
|
||||
|
||||
This is useful for overriding config options via the command line.
|
||||
@@ -97,9 +98,9 @@ def SetDefaultColoring(state):
|
||||
state = state.lower()
|
||||
if state in ("auto",):
|
||||
DEFAULT = state
|
||||
elif state in ("always", "yes", "true", True):
|
||||
elif state in ("always", "yes", "true"):
|
||||
DEFAULT = "always"
|
||||
elif state in ("never", "no", "false", False):
|
||||
elif state in ("never", "no", "false"):
|
||||
DEFAULT = "never"
|
||||
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ import pathlib
|
||||
|
||||
import pytest
|
||||
|
||||
import color
|
||||
import platform_utils
|
||||
import repo_trace
|
||||
|
||||
@@ -28,6 +29,16 @@ def disable_repo_trace(tmp_path):
|
||||
repo_trace._TRACE_FILE = str(tmp_path / "TRACE_FILE_from_test")
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def restore_default_coloring() -> None:
|
||||
"""Force disable color for reproducible test behavior.
|
||||
|
||||
The few tests that cover color behavior can still reset/change the color as
|
||||
needed.
|
||||
"""
|
||||
color.SetDefaultColoring("never")
|
||||
|
||||
|
||||
# adapted from pytest-home 0.5.1
|
||||
def _set_home(monkeypatch, path: pathlib.Path):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user