mirror of
https://github.com/nix-community/nix-direnv.git
synced 2025-11-08 11:36:11 +01:00
test: other random ruff lints
This commit is contained in:
parent
8c46f6e97d
commit
d5a10dc6d5
5 changed files with 13 additions and 8 deletions
|
|
@ -1,9 +1,9 @@
|
||||||
import shutil
|
import shutil
|
||||||
import textwrap
|
import textwrap
|
||||||
|
from collections.abc import Iterator
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from tempfile import TemporaryDirectory
|
from tempfile import TemporaryDirectory
|
||||||
from typing import Iterator
|
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
|
@ -31,7 +31,7 @@ class DirenvProject:
|
||||||
run(["direnv", "allow"], cwd=self.directory)
|
run(["direnv", "allow"], cwd=self.directory)
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture()
|
||||||
def direnv_project(test_root: Path, project_root: Path) -> Iterator[DirenvProject]:
|
def direnv_project(test_root: Path, project_root: Path) -> Iterator[DirenvProject]:
|
||||||
"""
|
"""
|
||||||
Setups a direnv test project
|
Setups a direnv test project
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
import logging
|
import logging
|
||||||
|
import shlex
|
||||||
import subprocess
|
import subprocess
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import IO, Any
|
from typing import IO, Any
|
||||||
|
|
@ -20,7 +21,7 @@ def run(
|
||||||
) -> subprocess.CompletedProcess:
|
) -> subprocess.CompletedProcess:
|
||||||
if cwd is not None:
|
if cwd is not None:
|
||||||
log.debug(f"cd {cwd}")
|
log.debug(f"cd {cwd}")
|
||||||
log.debug("$ " + " ".join(cmd))
|
log.debug(f"$ {shlex.join(cmd)}")
|
||||||
return subprocess.run(
|
return subprocess.run(
|
||||||
cmd, text=text, check=check, cwd=cwd, stderr=stderr, stdout=stdout, env=env
|
cmd, text=text, check=check, cwd=cwd, stderr=stderr, stdout=stdout, env=env
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ TEST_ROOT = Path(__file__).parent.resolve()
|
||||||
PROJECT_ROOT = TEST_ROOT.parent
|
PROJECT_ROOT = TEST_ROOT.parent
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture()
|
||||||
def test_root() -> Path:
|
def test_root() -> Path:
|
||||||
"""
|
"""
|
||||||
Root directory of the tests
|
Root directory of the tests
|
||||||
|
|
@ -14,7 +14,7 @@ def test_root() -> Path:
|
||||||
return TEST_ROOT
|
return TEST_ROOT
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture()
|
||||||
def project_root() -> Path:
|
def project_root() -> Path:
|
||||||
"""
|
"""
|
||||||
Root directory of the tests
|
Root directory of the tests
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ from .procs import run
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def common_test(direnv_project: DirenvProject) -> None:
|
def common_test(direnv_project: DirenvProject) -> None:
|
||||||
run(["nix-collect-garbage"])
|
run(["nix-collect-garbage"])
|
||||||
|
|
||||||
|
|
@ -52,7 +53,9 @@ def common_test_clean(direnv_project: DirenvProject) -> None:
|
||||||
sys.stderr.write(out3.stderr)
|
sys.stderr.write(out3.stderr)
|
||||||
|
|
||||||
files = [
|
files = [
|
||||||
path for path in (direnv_project.directory / ".direnv").iterdir() if path.is_file()
|
path
|
||||||
|
for path in (direnv_project.directory / ".direnv").iterdir()
|
||||||
|
if path.is_file()
|
||||||
]
|
]
|
||||||
rcs = [f for f in files if f.match("*.rc")]
|
rcs = [f for f in files if f.match("*.rc")]
|
||||||
profiles = [f for f in files if not f.match("*.rc")]
|
profiles = [f for f in files if not f.match("*.rc")]
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
import shlex
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
import unittest
|
import unittest
|
||||||
|
|
@ -16,7 +17,7 @@ def direnv_exec(
|
||||||
direnv_project: DirenvProject, cmd: str, env: dict[str, str] | None = None
|
direnv_project: DirenvProject, cmd: str, env: dict[str, str] | None = None
|
||||||
) -> None:
|
) -> None:
|
||||||
args = ["direnv", "exec", str(direnv_project.directory), "sh", "-c", cmd]
|
args = ["direnv", "exec", str(direnv_project.directory), "sh", "-c", cmd]
|
||||||
log.debug("$ " + " ".join(args))
|
log.debug(f"$ {shlex.join(args)}")
|
||||||
out = run(
|
out = run(
|
||||||
args,
|
args,
|
||||||
stderr=subprocess.PIPE,
|
stderr=subprocess.PIPE,
|
||||||
|
|
@ -28,7 +29,7 @@ def direnv_exec(
|
||||||
sys.stdout.write(out.stdout)
|
sys.stdout.write(out.stdout)
|
||||||
sys.stderr.write(out.stderr)
|
sys.stderr.write(out.stderr)
|
||||||
assert out.returncode == 0
|
assert out.returncode == 0
|
||||||
assert "OK\n" == out.stdout
|
assert out.stdout == "OK\n"
|
||||||
assert "renewed cache" in out.stderr
|
assert "renewed cache" in out.stderr
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue