Files
qwenpaw/tests/contract/providers/test_provider_contract.py
agent-radar 1a3a4ccde1
Creator App Tests / PR Spam Gate (push) Skipped
Frontend Tests / PR Spam Gate (push) Skipped
NPM Format (website & console) / PR Spam Gate (push) Skipped
Pre-commit Checks / PR Spam Gate (push) Skipped
QwenPaw Creator Plugin Release / check-version (push) Canceled after 0s
QwenPaw Creator Plugin Release / upload-oss (push) Canceled after 0s
Tests / PR Spam Gate (push) Skipped
CodeQL / CodeQL (python) (push) Canceled after 0s
CodeQL / CodeQL (typescript) (push) Canceled after 0s
Creator App Tests / Creator Backend Tests (push) Canceled after 0s
Creator App Tests / Creator UI Build & Tests (push) Canceled after 0s
E2E Smoke Tests / Playwright UI Smoke (push) Canceled after 0s
Frontend Tests / Detect console changes (push) Canceled after 0s
NPM Format (website & console) / website format check (push) Canceled after 0s
NPM Format (website & console) / console format check (push) Canceled after 0s
Pre-commit Checks / Pre-commit (push) Canceled after 0s
QwenPaw Data Plugin Release / check-version (push) Canceled after 0s
Tests / Detect code changes (push) Canceled after 0s
Frontend Tests / Vitest Unit Tests (push) Canceled after 0s
Frontend Tests / Frontend Summary (push) Canceled after 0s
QwenPaw Data Plugin Release / upload-oss (push) Canceled after 0s
Tests / Maintainer Approval (push) Canceled after 0s
Tests / Unit Tests - py3.11 - macos-latest (push) Canceled after 0s
Tests / Unit Tests - py3.11 - ubuntu-latest (push) Canceled after 0s
Tests / Unit Tests - py3.13 - ubuntu-latest (push) Canceled after 0s
Tests / Unit Tests - py3.11 - windows-latest (push) Canceled after 0s
Tests / Contract Tests - py3.11 - macos-latest (push) Canceled after 0s
Tests / Contract Tests - py3.11 - ubuntu-latest (push) Canceled after 0s
Tests / Contract Tests - py3.13 - ubuntu-latest (push) Canceled after 0s
Tests / Contract Tests - py3.11 - windows-latest (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - macos-latest - p0 (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - macos-latest - p1 (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - macos-latest - p2 (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - ubuntu-latest - fallback (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - ubuntu-latest - p0 (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - ubuntu-latest - p1 (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - ubuntu-latest - p2 (push) Canceled after 0s
Tests / Integrated Tests - py3.13 - ubuntu-latest - p0 (push) Canceled after 0s
Tests / Integrated Tests - py3.13 - ubuntu-latest - p1 (push) Canceled after 0s
Tests / Integrated Tests - py3.13 - ubuntu-latest - p2 (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - windows-latest - p0 (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - windows-latest - p1 (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - windows-latest - p2 (push) Canceled after 0s
Tests / Coverage Report (push) Canceled after 0s
Tests / Test Summary (push) Canceled after 0s
源码快照 @ 2026-09-01 (source-only, 剔除非源码素材)
2026-09-01 20:01:50 +08:00

97 lines
3.5 KiB
Python

# -*- coding: utf-8 -*-
"""
Provider Contract Tests
Ensures all Provider subclasses satisfy the base interface.
Usage:
class TestOpenAIProviderContract(ProviderContractTest):
def create_instance(self):
return OpenAIProvider(id="openai", name="OpenAI", ...)
"""
from __future__ import annotations
from abc import abstractmethod
from typing import Any
from .. import BaseContractTest
class ProviderContractTest(BaseContractTest):
"""
Contract tests for Provider subclasses.
All LLM providers must satisfy these contracts.
"""
@abstractmethod
def create_instance(self) -> Any:
"""Provide a configured provider instance."""
# =========================================================================
# Contract: Required Abstract Methods
# =========================================================================
def test_has_check_connection_method(self, instance):
"""Contract: All providers must implement check_connection()."""
assert hasattr(
instance,
"check_connection",
), "Missing check_connection()"
assert callable(getattr(instance, "check_connection"))
def test_has_fetch_models_method(self, instance):
"""Contract: All providers must implement fetch_models()."""
assert hasattr(instance, "fetch_models"), "Missing fetch_models()"
assert callable(getattr(instance, "fetch_models"))
def test_has_check_model_connection_method(self, instance):
"""Contract: All providers must implement check_model_connection()."""
assert hasattr(
instance,
"check_model_connection",
), "Missing check_model_connection()"
assert callable(getattr(instance, "check_model_connection"))
# =========================================================================
# Contract: Common Attributes
# =========================================================================
def test_has_provider_id(self, instance):
"""Contract: Providers must have id attribute."""
assert hasattr(instance, "id"), "Missing id attribute"
assert isinstance(instance.id, str), "id must be string"
def test_has_provider_name(self, instance):
"""Contract: Providers must have name attribute."""
assert hasattr(instance, "name"), "Missing name attribute"
assert isinstance(instance.name, str), "name must be string"
def test_has_base_url(self, instance):
"""Contract: Providers must have base_url attribute."""
assert hasattr(instance, "base_url"), "Missing base_url attribute"
def test_has_api_key(self, instance):
"""Contract: Providers must have api_key attribute."""
assert hasattr(instance, "api_key"), "Missing api_key attribute"
def test_has_models_list(self, instance):
"""Contract: Providers must have models list."""
assert hasattr(instance, "models"), "Missing models attribute"
def test_has_chat_model(self, instance):
"""Contract: Providers must have chat_model attribute."""
assert hasattr(instance, "chat_model"), "Missing chat_model attribute"
# =============================================================================
# Example Implementations (TODO: Add real ones)
# =============================================================================
# Example usage:
# class TestOpenAIProviderContract(ProviderContractTest):
# def create_instance(self):
# from qwenpaw.providers.openai_provider import OpenAIProvider
# return OpenAIProvider(...)