mirror of
https://github.com/hanzoai/anomalib.git
synced 2026-10-30 18:48:11 +00:00
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.
52 lines
1.8 KiB
Python
52 lines
1.8 KiB
Python
"""Test Threshold metric."""
|
|
|
|
# Copyright (C) 2024 Intel Corporation
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
|
|
import pytest
|
|
from torchmetrics import Metric
|
|
|
|
from anomalib.metrics.threshold import BaseThreshold, Threshold
|
|
|
|
|
|
class TestThreshold:
|
|
"""Test cases for the Threshold class."""
|
|
|
|
@staticmethod
|
|
def test_threshold_abstract_methods() -> None:
|
|
"""Test that Threshold class raises NotImplementedError for abstract methods."""
|
|
threshold = Threshold()
|
|
|
|
with pytest.raises(NotImplementedError, match="Subclass of Threshold must implement the compute method"):
|
|
threshold.compute()
|
|
|
|
with pytest.raises(NotImplementedError, match="Subclass of Threshold must implement the update method"):
|
|
threshold.update()
|
|
|
|
@staticmethod
|
|
def test_threshold_initialization() -> None:
|
|
"""Test that Threshold can be initialized without errors."""
|
|
threshold = Threshold()
|
|
assert isinstance(threshold, Metric)
|
|
|
|
|
|
class TestBaseThreshold:
|
|
"""Test cases for the BaseThreshold class."""
|
|
|
|
@staticmethod
|
|
def test_base_threshold_inheritance() -> None:
|
|
"""Test that BaseThreshold inherits from Threshold."""
|
|
base_threshold = BaseThreshold()
|
|
assert isinstance(base_threshold, Threshold)
|
|
|
|
@staticmethod
|
|
def test_base_threshold_abstract_methods() -> None:
|
|
"""Test that BaseThreshold class raises NotImplementedError for abstract methods."""
|
|
base_threshold = BaseThreshold()
|
|
|
|
with pytest.raises(NotImplementedError, match="Subclass of Threshold must implement the compute method"):
|
|
base_threshold.compute()
|
|
|
|
with pytest.raises(NotImplementedError, match="Subclass of Threshold must implement the update method"):
|
|
base_threshold.update()
|