mirror of
https://github.com/denizsafak/abogen.git
synced 2026-07-18 21:50:28 +02:00
fix(tests): mock spacy in plugin tests to fix externally-managed-environment failures
This commit is contained in:
@@ -12,6 +12,7 @@ from __future__ import annotations
|
|||||||
import logging
|
import logging
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
from unittest.mock import patch
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
@@ -147,6 +148,23 @@ def engine_config() -> Any:
|
|||||||
return EngineConfig(device="cpu")
|
return EngineConfig(device="cpu")
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(autouse=True)
|
||||||
|
def _mock_kokoro_pipeline():
|
||||||
|
"""Prevent real KPipeline initialization during generic plugin tests.
|
||||||
|
|
||||||
|
The real KPipeline requires spacy model downloads which aren't available
|
||||||
|
in externally-managed environments. Mock spacy's download and load so
|
||||||
|
the engine contract can be tested without heavy dependencies.
|
||||||
|
"""
|
||||||
|
from unittest.mock import MagicMock
|
||||||
|
|
||||||
|
mock_nlp = MagicMock()
|
||||||
|
|
||||||
|
with patch("spacy.cli.download"), \
|
||||||
|
patch("spacy.load", return_value=mock_nlp):
|
||||||
|
yield
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def create_engine(loaded_plugin, host_context, engine_config):
|
def create_engine(loaded_plugin, host_context, engine_config):
|
||||||
"""Create an engine instance from a loaded plugin.
|
"""Create an engine instance from a loaded plugin.
|
||||||
|
|||||||
@@ -38,8 +38,10 @@ from tests.contracts.engine_contract import EngineContractMixin
|
|||||||
def _kokoro_available() -> bool:
|
def _kokoro_available() -> bool:
|
||||||
try:
|
try:
|
||||||
from kokoro import KPipeline # type: ignore[import-not-found]
|
from kokoro import KPipeline # type: ignore[import-not-found]
|
||||||
|
import spacy
|
||||||
|
spacy.load("en_core_web_sm")
|
||||||
return True
|
return True
|
||||||
except ImportError:
|
except (ImportError, OSError):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user