Home / File/ test_arbitrary_types.py — fastapi Source File

test_arbitrary_types.py — fastapi Source File

Architecture documentation for test_arbitrary_types.py, a python file in the fastapi codebase. 6 imports, 0 dependents.

File python FastAPI Responses 6 imports 4 functions 2 classes

Entity Profile

Dependency Diagram

graph LR
  0a65a3af_f6dc_1275_2ed7_2fa9f4e69088["test_arbitrary_types.py"]
  0dda2280_3359_8460_301c_e98c77e78185["typing"]
  0a65a3af_f6dc_1275_2ed7_2fa9f4e69088 --> 0dda2280_3359_8460_301c_e98c77e78185
  5befe8bf_65d1_d058_6b78_4a597a8488e9["pytest"]
  0a65a3af_f6dc_1275_2ed7_2fa9f4e69088 --> 5befe8bf_65d1_d058_6b78_4a597a8488e9
  534f6e44_61b8_3c38_8b89_6934a6df9802["__init__.py"]
  0a65a3af_f6dc_1275_2ed7_2fa9f4e69088 --> 534f6e44_61b8_3c38_8b89_6934a6df9802
  a7c04dee_ee23_5891_b185_47ff6bed036d["testclient.py"]
  0a65a3af_f6dc_1275_2ed7_2fa9f4e69088 --> a7c04dee_ee23_5891_b185_47ff6bed036d
  a7f4e7b0_9725_db90_5cbc_7ca8211b323a["inline_snapshot"]
  0a65a3af_f6dc_1275_2ed7_2fa9f4e69088 --> a7f4e7b0_9725_db90_5cbc_7ca8211b323a
  6913fbd4_39df_d14b_44bb_522e99b65b90["pydantic"]
  0a65a3af_f6dc_1275_2ed7_2fa9f4e69088 --> 6913fbd4_39df_d14b_44bb_522e99b65b90
  style 0a65a3af_f6dc_1275_2ed7_2fa9f4e69088 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

from typing import Annotated

import pytest
from fastapi import FastAPI
from fastapi.testclient import TestClient
from inline_snapshot import snapshot


@pytest.fixture(name="client")
def get_client():
    from pydantic import (
        BaseModel,
        ConfigDict,
        PlainSerializer,
        TypeAdapter,
        WithJsonSchema,
    )

    class FakeNumpyArray:
        def __init__(self):
            self.data = [1.0, 2.0, 3.0]

    FakeNumpyArrayPydantic = Annotated[
        FakeNumpyArray,
        WithJsonSchema(TypeAdapter(list[float]).json_schema()),
        PlainSerializer(lambda v: v.data),
    ]

    class MyModel(BaseModel):
        model_config = ConfigDict(arbitrary_types_allowed=True)
        custom_field: FakeNumpyArrayPydantic

    app = FastAPI()

    @app.get("/")
    def test() -> MyModel:
        return MyModel(custom_field=FakeNumpyArray())

    client = TestClient(app)
    return client


def test_get(client: TestClient):
    response = client.get("/")
    assert response.json() == {"custom_field": [1.0, 2.0, 3.0]}


def test_typeadapter():
    # This test is only to confirm that Pydantic alone is working as expected
    from pydantic import (
        BaseModel,
        ConfigDict,
        PlainSerializer,
        TypeAdapter,
        WithJsonSchema,
    )

    class FakeNumpyArray:
        def __init__(self):
            self.data = [1.0, 2.0, 3.0]
// ... (76 more lines)

Domain

Subdomains

Dependencies

Frequently Asked Questions

What does test_arbitrary_types.py do?
test_arbitrary_types.py is a source file in the fastapi codebase, written in python. It belongs to the FastAPI domain, Responses subdomain.
What functions are defined in test_arbitrary_types.py?
test_arbitrary_types.py defines 4 function(s): get_client, test_get, test_openapi_schema, test_typeadapter.
What does test_arbitrary_types.py depend on?
test_arbitrary_types.py imports 6 module(s): __init__.py, inline_snapshot, pydantic, pytest, testclient.py, typing.
Where is test_arbitrary_types.py in the architecture?
test_arbitrary_types.py is located at tests/test_arbitrary_types.py (domain: FastAPI, subdomain: Responses, directory: tests).

Analyze Your Own Codebase

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

Try Supermodel Free