mirror of
https://github.com/hwchase17/langchain.git
synced 2026-06-09 10:17:00 +00:00
Thank you for contributing to LangChain! Follow these steps to mark your
pull request as ready for review. **If any of these steps are not
completed, your PR will not be considered for review.**
- [x] **PR title**: Follows the format: {TYPE}({SCOPE}): {DESCRIPTION}
- [x] **PR message**: ***Delete this entire checklist*** and replace
with
fix #30146
- [x] **Add tests and docs**: If you're adding a new integration, you
must include:
- [x] **Lint and test**: Run `make format`, `make lint` and `make test`
from the root of the package(s) you've modified. **We will not consider
a PR unless these three are passing in CI.** See [contribution
guidelines](https://python.langchain.com/docs/contributing/) for more.
Additional guidelines:
- Make sure optional dependencies are imported within a function.
- Please do not add dependencies to `pyproject.toml` files (even
optional ones) unless they are **required** for unit tests.
- Most PRs should not touch more than one package.
- Changes should be backwards compatible.
---------
Co-authored-by: Mason Daugherty <mason@langchain.dev>
Co-authored-by: Mason Daugherty <github@mdrxy.com>
63 lines
2.0 KiB
Python
63 lines
2.0 KiB
Python
"""Test client utility functions."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from langchain_anthropic._client_utils import (
|
|
_get_default_async_httpx_client,
|
|
_get_default_httpx_client,
|
|
)
|
|
|
|
|
|
def test_sync_client_without_proxy() -> None:
|
|
"""Test sync client creation without proxy."""
|
|
client = _get_default_httpx_client(base_url="https://api.anthropic.com")
|
|
|
|
# Should not have proxy configured
|
|
assert not hasattr(client, "proxies") or client.proxies is None
|
|
|
|
|
|
def test_sync_client_with_proxy() -> None:
|
|
"""Test sync client creation with proxy."""
|
|
proxy_url = "http://proxy.example.com:8080"
|
|
client = _get_default_httpx_client(
|
|
base_url="https://api.anthropic.com", anthropic_proxy=proxy_url
|
|
)
|
|
|
|
# Check internal _transport since httpx stores proxy configuration in the transport
|
|
# layer
|
|
transport = getattr(client, "_transport", None)
|
|
assert transport is not None
|
|
|
|
|
|
def test_async_client_without_proxy() -> None:
|
|
"""Test async client creation without proxy."""
|
|
client = _get_default_async_httpx_client(base_url="https://api.anthropic.com")
|
|
|
|
assert not hasattr(client, "proxies") or client.proxies is None
|
|
|
|
|
|
def test_async_client_with_proxy() -> None:
|
|
"""Test async client creation with proxy."""
|
|
proxy_url = "http://proxy.example.com:8080"
|
|
client = _get_default_async_httpx_client(
|
|
base_url="https://api.anthropic.com", anthropic_proxy=proxy_url
|
|
)
|
|
|
|
transport = getattr(client, "_transport", None)
|
|
assert transport is not None
|
|
|
|
|
|
def test_client_proxy_none_value() -> None:
|
|
"""Test that explicitly passing None for proxy works correctly."""
|
|
sync_client = _get_default_httpx_client(
|
|
base_url="https://api.anthropic.com", anthropic_proxy=None
|
|
)
|
|
|
|
async_client = _get_default_async_httpx_client(
|
|
base_url="https://api.anthropic.com", anthropic_proxy=None
|
|
)
|
|
|
|
# Both should be created successfully with None proxy
|
|
assert sync_client is not None
|
|
assert async_client is not None
|