Browse Source

Test allowed

pull/13803/head
Pedro Lobato 2 months ago
parent
commit
d51b7d14b1
  1. 2
      fastapi/encoders.py
  2. 13
      tests/test_jsonable_encoder.py

2
fastapi/encoders.py

@ -17,7 +17,7 @@ from re import Pattern
from types import GeneratorType from types import GeneratorType
from typing import ( from typing import (
Annotated, Annotated,
Any, Any
) )
from uuid import UUID from uuid import UUID

13
tests/test_jsonable_encoder.py

@ -436,11 +436,18 @@ def test_encode_pydantic_extra_types_color():
@pytest.mark.filterwarnings("ignore::DeprecationWarning") @pytest.mark.filterwarnings("ignore::DeprecationWarning")
def test_encode_deprecated_pydantic_color(): @pytest.mark.parametrize(
"module_path",
[
pytest.param("pydantic.color"),
pytest.param("pydantic_extra_types.color"),
],
)
def test_encode_color(module_path):
try: try:
from pydantic.color import Color Color = __import__(module_path, fromlist=["Color"]).Color
except ImportError: # pragma: no cover except ImportError: # pragma: no cover
pytest.skip("pydantic.color not available") pytest.skip(f"{module_path} not available")
data = {"color": Color("blue")} data = {"color": Color("blue")}
assert jsonable_encoder(data) == {"color": "blue"} assert jsonable_encoder(data) == {"color": "blue"}

Loading…
Cancel
Save