Skip to content

Commit

Permalink
tests - skipif?
Browse files Browse the repository at this point in the history
  • Loading branch information
commonism committed Aug 29, 2024
1 parent b9321ea commit 2b2d3c4
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions tests/schema_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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()

Expand All @@ -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)]
Expand Down

0 comments on commit 2b2d3c4

Please sign in to comment.