59 lines
1.6 KiB
Python
59 lines
1.6 KiB
Python
from __future__ import annotations
|
|
|
|
import os
|
|
import shutil
|
|
import subprocess
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
PROJECT_ROOT = Path(__file__).resolve().parents[1]
|
|
SOURCE_ROOT = PROJECT_ROOT / "src"
|
|
|
|
|
|
def _environment_with_source() -> dict[str, str]:
|
|
environment = os.environ.copy()
|
|
existing_pythonpath = environment.get("PYTHONPATH")
|
|
paths = [str(SOURCE_ROOT)]
|
|
if existing_pythonpath:
|
|
paths.append(existing_pythonpath)
|
|
environment["PYTHONPATH"] = os.pathsep.join(paths)
|
|
return environment
|
|
|
|
|
|
def _assert_successful_help(result: subprocess.CompletedProcess[str]) -> None:
|
|
assert result.returncode == 0, result.stderr
|
|
assert "usage:" in result.stdout.lower()
|
|
assert "GYXX Flow" in result.stdout
|
|
|
|
|
|
def test_python_module_help_has_no_filesystem_side_effects(tmp_path: Path) -> None:
|
|
result = subprocess.run(
|
|
[sys.executable, "-m", "gyxx_flow", "--help"],
|
|
cwd=tmp_path,
|
|
env=_environment_with_source(),
|
|
capture_output=True,
|
|
text=True,
|
|
check=False,
|
|
)
|
|
|
|
_assert_successful_help(result)
|
|
assert list(tmp_path.iterdir()) == []
|
|
|
|
|
|
def test_installed_console_script_help_has_no_filesystem_side_effects(
|
|
tmp_path: Path,
|
|
) -> None:
|
|
executable = shutil.which("gyxx", path=str(Path(sys.executable).parent))
|
|
assert executable is not None, "The installed gyxx console script was not found"
|
|
|
|
result = subprocess.run(
|
|
[executable, "--help"],
|
|
cwd=tmp_path,
|
|
capture_output=True,
|
|
text=True,
|
|
check=False,
|
|
)
|
|
|
|
_assert_successful_help(result)
|
|
assert list(tmp_path.iterdir()) == []
|