nix-direnv/tests/procs.py
Jörg Thalheim 748988f4b9
rewrite tests using pytest
this allows us to use fixtures that are more flexible
2022-06-01 08:20:43 +02:00

25 lines
550 B
Python

#!/usr/bin/env python3
import subprocess
from typing import List, Union, IO, Any
from pathlib import Path
_FILE = Union[None, int, IO[Any]]
_DIR = Union[None, Path, str]
def run(
cmd: List[str],
text: bool = True,
check: bool = True,
cwd: _DIR = None,
stderr: _FILE = None,
stdout: _FILE = None,
) -> subprocess.CompletedProcess:
if cwd is not None:
print(f"cd {cwd}")
print("$ " + " ".join(cmd))
return subprocess.run(
cmd, text=text, check=check, cwd=cwd, stderr=stderr, stdout=stdout
)