9194ef5abd
Docs/Test Workflow / Test docs build (push) Failing after 0s
Check links & references / links-check (push) Failing after 1s
Pytest/Test Workflow / Import Test and Pytest Run (ubuntu-latest, 3.10) (push) Failing after 0s
Pytest/Test Workflow / Import Test and Pytest Run (ubuntu-latest, 3.11) (push) Failing after 0s
PR Conflict Labeler / main (push) Failing after 2s
Pytest/Test Workflow / Import Test and Pytest Run (ubuntu-latest, 3.12) (push) Failing after 2s
Pytest/Test Workflow / Import Test and Pytest Run (ubuntu-latest, 3.13) (push) Failing after 0s
Pytest/Test Workflow / Build this Package (push) Failing after 5s
Pytest/Test Workflow / Import Test and Pytest Run (macos-latest, 3.10) (push) Has been cancelled
Pytest/Test Workflow / Import Test and Pytest Run (macos-latest, 3.11) (push) Has been cancelled
Pytest/Test Workflow / Import Test and Pytest Run (macos-latest, 3.12) (push) Has been cancelled
Pytest/Test Workflow / Import Test and Pytest Run (macos-latest, 3.13) (push) Has been cancelled
Pytest/Test Workflow / Import Test and Pytest Run (windows-latest, 3.10) (push) Has been cancelled
Pytest/Test Workflow / Import Test and Pytest Run (windows-latest, 3.11) (push) Has been cancelled
Pytest/Test Workflow / Import Test and Pytest Run (windows-latest, 3.12) (push) Has been cancelled
Pytest/Test Workflow / Import Test and Pytest Run (windows-latest, 3.13) (push) Has been cancelled
Pytest/Test Workflow / testing-guardian (push) Has been cancelled
45 lines
1.6 KiB
Python
45 lines
1.6 KiB
Python
"""Tests for supervision.metrics.utils.utils — pandas extra guard."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import builtins
|
|
|
|
import pytest
|
|
|
|
from supervision.metrics.utils.utils import ensure_pandas_installed
|
|
|
|
|
|
class TestEnsurePandasInstalled:
|
|
"""Verify the `metrics` extra guard for pandas-dependent code paths."""
|
|
|
|
def test_noop_when_pandas_importable(self, monkeypatch: pytest.MonkeyPatch) -> None:
|
|
"""No exception is raised when pandas is importable."""
|
|
real_import = builtins.__import__
|
|
|
|
def _fake_import(name: str, *args: object, **kwargs: object) -> object:
|
|
"""Pretend pandas is importable regardless of the real environment."""
|
|
if name == "pandas":
|
|
return object()
|
|
return real_import(name, *args, **kwargs)
|
|
|
|
monkeypatch.setattr(builtins, "__import__", _fake_import)
|
|
|
|
ensure_pandas_installed()
|
|
|
|
def test_raises_import_error_when_pandas_missing(
|
|
self, monkeypatch: pytest.MonkeyPatch
|
|
) -> None:
|
|
"""A clear ImportError is raised when pandas cannot be imported."""
|
|
real_import = builtins.__import__
|
|
|
|
def _fake_import(name: str, *args: object, **kwargs: object) -> object:
|
|
"""Raise ImportError for pandas, delegate everything else."""
|
|
if name == "pandas":
|
|
raise ImportError("No module named 'pandas'")
|
|
return real_import(name, *args, **kwargs)
|
|
|
|
monkeypatch.setattr(builtins, "__import__", _fake_import)
|
|
|
|
with pytest.raises(ImportError, match=r"metrics.*extra"):
|
|
ensure_pandas_installed()
|