From d5a10dc6d5c3274b7e6b3457194ab37ead80a847 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Wed, 29 Nov 2023 08:21:15 +0100 Subject: [PATCH] test: other random ruff lints --- tests/direnv_project.py | 4 ++-- tests/procs.py | 3 ++- tests/root.py | 4 ++-- tests/test_gc.py | 5 ++++- tests/test_use_nix.py | 5 +++-- 5 files changed, 13 insertions(+), 8 deletions(-) diff --git a/tests/direnv_project.py b/tests/direnv_project.py index b5108ff..f2166fe 100644 --- a/tests/direnv_project.py +++ b/tests/direnv_project.py @@ -1,9 +1,9 @@ import shutil import textwrap +from collections.abc import Iterator from dataclasses import dataclass from pathlib import Path from tempfile import TemporaryDirectory -from typing import Iterator import pytest @@ -31,7 +31,7 @@ class DirenvProject: run(["direnv", "allow"], cwd=self.directory) -@pytest.fixture +@pytest.fixture() def direnv_project(test_root: Path, project_root: Path) -> Iterator[DirenvProject]: """ Setups a direnv test project diff --git a/tests/procs.py b/tests/procs.py index 971c0e4..f9d80ba 100644 --- a/tests/procs.py +++ b/tests/procs.py @@ -1,4 +1,5 @@ import logging +import shlex import subprocess from pathlib import Path from typing import IO, Any @@ -20,7 +21,7 @@ def run( ) -> subprocess.CompletedProcess: if cwd is not None: log.debug(f"cd {cwd}") - log.debug("$ " + " ".join(cmd)) + log.debug(f"$ {shlex.join(cmd)}") return subprocess.run( cmd, text=text, check=check, cwd=cwd, stderr=stderr, stdout=stdout, env=env ) diff --git a/tests/root.py b/tests/root.py index b3f0914..a5bf399 100644 --- a/tests/root.py +++ b/tests/root.py @@ -6,7 +6,7 @@ TEST_ROOT = Path(__file__).parent.resolve() PROJECT_ROOT = TEST_ROOT.parent -@pytest.fixture +@pytest.fixture() def test_root() -> Path: """ Root directory of the tests @@ -14,7 +14,7 @@ def test_root() -> Path: return TEST_ROOT -@pytest.fixture +@pytest.fixture() def project_root() -> Path: """ Root directory of the tests diff --git a/tests/test_gc.py b/tests/test_gc.py index 8d49683..26f2566 100644 --- a/tests/test_gc.py +++ b/tests/test_gc.py @@ -10,6 +10,7 @@ from .procs import run log = logging.getLogger(__name__) + def common_test(direnv_project: DirenvProject) -> None: run(["nix-collect-garbage"]) @@ -52,7 +53,9 @@ def common_test_clean(direnv_project: DirenvProject) -> None: sys.stderr.write(out3.stderr) 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")] profiles = [f for f in files if not f.match("*.rc")] diff --git a/tests/test_use_nix.py b/tests/test_use_nix.py index f12cb6b..804079d 100644 --- a/tests/test_use_nix.py +++ b/tests/test_use_nix.py @@ -1,5 +1,6 @@ import logging import os +import shlex import subprocess import sys import unittest @@ -16,7 +17,7 @@ def direnv_exec( direnv_project: DirenvProject, cmd: str, env: dict[str, str] | None = None ) -> None: args = ["direnv", "exec", str(direnv_project.directory), "sh", "-c", cmd] - log.debug("$ " + " ".join(args)) + log.debug(f"$ {shlex.join(args)}") out = run( args, stderr=subprocess.PIPE, @@ -28,7 +29,7 @@ def direnv_exec( sys.stdout.write(out.stdout) sys.stderr.write(out.stderr) assert out.returncode == 0 - assert "OK\n" == out.stdout + assert out.stdout == "OK\n" assert "renewed cache" in out.stderr