54 lines
1.6 KiB
Python
54 lines
1.6 KiB
Python
"""Shared helpers for integration tests."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import shutil
|
|
import subprocess
|
|
import tempfile
|
|
from pathlib import Path
|
|
|
|
from tests.conftest import make_png
|
|
|
|
|
|
def has_darktable_style(style_name: str, config_dir: Path | None = None) -> bool:
|
|
"""Return True if darktable-cli can apply ``style_name`` to a tiny PNG."""
|
|
if not shutil.which("darktable-cli"):
|
|
return False
|
|
|
|
config = config_dir or Path.home() / ".config" / "darktable"
|
|
styles_dir = config / "styles"
|
|
if not styles_dir.is_dir():
|
|
return False
|
|
if not any(p.stem == style_name for p in styles_dir.glob("*.dtstyle")):
|
|
return False
|
|
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
tmp_path = Path(tmp)
|
|
src = tmp_path / "probe.png"
|
|
out_dir = tmp_path / "out"
|
|
out_dir.mkdir()
|
|
make_png(src)
|
|
cmd = [
|
|
"darktable-cli",
|
|
str(src),
|
|
str(out_dir),
|
|
"--style",
|
|
style_name,
|
|
"--out-ext",
|
|
"png",
|
|
"--style-overwrite",
|
|
"--core",
|
|
"--configdir",
|
|
str(config),
|
|
]
|
|
result = subprocess.run(cmd, capture_output=True, text=True)
|
|
if result.returncode != 0:
|
|
return False
|
|
return any(out_dir.iterdir())
|
|
|
|
|
|
def has_workflow_tools() -> bool:
|
|
"""True when rembg, gmic, ImageMagick, and darktable-cli are on PATH."""
|
|
has_magick = bool(shutil.which("magick") or shutil.which("convert"))
|
|
return all(shutil.which(name) for name in ("rembg", "gmic", "darktable-cli")) and has_magick
|