Buckets:

download
raw
5.08 kB
"""Tests for the lightweight ProviderRegistry."""
import pytest
from osprey.models.provider_registry import (
ProviderRegistry,
get_provider_registry,
reset_provider_registry,
)
@pytest.fixture(autouse=True)
def _clean_singleton():
"""Reset the singleton before and after every test."""
reset_provider_registry()
yield
reset_provider_registry()
class TestProviderRegistry:
"""Unit tests for ProviderRegistry."""
@pytest.mark.unit
def test_get_builtin_provider(self):
"""Built-in providers (e.g. anthropic) resolve to a class."""
reg = ProviderRegistry()
cls = reg.get_provider("anthropic")
assert cls is not None
assert cls.name == "anthropic"
@pytest.mark.unit
def test_get_unknown_returns_none(self):
"""Unknown provider name returns None, never raises."""
reg = ProviderRegistry()
assert reg.get_provider("does_not_exist") is None
@pytest.mark.unit
def test_register_custom_provider(self):
"""Custom providers registered at runtime are resolvable."""
reg = ProviderRegistry()
reg.register_provider(
"anthropic_custom",
"osprey.models.providers.anthropic",
"AnthropicProviderAdapter",
)
cls = reg.get_provider("anthropic_custom")
assert cls is not None
assert cls.name == "anthropic"
@pytest.mark.unit
def test_list_providers_contains_all_builtins(self):
"""list_providers returns all 12 built-in names."""
reg = ProviderRegistry()
names = reg.list_providers()
expected = {
"anthropic",
"openai",
"google",
"ollama",
"cborg",
"amsc-i2",
"als-apg",
"stanford",
"argo",
"asksage",
"vllm",
"ds4",
}
assert expected == set(names)
assert len(names) == 12
@pytest.mark.unit
def test_singleton_identity(self):
"""get_provider_registry() returns the same instance."""
a = get_provider_registry()
b = get_provider_registry()
assert a is b
@pytest.mark.unit
def test_load_providers_config_filtered(self):
"""load_providers with configured_names only loads those."""
reg = ProviderRegistry()
result = reg.load_providers(configured_names={"anthropic", "cborg"})
assert set(result.keys()) == {"anthropic", "cborg"}
@pytest.mark.unit
def test_load_providers_exclusion_filtered(self):
"""load_providers with excluded_names skips those."""
reg = ProviderRegistry()
result = reg.load_providers(excluded_names={"anthropic", "openai"})
assert "anthropic" not in result
assert "openai" not in result
# All others should be present (may fail if import fails on CI)
assert "cborg" in result
@pytest.mark.unit
def test_load_providers_skips_failed_imports(self):
"""A configured provider whose module can't be imported is silently
dropped from the result (not crashing the bulk load) while valid
siblings still load. This is the air-gapped behavior the `if cls is not
None` guard exists for — exercised here via a deliberately broken entry.
"""
reg = ProviderRegistry()
reg.register_provider(
"broken_provider",
"osprey.models.providers.does_not_exist_xyz",
"NoSuchAdapter",
)
result = reg.load_providers(configured_names={"anthropic", "broken_provider"})
assert "broken_provider" not in result
assert "anthropic" in result
@pytest.mark.unit
def test_lazy_load_caches(self):
"""Second get_provider call returns cached class (no re-import)."""
reg = ProviderRegistry()
first = reg.get_provider("anthropic")
second = reg.get_provider("anthropic")
assert first is second
@pytest.mark.unit
def test_ds4_is_registered(self):
"""ds4 resolves to its adapter and is keyless."""
from osprey.models.provider_registry import PROVIDER_API_KEYS
reg = ProviderRegistry()
cls = reg.get_provider("ds4")
assert cls is not None
assert cls.name == "ds4"
assert PROVIDER_API_KEYS.get("ds4", "MISSING") is None
@pytest.mark.unit
def test_register_override_evicts_cache(self):
"""Overwriting an existing entry clears the cache for that name."""
reg = ProviderRegistry()
# Load anthropic into cache
reg.get_provider("anthropic")
assert "anthropic" in reg._providers
# Override with a different class
reg.register_provider(
"anthropic",
"osprey.models.providers.openai",
"OpenAIProviderAdapter",
)
# Cache should be evicted
assert "anthropic" not in reg._providers
cls = reg.get_provider("anthropic")
assert cls is not None
assert cls.name == "openai"

Xet Storage Details

Size:
5.08 kB
·
Xet hash:
0325ac187bf6f81e9770f21f15d16c23e7753b30a3eb1b1c22d1c6b058c71ed7

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.