mirror of
https://github.com/nix-community/nix-direnv.git
synced 2025-11-08 11:36:11 +01:00
tests: don't use print in favour of logger
This commit is contained in:
parent
9ac34be48f
commit
8c46f6e97d
3 changed files with 14 additions and 5 deletions
|
|
@ -1,3 +1,4 @@
|
|||
import logging
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
from typing import IO, Any
|
||||
|
|
@ -5,6 +6,8 @@ from typing import IO, Any
|
|||
_FILE = None | int | IO[Any]
|
||||
_DIR = None | Path | str
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def run(
|
||||
cmd: list[str],
|
||||
|
|
@ -16,8 +19,8 @@ def run(
|
|||
env: dict[str, str] | None = None,
|
||||
) -> subprocess.CompletedProcess:
|
||||
if cwd is not None:
|
||||
print(f"cd {cwd}")
|
||||
print("$ " + " ".join(cmd))
|
||||
log.debug(f"cd {cwd}")
|
||||
log.debug("$ " + " ".join(cmd))
|
||||
return subprocess.run(
|
||||
cmd, text=text, check=check, cwd=cwd, stderr=stderr, stdout=stdout, env=env
|
||||
)
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
import logging
|
||||
import subprocess
|
||||
import sys
|
||||
import unittest
|
||||
|
|
@ -7,6 +8,8 @@ import pytest
|
|||
from .direnv_project import DirenvProject
|
||||
from .procs import run
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
def common_test(direnv_project: DirenvProject) -> None:
|
||||
run(["nix-collect-garbage"])
|
||||
|
||||
|
|
@ -54,7 +57,7 @@ def common_test_clean(direnv_project: DirenvProject) -> None:
|
|||
rcs = [f for f in files if f.match("*.rc")]
|
||||
profiles = [f for f in files if not f.match("*.rc")]
|
||||
if len(rcs) != 1 or len(profiles) != 1:
|
||||
print(files)
|
||||
log.debug(files)
|
||||
assert len(rcs) == 1
|
||||
assert len(profiles) == 1
|
||||
|
||||
|
|
@ -79,7 +82,7 @@ def test_use_flake(direnv_project: DirenvProject, strict_env: bool) -> None:
|
|||
# should only contain our flake-utils flake
|
||||
if len(inputs) != 4:
|
||||
run(["nix", "flake", "archive", "--json"], cwd=direnv_project.directory)
|
||||
print(inputs)
|
||||
log.debug(inputs)
|
||||
assert len(inputs) == 4
|
||||
for symlink in inputs:
|
||||
assert symlink.is_dir()
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
import logging
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
|
|
@ -8,12 +9,14 @@ import pytest
|
|||
from .direnv_project import DirenvProject
|
||||
from .procs import run
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
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]
|
||||
print("$ " + " ".join(args))
|
||||
log.debug("$ " + " ".join(args))
|
||||
out = run(
|
||||
args,
|
||||
stderr=subprocess.PIPE,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue