mirror of
https://github.com/nix-community/nix-direnv.git
synced 2025-11-08 11:36:11 +01:00
rewrite tests using pytest
this allows us to use fixtures that are more flexible
This commit is contained in:
parent
6dbc942fea
commit
748988f4b9
10 changed files with 195 additions and 113 deletions
47
tests/direnv_project.py
Normal file
47
tests/direnv_project.py
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
from dataclasses import dataclass
|
||||
import shutil
|
||||
from tempfile import TemporaryDirectory
|
||||
from typing import Iterator
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from procs import run
|
||||
|
||||
|
||||
@dataclass
|
||||
class DirenvProject:
|
||||
dir: Path
|
||||
nix_direnv: Path
|
||||
|
||||
@property
|
||||
def envrc(self) -> Path:
|
||||
return self.dir / ".envrc"
|
||||
|
||||
def setup_envrc(self, content: str) -> None:
|
||||
self.envrc.write_text(
|
||||
f"""
|
||||
source {self.nix_direnv}
|
||||
{content}
|
||||
"""
|
||||
)
|
||||
run(["direnv", "allow"], cwd=self.dir)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def direnv_project(test_root: Path, project_root: Path) -> Iterator[DirenvProject]:
|
||||
"""
|
||||
Setups a direnv test project
|
||||
"""
|
||||
with TemporaryDirectory() as _dir:
|
||||
dir = Path(_dir) / "proj"
|
||||
shutil.copytree(test_root / "testenv", dir)
|
||||
nix_direnv = project_root / "direnvrc"
|
||||
|
||||
c = DirenvProject(Path(dir), nix_direnv)
|
||||
try:
|
||||
yield c
|
||||
finally:
|
||||
pass
|
||||
Loading…
Add table
Add a link
Reference in a new issue