test_custom_encoders() — fastapi Function Reference
Architecture documentation for the test_custom_encoders() function in test_jsonable_encoder.py from the fastapi codebase.
Entity Profile
Dependency Diagram
graph TD a89fe105_75ff_c792_4371_cb1070151432["test_custom_encoders()"] 80ce950d_4c72_e7d9_21bb_a5c60524786c["test_jsonable_encoder.py"] a89fe105_75ff_c792_4371_cb1070151432 -->|defined in| 80ce950d_4c72_e7d9_21bb_a5c60524786c 1ac1bc37_1a47_e7e2_9156_ab0473094700["jsonable_encoder()"] a89fe105_75ff_c792_4371_cb1070151432 -->|calls| 1ac1bc37_1a47_e7e2_9156_ab0473094700 78cf9f6d_f562_f455_e0de_8806b95a89f1["isoformat()"] a89fe105_75ff_c792_4371_cb1070151432 -->|calls| 78cf9f6d_f562_f455_e0de_8806b95a89f1 style a89fe105_75ff_c792_4371_cb1070151432 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
tests/test_jsonable_encoder.py lines 205–225
def test_custom_encoders():
class safe_datetime(datetime):
pass
class MyDict(TypedDict):
dt_field: safe_datetime
instance = MyDict(dt_field=safe_datetime.now())
encoded_instance = jsonable_encoder(
instance, custom_encoder={safe_datetime: lambda o: o.strftime("%H:%M:%S")}
)
assert encoded_instance["dt_field"] == instance["dt_field"].strftime("%H:%M:%S")
encoded_instance = jsonable_encoder(
instance, custom_encoder={datetime: lambda o: o.strftime("%H:%M:%S")}
)
assert encoded_instance["dt_field"] == instance["dt_field"].strftime("%H:%M:%S")
encoded_instance2 = jsonable_encoder(instance)
assert encoded_instance2["dt_field"] == instance["dt_field"].isoformat()
Domain
Subdomains
Defined In
Source
Frequently Asked Questions
What does test_custom_encoders() do?
test_custom_encoders() is a function in the fastapi codebase, defined in tests/test_jsonable_encoder.py.
Where is test_custom_encoders() defined?
test_custom_encoders() is defined in tests/test_jsonable_encoder.py at line 205.
What does test_custom_encoders() call?
test_custom_encoders() calls 2 function(s): isoformat, jsonable_encoder.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free