mirror of
https://github.com/nix-community/nix-direnv.git
synced 2025-11-08 19:46: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
|
import subprocess
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import IO, Any
|
from typing import IO, Any
|
||||||
|
|
@ -5,6 +6,8 @@ from typing import IO, Any
|
||||||
_FILE = None | int | IO[Any]
|
_FILE = None | int | IO[Any]
|
||||||
_DIR = None | Path | str
|
_DIR = None | Path | str
|
||||||
|
|
||||||
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def run(
|
def run(
|
||||||
cmd: list[str],
|
cmd: list[str],
|
||||||
|
|
@ -16,8 +19,8 @@ def run(
|
||||||
env: dict[str, str] | None = None,
|
env: dict[str, str] | None = None,
|
||||||
) -> subprocess.CompletedProcess:
|
) -> subprocess.CompletedProcess:
|
||||||
if cwd is not None:
|
if cwd is not None:
|
||||||
print(f"cd {cwd}")
|
log.debug(f"cd {cwd}")
|
||||||
print("$ " + " ".join(cmd))
|
log.debug("$ " + " ".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
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
import logging
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
import unittest
|
import unittest
|
||||||
|
|
@ -7,6 +8,8 @@ import pytest
|
||||||
from .direnv_project import DirenvProject
|
from .direnv_project import DirenvProject
|
||||||
from .procs import run
|
from .procs import run
|
||||||
|
|
||||||
|
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"])
|
||||||
|
|
||||||
|
|
@ -54,7 +57,7 @@ def common_test_clean(direnv_project: DirenvProject) -> None:
|
||||||
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")]
|
||||||
if len(rcs) != 1 or len(profiles) != 1:
|
if len(rcs) != 1 or len(profiles) != 1:
|
||||||
print(files)
|
log.debug(files)
|
||||||
assert len(rcs) == 1
|
assert len(rcs) == 1
|
||||||
assert len(profiles) == 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
|
# should only contain our flake-utils flake
|
||||||
if len(inputs) != 4:
|
if len(inputs) != 4:
|
||||||
run(["nix", "flake", "archive", "--json"], cwd=direnv_project.directory)
|
run(["nix", "flake", "archive", "--json"], cwd=direnv_project.directory)
|
||||||
print(inputs)
|
log.debug(inputs)
|
||||||
assert len(inputs) == 4
|
assert len(inputs) == 4
|
||||||
for symlink in inputs:
|
for symlink in inputs:
|
||||||
assert symlink.is_dir()
|
assert symlink.is_dir()
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
import logging
|
||||||
import os
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
|
|
@ -8,12 +9,14 @@ import pytest
|
||||||
from .direnv_project import DirenvProject
|
from .direnv_project import DirenvProject
|
||||||
from .procs import run
|
from .procs import run
|
||||||
|
|
||||||
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def direnv_exec(
|
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]
|
||||||
print("$ " + " ".join(args))
|
log.debug("$ " + " ".join(args))
|
||||||
out = run(
|
out = run(
|
||||||
args,
|
args,
|
||||||
stderr=subprocess.PIPE,
|
stderr=subprocess.PIPE,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue