File size: 2,574 Bytes
41ff959
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
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,
    }