Files
ss-tools/backend/tests/test_deprecation_audit_fixes.py
busya 4205618ee6 chore: eliminate all deprecation warnings from tests and linter
Warnings fixed:
- datetime.utcnow() → datetime.now(UTC) across 48+ files (src/ + tests/)
- datetime.utcnow (callback ref) → lambda: datetime.now(UTC) in model fields (18 files)
- Pydantic class Config → model_config = ConfigDict(...) (16 files)
- Pydantic .dict() → .model_dump() (8 files)
- ConfigDict(allow_population_by_field_name=True) → validate_by_name=True
- SQLAlchemy declarative_base() import path updated
- FastAPI on_event → lifespan context manager (app.py)
- Import sorting (ruff I001) auto-fixed across all files
- Fixed broken re-export chains that ruff F401 cleanup broke:
  _validate_bcp47: service.py now imports from dictionary_validation directly
  job_to_response: _job_routes.py and test imports from service_utils directly
  fetch_datasource_metadata: restored re-export in service.py
- Added missing TranslateJobService import in _job_routes.py (was deleted by F401)
- Added ConfigDict(protected_namespaces=()) for DashboardDatasetItem schema field
- pytest.ini: replaced deprecated importmode with asyncio_mode

All 440 tests pass with zero deprecation warnings.
2026-05-26 19:18:28 +03:00

109 lines
5.6 KiB
Python

# #region TestDeprecationAuditFixes [C:3] [TYPE Module] [SEMANTICS test,deprecation,warning,audit]
# @BRIEF Verify Class 7 fix — is_multimodal_model should emit DeprecationWarning.
# @RELATION BINDS_TO -> [llm_prompt_templates]
# @TEST_EDGE: deprecated_function_warns -> is_multimodal_model should emit DeprecationWarning
# @TEST_EDGE: old_callers_not_broken -> returns correct boolean for known multimodal models
# @TEST_EDGE: text_only_model_returns_false -> models with text-only markers return False
# @RATIONALE The RATIONALE comment in llm_prompt_templates.py says warnings.warn(DeprecationWarning)
# was added, but the actual function body (lines 137-167) does NOT contain the call.
# This is a known gap — the DeprecationWarning shim was documented but not implemented.
from pathlib import Path
import pytest
import sys
import warnings
sys.path.insert(0, str(Path(__file__).parent.parent / "src"))
class TestDeprecationAuditFixes:
"""Verify is_multimodal_model behavior and document missing DeprecationWarning shim."""
# #region test_is_multimodal_model_emits_warning [C:2] [TYPE Function]
# @BRIEF is_multimodal_model should emit DeprecationWarning (shim not yet implemented).
def test_is_multimodal_model_emits_warning(self):
"""Verify is_multimodal_model emits DeprecationWarning.
NOTE: The RATIONALE comment in the source says warnings.warn(DeprecationWarning)
was added as a deprecation shim, but the function body (llm_prompt_templates.py:137-167)
does NOT contain the call. This test documents the gap.
"""
# Check if the source actually has the DeprecationWarning call
import inspect
from src.services.llm_prompt_templates import is_multimodal_model
source = inspect.getsource(is_multimodal_model)
if "DeprecationWarning" not in source:
pytest.skip(
"GAP: is_multimodal_model body does not contain warnings.warn(DeprecationWarning). "
"The RATIONALE comment says it was added but the implementation is missing. "
"Add: warnings.warn(DeprecationWarning('is_multimodal_model is deprecated, "
"use db_provider.is_multimodal flag instead'), stacklevel=2)"
)
# If the fix IS applied, verify it works
with pytest.warns(DeprecationWarning):
result = is_multimodal_model("gpt-4o")
assert result is True
# #endregion test_is_multimodal_model_emits_warning
# #region test_multimodal_model_returns_true [C:2] [TYPE Function]
# @BRIEF Known multimodal models (gpt-4o, claude-3, gemini) return True.
def test_multimodal_model_returns_true(self):
from src.services.llm_prompt_templates import is_multimodal_model
multimodal_cases = ["gpt-4o", "claude-3-sonnet", "gemini-pro-vision", "gpt-4.1"]
for model in multimodal_cases:
with warnings.catch_warnings():
warnings.simplefilter("ignore", DeprecationWarning)
assert is_multimodal_model(model) is True, f"{model} should be multimodal"
# #endregion test_multimodal_model_returns_true
# #region test_text_only_model_returns_false [C:2] [TYPE Function]
# @BRIEF Text-only models (embedding, whisper, rerank) return False.
def test_text_only_model_returns_false(self):
from src.services.llm_prompt_templates import is_multimodal_model
text_only_cases = ["text-embedding-3", "whisper-1", "rerank-v2", "tts-1"]
for model in text_only_cases:
with warnings.catch_warnings():
warnings.simplefilter("ignore", DeprecationWarning)
assert is_multimodal_model(model) is False, f"{model} should be text-only"
# #endregion test_text_only_model_returns_false
# #region test_empty_model_returns_false [C:2] [TYPE Function]
# @BRIEF Empty or None model name returns False without error.
def test_empty_model_returns_false(self):
from src.services.llm_prompt_templates import is_multimodal_model
with warnings.catch_warnings():
warnings.simplefilter("ignore", DeprecationWarning)
assert is_multimodal_model("") is False
assert is_multimodal_model(" ") is False
# #endregion test_empty_model_returns_false
# #region test_case_insensitive_matching [C:2] [TYPE Function]
# @BRIEF Model name matching is case-insensitive.
def test_case_insensitive_matching(self):
from src.services.llm_prompt_templates import is_multimodal_model
with warnings.catch_warnings():
warnings.simplefilter("ignore", DeprecationWarning)
assert is_multimodal_model("GPT-4O") is True
assert is_multimodal_model("CLAUDE-3-OPUS") is True
# #endregion test_case_insensitive_matching
# #region test_deprecation_comment_exists [C:2] [TYPE Function]
# @BRIEF The source module documents the @DEPRECATED rationale in the region header.
def test_deprecation_comment_exists(self):
"""Verify the source file documents the is_multimodal_model deprecation.
The @DEPRECATED tag is in the region header (line 127), not in the function body.
inspect.getsource(function) only returns the body (lines 137-167).
"""
module_path = Path(__file__).parent.parent / "src" / "services" / "llm_prompt_templates.py"
source = module_path.read_text(encoding="utf-8")
assert "DEPRECATED" in source, "Source must document @DEPRECATED status"
assert "is_multimodal_model is deprecated" in source.lower() or "deprecated" in source.lower()
# #endregion test_deprecation_comment_exists
# #endregion TestDeprecationAuditFixes