From 3cc9be2becc0927f0e76189299ef78ea41941c24 Mon Sep 17 00:00:00 2001 From: mtkennerly Date: Fri, 9 Feb 2024 17:56:45 -0500 Subject: [PATCH] #77: Set Fossil env vars for test automatically --- tests/integration/test_dunamai.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/integration/test_dunamai.py b/tests/integration/test_dunamai.py index c68d602..932d030 100644 --- a/tests/integration/test_dunamai.py +++ b/tests/integration/test_dunamai.py @@ -1,6 +1,7 @@ import datetime as dt import os import shutil +import sys import time from contextlib import contextmanager from pathlib import Path @@ -39,6 +40,17 @@ def is_git_legacy() -> bool: return version < [2, 7] +def set_missing_env(key: str, value: str, alts: Optional[List[str]] = None) -> None: + if alts is None: + alts = [] + + for k in [key, *alts]: + if os.environ.get(k) is not None: + return + + os.environ[key] = value + + def make_run_callback(where: Path) -> Callable: def inner(command, expected_code: int = 0, env: Optional[dict] = None): _, out = _run_cmd(command, where=where, codes=[expected_code], env=env) @@ -796,6 +808,10 @@ def test__version__from_fossil(tmp_path) -> None: from_vcs = make_from_callback(Version.from_fossil) b = "trunk" + if sys.platform != "win32": + set_missing_env("FOSSIL_HOME", str(REPO / "tests"), ["HOME", "XDG_CONFIG_HOME"]) + set_missing_env("USER", "dunamai") + with chdir(vcs): run("fossil init repo") run("fossil open repo --force")