Home / File/ test_qs.py — anthropic-sdk-python Source File

test_qs.py — anthropic-sdk-python Source File

Architecture documentation for test_qs.py, a python file in the anthropic-sdk-python codebase. 5 imports, 0 dependents.

File python AnthropicClient Authentication 5 imports 8 functions

Entity Profile

Dependency Diagram

graph LR
  f0b34a63_809b_7308_2411_fc88725d50fa["test_qs.py"]
  89ddcdd7_3ae1_4c7b_41bb_9f1e25f16875["typing"]
  f0b34a63_809b_7308_2411_fc88725d50fa --> 89ddcdd7_3ae1_4c7b_41bb_9f1e25f16875
  4c73056b_526d_2199_4a80_7fcd0cd9bcbe["functools"]
  f0b34a63_809b_7308_2411_fc88725d50fa --> 4c73056b_526d_2199_4a80_7fcd0cd9bcbe
  900b1f66_5ec1_5ff8_7686_a5c6e966d659["urllib.parse"]
  f0b34a63_809b_7308_2411_fc88725d50fa --> 900b1f66_5ec1_5ff8_7686_a5c6e966d659
  cde8421b_93c7_41e4_d69d_2a3f1bade2f2["pytest"]
  f0b34a63_809b_7308_2411_fc88725d50fa --> cde8421b_93c7_41e4_d69d_2a3f1bade2f2
  6b3ceddb_7e27_e2e4_b849_d2c437da11a8["anthropic._qs"]
  f0b34a63_809b_7308_2411_fc88725d50fa --> 6b3ceddb_7e27_e2e4_b849_d2c437da11a8
  style f0b34a63_809b_7308_2411_fc88725d50fa fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

from typing import Any, cast
from functools import partial
from urllib.parse import unquote

import pytest

from anthropic._qs import Querystring, stringify


def test_empty() -> None:
    assert stringify({}) == ""
    assert stringify({"a": {}}) == ""
    assert stringify({"a": {"b": {"c": {}}}}) == ""


def test_basic() -> None:
    assert stringify({"a": 1}) == "a=1"
    assert stringify({"a": "b"}) == "a=b"
    assert stringify({"a": True}) == "a=true"
    assert stringify({"a": False}) == "a=false"
    assert stringify({"a": 1.23456}) == "a=1.23456"
    assert stringify({"a": None}) == ""


@pytest.mark.parametrize("method", ["class", "function"])
def test_nested_dotted(method: str) -> None:
    if method == "class":
        serialise = Querystring(nested_format="dots").stringify
    else:
        serialise = partial(stringify, nested_format="dots")

    assert unquote(serialise({"a": {"b": "c"}})) == "a.b=c"
    assert unquote(serialise({"a": {"b": "c", "d": "e", "f": "g"}})) == "a.b=c&a.d=e&a.f=g"
    assert unquote(serialise({"a": {"b": {"c": {"d": "e"}}}})) == "a.b.c.d=e"
    assert unquote(serialise({"a": {"b": True}})) == "a.b=true"


def test_nested_brackets() -> None:
    assert unquote(stringify({"a": {"b": "c"}})) == "a[b]=c"
    assert unquote(stringify({"a": {"b": "c", "d": "e", "f": "g"}})) == "a[b]=c&a[d]=e&a[f]=g"
    assert unquote(stringify({"a": {"b": {"c": {"d": "e"}}}})) == "a[b][c][d]=e"
    assert unquote(stringify({"a": {"b": True}})) == "a[b]=true"


@pytest.mark.parametrize("method", ["class", "function"])
def test_array_comma(method: str) -> None:
    if method == "class":
        serialise = Querystring(array_format="comma").stringify
    else:
        serialise = partial(stringify, array_format="comma")

    assert unquote(serialise({"in": ["foo", "bar"]})) == "in=foo,bar"
    assert unquote(serialise({"a": {"b": [True, False]}})) == "a[b]=true,false"
    assert unquote(serialise({"a": {"b": [True, False, None, True]}})) == "a[b]=true,false,true"


def test_array_repeat() -> None:
    assert unquote(stringify({"in": ["foo", "bar"]})) == "in=foo&in=bar"
    assert unquote(stringify({"a": {"b": [True, False]}})) == "a[b]=true&a[b]=false"
    assert unquote(stringify({"a": {"b": [True, False, None, True]}})) == "a[b]=true&a[b]=false&a[b]=true"
    assert unquote(stringify({"in": ["foo", {"b": {"c": ["d", "e"]}}]})) == "in=foo&in[b][c]=d&in[b][c]=e"


@pytest.mark.parametrize("method", ["class", "function"])
def test_array_brackets(method: str) -> None:
    if method == "class":
        serialise = Querystring(array_format="brackets").stringify
    else:
        serialise = partial(stringify, array_format="brackets")

    assert unquote(serialise({"in": ["foo", "bar"]})) == "in[]=foo&in[]=bar"
    assert unquote(serialise({"a": {"b": [True, False]}})) == "a[b][]=true&a[b][]=false"
    assert unquote(serialise({"a": {"b": [True, False, None, True]}})) == "a[b][]=true&a[b][]=false&a[b][]=true"


def test_unknown_array_format() -> None:
    with pytest.raises(NotImplementedError, match="Unknown array_format value: foo, choose from comma, repeat"):
        stringify({"a": ["foo", "bar"]}, array_format=cast(Any, "foo"))

Subdomains

Dependencies

  • anthropic._qs
  • functools
  • pytest
  • typing
  • urllib.parse

Frequently Asked Questions

What does test_qs.py do?
test_qs.py is a source file in the anthropic-sdk-python codebase, written in python. It belongs to the AnthropicClient domain, Authentication subdomain.
What functions are defined in test_qs.py?
test_qs.py defines 8 function(s): test_array_brackets, test_array_comma, test_array_repeat, test_basic, test_empty, test_nested_brackets, test_nested_dotted, test_unknown_array_format.
What does test_qs.py depend on?
test_qs.py imports 5 module(s): anthropic._qs, functools, pytest, typing, urllib.parse.
Where is test_qs.py in the architecture?
test_qs.py is located at tests/test_qs.py (domain: AnthropicClient, subdomain: Authentication, directory: tests).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free