Skip to content

Commit 14b032a

Browse files
committed
update tests to remove pydantic v1 tests
1 parent b2dbc8b commit 14b032a

File tree

2 files changed

+8
-59
lines changed

2 files changed

+8
-59
lines changed

scripts/test

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,8 @@ PY_VERSION_MIN=">=3.9.0"
1414
PY_VERSION_MAX=">=3.14.0"
1515

1616
function run_tests() {
17-
echo "==> Running tests with Pydantic v2"
17+
echo "==> Running tests"
1818
uv run --isolated --all-extras pytest "$@"
19-
20-
# Skip Pydantic v1 tests on latest Python (not supported)
21-
if [[ "$UV_PYTHON" != "$PY_VERSION_MAX" ]]; then
22-
echo "==> Running tests with Pydantic v1"
23-
uv run --isolated --all-extras --group=pydantic-v1 pytest "$@"
24-
fi
2519
}
2620

2721
# If UV_PYTHON is already set in the environment, just run the command once

tests/test_models.py

Lines changed: 7 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from pydantic import Field
99

1010
from stagehand._utils import PropertyInfo
11-
from stagehand._compat import PYDANTIC_V1, parse_obj, model_dump, model_json
11+
from stagehand._compat import parse_obj, model_dump, model_json
1212
from stagehand._models import DISCRIMINATOR_CACHE, BaseModel, construct_type
1313

1414

@@ -294,12 +294,8 @@ class Model(BaseModel):
294294
assert cast(bool, m.foo) is True
295295

296296
m = Model.construct(foo={"name": 3})
297-
if PYDANTIC_V1:
298-
assert isinstance(m.foo, Submodel2)
299-
assert m.foo.name == "3"
300-
else:
301-
assert isinstance(m.foo, Submodel1)
302-
assert m.foo.name == 3 # type: ignore
297+
assert isinstance(m.foo, Submodel1)
298+
assert m.foo.name == 3 # type: ignore
303299

304300

305301
def test_list_of_unions() -> None:
@@ -426,10 +422,7 @@ class Model(BaseModel):
426422

427423
expected = datetime(2019, 12, 27, 18, 11, 19, 117000, tzinfo=timezone.utc)
428424

429-
if PYDANTIC_V1:
430-
expected_json = '{"created_at": "2019-12-27T18:11:19.117000+00:00"}'
431-
else:
432-
expected_json = '{"created_at":"2019-12-27T18:11:19.117000Z"}'
425+
expected_json = '{"created_at":"2019-12-27T18:11:19.117000Z"}'
433426

434427
model = Model.construct(created_at="2019-12-27T18:11:19.117Z")
435428
assert model.created_at == expected
@@ -531,10 +524,6 @@ class Model2(BaseModel):
531524
assert m4.to_dict(mode="python") == {"created_at": datetime.fromisoformat(time_str)}
532525
assert m4.to_dict(mode="json") == {"created_at": time_str}
533526

534-
if PYDANTIC_V1:
535-
with pytest.raises(ValueError, match="warnings is only supported in Pydantic v2"):
536-
m.to_dict(warnings=False)
537-
538527

539528
def test_forwards_compat_model_dump_method() -> None:
540529
class Model(BaseModel):
@@ -556,13 +545,6 @@ class Model(BaseModel):
556545
assert m3.model_dump() == {"foo": None}
557546
assert m3.model_dump(exclude_none=True) == {}
558547

559-
if PYDANTIC_V1:
560-
with pytest.raises(ValueError, match="round_trip is only supported in Pydantic v2"):
561-
m.model_dump(round_trip=True)
562-
563-
with pytest.raises(ValueError, match="warnings is only supported in Pydantic v2"):
564-
m.model_dump(warnings=False)
565-
566548

567549
def test_compat_method_no_error_for_warnings() -> None:
568550
class Model(BaseModel):
@@ -580,10 +562,7 @@ class Model(BaseModel):
580562
assert json.loads(m.to_json()) == {"FOO": "hello"}
581563
assert json.loads(m.to_json(use_api_names=False)) == {"foo": "hello"}
582564

