From 2b2d3c4124aeed9239722ec551b8c829c061ec37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20K=C3=B6tter?= Date: Thu, 29 Aug 2024 07:12:41 +0200 Subject: [PATCH] tests - skipif? --- tests/schema_test.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/tests/schema_test.py b/tests/schema_test.py index 95ebe7de..b4be99b1 100644 --- a/tests/schema_test.py +++ b/tests/schema_test.py @@ -4,6 +4,8 @@ import uuid from unittest.mock import MagicMock, patch +from pydantic.fields import FieldInfo + if sys.version_info >= (3, 9): from pathlib import Path else: @@ -106,6 +108,7 @@ def test_schema_string_pattern(with_schema_string_pattern): @pytest.mark.skipif(sys.version_info <= (3, 8), reason="typing") def test_schema_regex_engine(with_schema_regex_engine): + print(sys.version_info) api = OpenAPI("/", with_schema_regex_engine) Root = api.components.schemas["Root"].get_type() @@ -123,8 +126,12 @@ def test_schema_regex_engine(with_schema_regex_engine): import pydantic_core._pydantic_core with pytest.raises(pydantic_core._pydantic_core.SchemaError, match="error: unclosed character class$"): - pattern = typing.get_args(Root.model_fields["root"].annotation)[1].metadata[0].pattern - + annotations = typing.get_args(Root.model_fields["root"].annotation) + assert len(annotations) == 2 and annotations[0] == str and isinstance(annotations[1], FieldInfo), annotations + metadata = annotations[1].metadata + assert len(metadata) == 1, metadata + pattern = metadata[0].pattern + assert isinstance(pattern, str), pattern from typing import Annotated C = Annotated[str, pydantic.Field(pattern=pattern)]