Files
derek.holloway 7502bf64a4
CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
Flatten subprojects into a single base monorepo
2026-09-02 16:34:47 -07:00

77 lines
2.3 KiB
Python

"""Tests for perfxpert.providers.registry."""
import pytest
from perfxpert.providers import registry
from perfxpert.providers._base import Provider, ProviderResponse
from perfxpert.providers._exceptions import DryRunResponse
class _StubProvider(Provider):
def complete(self, messages, *, system="", model=None, max_tokens=None, dry_run=False):
if dry_run:
return DryRunResponse
return ProviderResponse(
content="stub",
provider="stub",
model=model or "stub-1",
input_tokens=0,
output_tokens=0,
)
@pytest.fixture(autouse=True)
def _reset_registry(monkeypatch):
"""Isolate tests — clear the module-level registry before/after."""
saved = dict(registry._REGISTRY)
registry._REGISTRY.clear()
yield
registry._REGISTRY.clear()
registry._REGISTRY.update(saved)
def test_register_then_get_returns_instance():
registry.register("stub", _StubProvider, "Stub for tests")
inst = registry.get_provider("stub")
assert isinstance(inst, _StubProvider)
def test_list_providers_includes_registered():
registry.register("stub", _StubProvider, "Stub for tests")
listing = registry.list_providers()
assert "stub" in listing
assert listing["stub"] == "Stub for tests"
def test_get_unknown_raises():
with pytest.raises(KeyError) as exc:
registry.get_provider("nonexistent")
assert "nonexistent" in str(exc.value)
def test_re_register_overwrites_silently():
registry.register("stub", _StubProvider, "first")
registry.register("stub", _StubProvider, "second")
assert registry.list_providers()["stub"] == "second"
def test_registered_instance_routes_dry_run():
registry.register("stub", _StubProvider, "desc")
inst = registry.get_provider("stub")
assert inst.complete([], dry_run=True) is DryRunResponse
def test_get_provider_forwards_kwargs():
captured = {}
class _Captures(Provider):
def __init__(self, **kwargs):
captured.update(kwargs)
def complete(self, messages, *, system="", model=None, max_tokens=None, dry_run=False):
return DryRunResponse
registry.register("cap", _Captures, "desc")
registry.get_provider("cap", foo="bar", timeout=30)
assert captured == {"foo": "bar", "timeout": 30}