Files
zeekay dda5b2a367 restore the tree
The previous commit was meant to remove .github/workflows and removed
every tracked path instead — 892 files, the whole repo. This puts back
the 874 that were never in scope; the eighteen workflow files stay gone,
for the reasons that commit gives.

Content is byte-identical to 9d2aec9 outside .github/workflows.
2026-08-13 23:27:57 -07:00

61 lines
1.9 KiB
Python

"""Test torch inference entrypoint script."""
# Copyright (C) 2023-2024 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
import sys
from collections.abc import Callable
from importlib.util import find_spec
from pathlib import Path
import pytest
from anomalib.models import Padim
sys.path.append("tools/inference")
class TestTorchInferenceEntrypoint:
"""This tests whether the entrypoints run without errors without quantitative measure of the outputs."""
@pytest.fixture()
@staticmethod
def get_functions() -> tuple[Callable, Callable]:
"""Get functions from torch_inference.py."""
if find_spec("torch_inference") is not None:
from tools.inference.torch_inference import get_parser, infer
else:
msg = "Unable to import torch_inference.py for testing"
raise ImportError(msg)
return get_parser, infer
@staticmethod
def test_torch_inference(
get_functions: tuple[Callable, Callable],
project_path: Path,
ckpt_path: Callable[[str], Path],
get_dummy_inference_image: str,
monkeypatch: pytest.MonkeyPatch,
) -> None:
"""Test torch_inference.py."""
# Set TRUST_REMOTE_CODE environment variable for the test
monkeypatch.setenv("TRUST_REMOTE_CODE", "1")
_ckpt_path = ckpt_path("Padim")
get_parser, infer = get_functions
model = Padim.load_from_checkpoint(_ckpt_path)
model.to_torch(
export_root=_ckpt_path.parent.parent.parent,
)
arguments = get_parser().parse_args(
[
"--weights",
str(_ckpt_path.parent.parent) + "/torch/model.pt",
"--input",
get_dummy_inference_image,
"--output",
str(project_path) + "/output.png",
],
)
infer(arguments)