Skip to content

Commit

Permalink
#77: Set Fossil env vars for test automatically
Browse files Browse the repository at this point in the history
  • Loading branch information
mtkennerly committed Feb 9, 2024
1 parent cb28211 commit 3cc9be2
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions tests/integration/test_dunamai.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import datetime as dt
import os
import shutil
import sys
import time
from contextlib import contextmanager
from pathlib import Path
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit 3cc9be2

Please sign in to comment.