97e91a83f3
Ruff / Ruff (push) Waiting to run
Test / Core Tests (push) Waiting to run
Test / Offline Coverage Tests (Python 3.10) (push) Waiting to run
Test / Offline Coverage Tests (Python 3.11) (push) Waiting to run
Test / Offline Coverage Tests (Python 3.12) (push) Waiting to run
Test / Offline Coverage Tests (Python 3.13) (push) Waiting to run
Test / Offline Coverage Tests (Python 3.9) (push) Waiting to run
Test / Full Coverage (Python 3.11) (push) Waiting to run
Test / Core Provider Tests (OpenAI) (push) Blocked by required conditions
Test / Core Provider Tests (Anthropic) (push) Blocked by required conditions
Test / Core Provider Tests (Google) (push) Blocked by required conditions
Test / Core Provider Tests (Other) (push) Blocked by required conditions
Test / Anthropic Tests (push) Blocked by required conditions
Test / Gemini Tests (push) Blocked by required conditions
Test / Google GenAI Tests (push) Blocked by required conditions
Test / Vertex AI Tests (push) Blocked by required conditions
Test / OpenAI Tests (push) Blocked by required conditions
Test / Writer Tests (push) Blocked by required conditions
Test / Auto Client Tests (push) Blocked by required conditions
ty / type-check (push) Waiting to run
43 lines
1.6 KiB
Python
43 lines
1.6 KiB
Python
import sys
|
|
import pytest
|
|
|
|
|
|
def test_from_provider_xai_requires_optional_extra(monkeypatch):
|
|
"""Test that from_provider('xai/...') raises ConfigurationError when xai_sdk is missing."""
|
|
import instructor
|
|
from instructor.core.exceptions import ConfigurationError
|
|
|
|
# Simulate xai_sdk being absent by temporarily hiding it
|
|
monkeypatch.setitem(sys.modules, "xai_sdk", None)
|
|
monkeypatch.setitem(sys.modules, "xai_sdk.sync", None)
|
|
monkeypatch.setitem(sys.modules, "xai_sdk.sync.client", None)
|
|
monkeypatch.setitem(sys.modules, "xai_sdk.aio", None)
|
|
monkeypatch.setitem(sys.modules, "xai_sdk.aio.client", None)
|
|
|
|
with pytest.raises(ConfigurationError) as excinfo:
|
|
instructor.from_provider("xai/grok-3-mini", api_key="test-key")
|
|
|
|
msg = str(excinfo.value)
|
|
assert "instructor[xai]" in msg
|
|
assert "uv pip install" in msg
|
|
|
|
|
|
def test_direct_from_xai_has_clear_error_when_sdk_missing(monkeypatch):
|
|
"""Test that from_xai() raises ClientError when xai_sdk is missing."""
|
|
from instructor.v2.core.errors import ClientError
|
|
import instructor.v2.providers.xai.client as xai_client
|
|
|
|
# Simulate xai_sdk being absent by setting the module-level sentinels to None
|
|
monkeypatch.setattr(xai_client, "SyncClient", None)
|
|
monkeypatch.setattr(xai_client, "AsyncClient", None)
|
|
monkeypatch.setattr(xai_client, "xchat", None)
|
|
|
|
with pytest.raises(ClientError) as excinfo:
|
|
xai_client.from_xai(
|
|
object()
|
|
) # ty: ignore[no-matching-overload] - deliberately invalid client
|
|
|
|
msg = str(excinfo.value)
|
|
assert "instructor[xai]" in msg
|
|
assert "xai-sdk" in msg
|