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

test_extract_files.py — anthropic-sdk-python Source File

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

File python AnthropicClient AsyncAPI 4 imports 3 functions

Entity Profile

Dependency Diagram

graph LR
  0c5e6779_0a2a_28fc_5287_7349e6c59ced["test_extract_files.py"]
  89ddcdd7_3ae1_4c7b_41bb_9f1e25f16875["typing"]
  0c5e6779_0a2a_28fc_5287_7349e6c59ced --> 89ddcdd7_3ae1_4c7b_41bb_9f1e25f16875
  cde8421b_93c7_41e4_d69d_2a3f1bade2f2["pytest"]
  0c5e6779_0a2a_28fc_5287_7349e6c59ced --> cde8421b_93c7_41e4_d69d_2a3f1bade2f2
  01a140e6_b92b_0f78_5c02_ede12a95cdde["anthropic._types"]
  0c5e6779_0a2a_28fc_5287_7349e6c59ced --> 01a140e6_b92b_0f78_5c02_ede12a95cdde
  d1009234_f799_7c53_7892_4262523206dd["anthropic._utils"]
  0c5e6779_0a2a_28fc_5287_7349e6c59ced --> d1009234_f799_7c53_7892_4262523206dd
  style 0c5e6779_0a2a_28fc_5287_7349e6c59ced fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

from __future__ import annotations

from typing import Sequence

import pytest

from anthropic._types import FileTypes
from anthropic._utils import extract_files


def test_removes_files_from_input() -> None:
    query = {"foo": "bar"}
    assert extract_files(query, paths=[]) == []
    assert query == {"foo": "bar"}

    query2 = {"foo": b"Bar", "hello": "world"}
    assert extract_files(query2, paths=[["foo"]]) == [("foo", b"Bar")]
    assert query2 == {"hello": "world"}

    query3 = {"foo": {"foo": {"bar": b"Bar"}}, "hello": "world"}
    assert extract_files(query3, paths=[["foo", "foo", "bar"]]) == [("foo[foo][bar]", b"Bar")]
    assert query3 == {"foo": {"foo": {}}, "hello": "world"}

    query4 = {"foo": {"bar": b"Bar", "baz": "foo"}, "hello": "world"}
    assert extract_files(query4, paths=[["foo", "bar"]]) == [("foo[bar]", b"Bar")]
    assert query4 == {"hello": "world", "foo": {"baz": "foo"}}


def test_multiple_files() -> None:
    query = {"documents": [{"file": b"My first file"}, {"file": b"My second file"}]}
    assert extract_files(query, paths=[["documents", "<array>", "file"]]) == [
        ("documents[][file]", b"My first file"),
        ("documents[][file]", b"My second file"),
    ]
    assert query == {"documents": [{}, {}]}


@pytest.mark.parametrize(
    "query,paths,expected",
    [
        [
            {"foo": {"bar": "baz"}},
            [["foo", "<array>", "bar"]],
            [],
        ],
        [
            {"foo": ["bar", "baz"]},
            [["foo", "bar"]],
            [],
        ],
        [
            {"foo": {"bar": "baz"}},
            [["foo", "foo"]],
            [],
        ],
    ],
    ids=["dict expecting array", "array expecting dict", "unknown keys"],
)
def test_ignores_incorrect_paths(
    query: dict[str, object],
    paths: Sequence[Sequence[str]],
    expected: list[tuple[str, FileTypes]],
) -> None:
    assert extract_files(query, paths=paths) == expected

Subdomains

Dependencies

  • anthropic._types
  • anthropic._utils
  • pytest
  • typing

Frequently Asked Questions

What does test_extract_files.py do?
test_extract_files.py is a source file in the anthropic-sdk-python codebase, written in python. It belongs to the AnthropicClient domain, AsyncAPI subdomain.
What functions are defined in test_extract_files.py?
test_extract_files.py defines 3 function(s): test_ignores_incorrect_paths, test_multiple_files, test_removes_files_from_input.
What does test_extract_files.py depend on?
test_extract_files.py imports 4 module(s): anthropic._types, anthropic._utils, pytest, typing.
Where is test_extract_files.py in the architecture?
test_extract_files.py is located at tests/test_extract_files.py (domain: AnthropicClient, subdomain: AsyncAPI, directory: tests).

Analyze Your Own Codebase

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

Try Supermodel Free