583-
if PYDANTIC_V1:
584-
assert m.to_json(indent=None) == '{"FOO": "hello"}'
585-
else:
586-
assert m.to_json(indent=None) == '{"FOO":"hello"}'
565+
assert m.to_json(indent=None) == '{"FOO":"hello"}'
587566

588567
m2 = Model()
589568
assert json.loads(m2.to_json()) == {}
@@ -595,10 +574,6 @@ class Model(BaseModel):
595574
assert json.loads(m3.to_json()) == {"FOO": None}
596575
assert json.loads(m3.to_json(exclude_none=True)) == {}
597576

598-
if PYDANTIC_V1:
599-
with pytest.raises(ValueError, match="warnings is only supported in Pydantic v2"):
600-
m.to_json(warnings=False)
601-
602577

603578
def test_forwards_compat_model_dump_json_method() -> None:
604579
class Model(BaseModel):
@@ -622,13 +597,6 @@ class Model(BaseModel):
622597
assert json.loads(m3.model_dump_json()) == {"foo": None}
623598
assert json.loads(m3.model_dump_json(exclude_none=True)) == {}
624599

625-
if PYDANTIC_V1:
626-
with pytest.raises(ValueError, match="round_trip is only supported in Pydantic v2"):
627-
m.model_dump_json(round_trip=True)
628-
629-
with pytest.raises(ValueError, match="warnings is only supported in Pydantic v2"):
630-
m.model_dump_json(warnings=False)
631-
632600

633601
def test_type_compat() -> None:
634602
# our model type can be assigned to Pydantic's model type
@@ -679,12 +647,7 @@ class B(BaseModel):
679647
)
680648
assert isinstance(m, A)
681649
assert m.type == "a"
682-
if PYDANTIC_V1:
683-
# pydantic v1 automatically converts inputs to strings
684-
# if the expected type is a str
685-
assert m.data == "100"
686-
else:
687-
assert m.data == 100 # type: ignore[comparison-overlap]
650+
assert m.data == 100 # type: ignore[comparison-overlap]
688651

689652

690653
def test_discriminated_unions_unknown_variant() -> None:
@@ -768,12 +731,7 @@ class B(BaseModel):
768731
)
769732
assert isinstance(m, A)
770733
assert m.foo_type == "a"
771-
if PYDANTIC_V1:
772-
# pydantic v1 automatically converts inputs to strings
773-
# if the expected type is a str
774-
assert m.data == "100"
775-
else:
776-
assert m.data == 100 # type: ignore[comparison-overlap]
734+
assert m.data == 100 # type: ignore[comparison-overlap]
777735

778736

779737
def test_discriminated_unions_overlapping_discriminators_invalid_data() -> None:
@@ -833,7 +791,6 @@ class B(BaseModel):
833791
assert DISCRIMINATOR_CACHE.get(UnionType) is discriminator
834792

835793

836-
@pytest.mark.skipif(PYDANTIC_V1, reason="TypeAliasType is not supported in Pydantic v1")
837794
def test_type_alias_type() -> None:
838795
Alias = TypeAliasType("Alias", str) # pyright: ignore
839796

@@ -849,7 +806,6 @@ class Model(BaseModel):
849806
assert m.union == "bar"
850807

851808

852-
@pytest.mark.skipif(PYDANTIC_V1, reason="TypeAliasType is not supported in Pydantic v1")
853809
def test_field_named_cls() -> None:
854810
class Model(BaseModel):
855811
cls: str
@@ -936,7 +892,6 @@ class Type2(BaseModel):
936892
assert isinstance(model.value, InnerType2)
937893

938894

939-
@pytest.mark.skipif(PYDANTIC_V1, reason="this is only supported in pydantic v2 for now")
940895
def test_extra_properties() -> None:
941896
class Item(BaseModel):
942897
prop: int

0 commit comments

Comments
 (0)