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
92 lines
2.5 KiB
Python
92 lines
2.5 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""
|
|
Contract Test Framework
|
|
|
|
Provides abstract contract tests that enforce all subclasses follow
|
|
the same interface contract. When a base class changes, all subclass
|
|
tests automatically validate they still satisfy the contract.
|
|
|
|
Example:
|
|
class MyBaseContract(BaseContractTest):
|
|
@abstractmethod
|
|
def create_instance(self):
|
|
pass
|
|
|
|
def test_contract(self, instance):
|
|
# Runs for ALL subclasses
|
|
assert hasattr(instance, 'required_method')
|
|
|
|
class TestMyImpl(MyBaseContract):
|
|
def create_instance(self):
|
|
return MyImpl()
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import inspect
|
|
from abc import ABC, abstractmethod
|
|
from typing import Any
|
|
|
|
import pytest
|
|
|
|
|
|
class BaseContractTest(ABC):
|
|
"""
|
|
Base class for contract tests.
|
|
|
|
Subclasses must implement `create_instance()` to provide an instance
|
|
of the class being tested. All test methods defined here automatically
|
|
run for each subclass.
|
|
|
|
Example:
|
|
class MyBaseContract(BaseContractTest):
|
|
@abstractmethod
|
|
def create_instance(self) -> MyBase:
|
|
pass
|
|
|
|
def test_has_required_method(self, instance):
|
|
assert hasattr(instance, 'required_method')
|
|
|
|
class TestMyImpl(MyBaseContract):
|
|
def create_instance(self):
|
|
return MyImpl()
|
|
"""
|
|
|
|
@abstractmethod
|
|
def create_instance(self) -> Any:
|
|
"""
|
|
Create and return an instance of the class under test.
|
|
|
|
Must be implemented by each concrete test subclass.
|
|
"""
|
|
raise NotImplementedError(
|
|
f"{self.__class__.__name__} must implement create_instance()",
|
|
)
|
|
|
|
@pytest.fixture
|
|
def instance(self) -> Any:
|
|
"""Fixture that provides the instance from create_instance()."""
|
|
return self.create_instance()
|
|
|
|
@classmethod
|
|
def get_concrete_tests(cls) -> list[type]:
|
|
"""
|
|
Get all concrete (non-abstract) test subclasses.
|
|
|
|
Returns:
|
|
List of test classes that inherit from this contract.
|
|
"""
|
|
subclasses = []
|
|
for subclass in cls.__subclasses__():
|
|
# Check if it's a concrete implementation (not abstract)
|
|
if not inspect.isabstract(subclass):
|
|
subclasses.append(subclass)
|
|
# Recursively get subclasses
|
|
subclasses.extend(subclass.get_concrete_tests())
|
|
return subclasses
|
|
|
|
|
|
__all__ = [
|
|
"BaseContractTest",
|
|
]
|