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

49 lines
2.0 KiB
Python

"""Tests for image utils."""
# Copyright (C) 2024 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
from pathlib import Path
import pytest
from anomalib.data.utils.image import get_image_filenames
class TestGetImageFilenames:
"""Tests for ``get_image_filenames`` function."""
@staticmethod
def test_existing_image_file(dataset_path: Path) -> None:
"""Test ``get_image_filenames`` returns the correct path for an existing image file."""
image_path = dataset_path / "mvtecad/dummy/train/good/000.png"
image_filenames = get_image_filenames(image_path)
assert image_filenames == [image_path.resolve()]
@staticmethod
def test_existing_image_directory(dataset_path: Path) -> None:
"""Test ``get_image_filenames`` returns the correct image filenames from an existing directory."""
directory_path = dataset_path / "mvtecad/dummy/train/good"
image_filenames = get_image_filenames(directory_path)
expected_filenames = [(directory_path / f"{i:03d}.png").resolve() for i in range(5)]
assert set(image_filenames) == set(expected_filenames)
@staticmethod
def test_nonexistent_image_file() -> None:
"""Test ``get_image_filenames`` raises FileNotFoundError for a nonexistent image file."""
with pytest.raises(FileNotFoundError):
get_image_filenames("009.tiff")
@staticmethod
def test_nonexistent_image_directory() -> None:
"""Test ``get_image_filenames`` raises FileNotFoundError for a nonexistent image directory."""
with pytest.raises(FileNotFoundError):
get_image_filenames("nonexistent_directory")
@staticmethod
def test_non_image_file(dataset_path: Path) -> None:
"""Test ``get_image_filenames`` raises ValueError for a non-image file."""
filename = dataset_path / "avenue/ground_truth_demo/testing_label_mask/1_label.mat"
with pytest.raises(ValueError, match=r"``filename`` is not an image file*"):
get_image_filenames(filename)