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
110 lines
2.9 KiB
Python
110 lines
2.9 KiB
Python
from __future__ import annotations
|
|
|
|
import asyncio
|
|
import inspect
|
|
import warnings
|
|
from collections.abc import Iterator
|
|
from contextlib import contextmanager
|
|
from typing import Any
|
|
|
|
import pytest
|
|
from pydantic.warnings import PydanticDeprecatedSince20
|
|
|
|
|
|
def clear_proxy_environment(monkeypatch: pytest.MonkeyPatch) -> None:
|
|
for name in (
|
|
"ALL_PROXY",
|
|
"all_proxy",
|
|
"HTTP_PROXY",
|
|
"http_proxy",
|
|
"HTTPS_PROXY",
|
|
"https_proxy",
|
|
):
|
|
monkeypatch.delenv(name, raising=False)
|
|
|
|
|
|
@contextmanager
|
|
def ignore_fireworks_pydantic_warning() -> Iterator[None]:
|
|
with warnings.catch_warnings():
|
|
warnings.filterwarnings(
|
|
"ignore",
|
|
message=r"Pydantic V1 style `@validator` validators are deprecated\..*",
|
|
category=PydanticDeprecatedSince20,
|
|
module=r"fireworks\.client\.image_api",
|
|
)
|
|
yield
|
|
|
|
|
|
def close_idle_event_loop() -> None:
|
|
try:
|
|
with warnings.catch_warnings():
|
|
warnings.filterwarnings(
|
|
"error",
|
|
message=r"There is no current event loop",
|
|
category=DeprecationWarning,
|
|
)
|
|
loop = asyncio.get_event_loop()
|
|
except (RuntimeError, DeprecationWarning):
|
|
return
|
|
|
|
if loop.is_running():
|
|
return
|
|
if not loop.is_closed():
|
|
loop.close()
|
|
asyncio.set_event_loop(None)
|
|
|
|
|
|
def close_provider_client(client: Any, *, async_client: bool = False) -> None:
|
|
if client is None:
|
|
return
|
|
|
|
if type(client).__module__.startswith("fireworks.client"):
|
|
if async_client:
|
|
asyncio.run(close_async_provider_client(client))
|
|
else:
|
|
client._client_v1.close()
|
|
client._image_client_v1.close()
|
|
return
|
|
|
|
methods = (
|
|
(("aclose", ()), ("close", ()), ("__aexit__", (None, None, None)))
|
|
if async_client
|
|
else (("close", ()), ("__exit__", (None, None, None)))
|
|
)
|
|
for name, args in methods:
|
|
method = getattr(client, name, None)
|
|
if not callable(method):
|
|
continue
|
|
result = method(*args)
|
|
if inspect.isawaitable(result):
|
|
|
|
async def wait_for_close(awaitable: Any) -> None:
|
|
await awaitable
|
|
|
|
asyncio.run(wait_for_close(result))
|
|
return
|
|
|
|
|
|
async def close_async_provider_client(client: Any) -> None:
|
|
if client is None:
|
|
return
|
|
|
|
if type(client).__module__.startswith("fireworks.client"):
|
|
client._client_v1.close()
|
|
client._image_client_v1.close()
|
|
await client.aclose()
|
|
return
|
|
|
|
for name, args in (
|
|
("aclose", ()),
|
|
("close", ()),
|
|
("__aexit__", (None, None, None)),
|
|
):
|
|
method = getattr(client, name, None)
|
|
if not callable(method):
|
|
continue
|
|
result = method(*args)
|
|
if inspect.isawaitable(result):
|
|
await result
|
|
return
|