import subprocess import sys from argparse import Namespace from pathlib import Path import pytest from src.demo import infer_batch_images def test_viewer_settings_is_a_static_config() -> None: assert infer_batch_images.VIEWER_SETTINGS == Path("config/viewer_settings.json").resolve() assert infer_batch_images.VIEWER_SETTINGS.is_file() def test_missing_splat_transform_disables_optional_exports(monkeypatch, capsys) -> None: args = Namespace(export_html=True, no_video=True) monkeypatch.setattr(infer_batch_images, "SPLAT_TRANSFORM", "missing-splat-transform") monkeypatch.setattr(infer_batch_images.shutil, "which", lambda _: None) infer_batch_images._disable_unavailable_optional_outputs(args) assert args.export_html is False assert "Skipping HTML export" in capsys.readouterr().out def test_missing_gsplat_disables_optional_video(monkeypatch, capsys) -> None: args = Namespace(export_html=True, no_video=False) monkeypatch.setattr(infer_batch_images, "is_gsplat_available", lambda: False) monkeypatch.setattr( infer_batch_images.shutil, "which", lambda _: "/usr/bin/splat-transform", ) infer_batch_images._disable_unavailable_optional_outputs(args) assert args.no_video is True assert args.export_html is True assert "Skipping video rendering" in capsys.readouterr().out @pytest.mark.parametrize( ("extra_args", "expected"), [([], True), (["--no-export-html"], False)], ) def test_batch_html_export_default(extra_args, expected, monkeypatch) -> None: monkeypatch.setattr(sys, "argv", ["infer_batch_images", *extra_args]) assert infer_batch_images._parse_args().export_html is expected def test_splat_transform_output_is_suppressed(monkeypatch) -> None: call = {} def fake_run(command, **kwargs): call["command"] = command call["kwargs"] = kwargs monkeypatch.setattr(infer_batch_images.subprocess, "run", fake_run) monkeypatch.setattr(infer_batch_images, "patch_supersplat_html_auto_rotate", lambda _: None) infer_batch_images._run_splat_transform( Path("scene.ply"), Path("scene.html"), Path("viewer.json"), ) assert call["command"] == [ infer_batch_images.SPLAT_TRANSFORM, "-w", "--viewer-settings", "viewer.json", "scene.ply", "--filter-harmonics", "0", "scene.html", ] assert call["kwargs"] == { "check": True, "stdout": subprocess.DEVNULL, "stderr": subprocess.DEVNULL, }