mirror of
https://github.com/fastapi/sqlmodel.git
synced 2026-03-13 09:29:54 +08:00
➖ Drop support for Python 3.9 (#1766)
This commit is contained in:
committed by
GitHub
parent
ffdcb44ae2
commit
ede8dd062d
@@ -1,10 +1,10 @@
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
from collections.abc import Generator
|
||||
from collections.abc import Callable, Generator
|
||||
from dataclasses import dataclass, field
|
||||
from pathlib import Path
|
||||
from typing import Any, Callable, Union
|
||||
from typing import Any
|
||||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
@@ -35,7 +35,7 @@ def cov_tmp_path(tmp_path: Path) -> Generator[Path, None, None]:
|
||||
shutil.copy(coverage_path, coverage_destiny_path)
|
||||
|
||||
|
||||
def coverage_run(*, module: str, cwd: Union[str, Path]) -> subprocess.CompletedProcess:
|
||||
def coverage_run(*, module: str, cwd: str | Path) -> subprocess.CompletedProcess:
|
||||
result = subprocess.run(
|
||||
[
|
||||
"coverage",
|
||||
@@ -53,7 +53,7 @@ def coverage_run(*, module: str, cwd: Union[str, Path]) -> subprocess.CompletedP
|
||||
|
||||
|
||||
def get_testing_print_function(
|
||||
calls: list[list[Union[str, dict[str, Any]]]],
|
||||
calls: list[list[str | dict[str, Any]]],
|
||||
) -> Callable[..., Any]:
|
||||
def new_print(*args: Any) -> None:
|
||||
data: list[Any] = []
|
||||
|
||||
@@ -11,7 +11,6 @@ from ...conftest import PrintMock, needs_py310
|
||||
@pytest.fixture(
|
||||
name="mod",
|
||||
params=[
|
||||
pytest.param("tutorial001_py39"),
|
||||
pytest.param("tutorial001_py310", marks=needs_py310),
|
||||
],
|
||||
)
|
||||
|
||||
@@ -11,7 +11,6 @@ from ...conftest import PrintMock, needs_py310
|
||||
@pytest.fixture(
|
||||
name="mod",
|
||||
params=[
|
||||
pytest.param("tutorial001_py39"),
|
||||
pytest.param("tutorial001_py310", marks=needs_py310),
|
||||
],
|
||||
)
|
||||
|
||||
@@ -11,7 +11,6 @@ from ...conftest import PrintMock, needs_py310
|
||||
@pytest.fixture(
|
||||
name="mod",
|
||||
params=[
|
||||
pytest.param("tutorial002_py39"),
|
||||
pytest.param("tutorial002_py310", marks=needs_py310),
|
||||
],
|
||||
)
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
from typing import Union
|
||||
|
||||
import pytest
|
||||
from pydantic import BaseModel, ValidationError
|
||||
from pydantic import Field as PField
|
||||
@@ -28,14 +26,14 @@ class SQLModelUserWithConfig(SQLModelUser):
|
||||
|
||||
|
||||
@pytest.mark.parametrize("model", [PydanticUser, SQLModelUser])
|
||||
def test_create_with_field_name(model: Union[type[PydanticUser], type[SQLModelUser]]):
|
||||
def test_create_with_field_name(model: type[PydanticUser] | type[SQLModelUser]):
|
||||
with pytest.raises(ValidationError):
|
||||
model(full_name="Alice")
|
||||
|
||||
|
||||
@pytest.mark.parametrize("model", [PydanticUserWithConfig, SQLModelUserWithConfig])
|
||||
def test_create_with_field_name_with_config(
|
||||
model: Union[type[PydanticUserWithConfig], type[SQLModelUserWithConfig]],
|
||||
model: type[PydanticUserWithConfig] | type[SQLModelUserWithConfig],
|
||||
):
|
||||
user = model(full_name="Alice")
|
||||
assert user.full_name == "Alice"
|
||||
@@ -46,12 +44,10 @@ def test_create_with_field_name_with_config(
|
||||
[PydanticUser, SQLModelUser, PydanticUserWithConfig, SQLModelUserWithConfig],
|
||||
)
|
||||
def test_create_with_alias(
|
||||
model: Union[
|
||||
type[PydanticUser],
|
||||
type[SQLModelUser],
|
||||
type[PydanticUserWithConfig],
|
||||
type[SQLModelUserWithConfig],
|
||||
],
|
||||
model: type[PydanticUser]
|
||||
| type[SQLModelUser]
|
||||
| type[PydanticUserWithConfig]
|
||||
| type[SQLModelUserWithConfig],
|
||||
):
|
||||
user = model(fullName="Bob") # using alias
|
||||
assert user.full_name == "Bob"
|
||||
@@ -59,7 +55,7 @@ def test_create_with_alias(
|
||||
|
||||
@pytest.mark.parametrize("model", [PydanticUserWithConfig, SQLModelUserWithConfig])
|
||||
def test_create_with_both_prefers_alias(
|
||||
model: Union[type[PydanticUserWithConfig], type[SQLModelUserWithConfig]],
|
||||
model: type[PydanticUserWithConfig] | type[SQLModelUserWithConfig],
|
||||
):
|
||||
user = model(full_name="IGNORED", fullName="Charlie")
|
||||
assert user.full_name == "Charlie" # alias should take precedence
|
||||
@@ -67,7 +63,7 @@ def test_create_with_both_prefers_alias(
|
||||
|
||||
@pytest.mark.parametrize("model", [PydanticUser, SQLModelUser])
|
||||
def test_dict_default_uses_field_names(
|
||||
model: Union[type[PydanticUser], type[SQLModelUser]],
|
||||
model: type[PydanticUser] | type[SQLModelUser],
|
||||
):
|
||||
user = model(fullName="Dana")
|
||||
data = user.model_dump()
|
||||
@@ -78,7 +74,7 @@ def test_dict_default_uses_field_names(
|
||||
|
||||
@pytest.mark.parametrize("model", [PydanticUser, SQLModelUser])
|
||||
def test_dict_by_alias_uses_aliases(
|
||||
model: Union[type[PydanticUser], type[SQLModelUser]],
|
||||
model: type[PydanticUser] | type[SQLModelUser],
|
||||
):
|
||||
user = model(fullName="Dana")
|
||||
data = user.model_dump(by_alias=True)
|
||||
@@ -89,7 +85,7 @@ def test_dict_by_alias_uses_aliases(
|
||||
|
||||
@pytest.mark.parametrize("model", [PydanticUser, SQLModelUser])
|
||||
def test_json_by_alias(
|
||||
model: Union[type[PydanticUser], type[SQLModelUser]],
|
||||
model: type[PydanticUser] | type[SQLModelUser],
|
||||
):
|
||||
user = model(fullName="Frank")
|
||||
json_data = user.model_dump_json(by_alias=True)
|
||||
@@ -107,7 +103,7 @@ class SQLModelUserV2(SQLModel):
|
||||
|
||||
@pytest.mark.parametrize("model", [PydanticUserV2, SQLModelUserV2])
|
||||
def test_create_with_validation_alias(
|
||||
model: Union[type[PydanticUserV2], type[SQLModelUserV2]],
|
||||
model: type[PydanticUserV2] | type[SQLModelUserV2],
|
||||
):
|
||||
user = model(firstName="John")
|
||||
assert user.first_name == "John"
|
||||
@@ -115,7 +111,7 @@ def test_create_with_validation_alias(
|
||||
|
||||
@pytest.mark.parametrize("model", [PydanticUserV2, SQLModelUserV2])
|
||||
def test_serialize_with_serialization_alias(
|
||||
model: Union[type[PydanticUserV2], type[SQLModelUserV2]],
|
||||
model: type[PydanticUserV2] | type[SQLModelUserV2],
|
||||
):
|
||||
user = model(firstName="Jane")
|
||||
data = user.model_dump(by_alias=True)
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import uuid
|
||||
from typing import Optional
|
||||
|
||||
from sqlmodel import Field, Session, SQLModel, create_engine, select
|
||||
|
||||
@@ -9,7 +8,7 @@ def test_annotated_optional_types(clear_sqlmodel) -> None:
|
||||
|
||||
class Hero(SQLModel, table=True):
|
||||
# Pydantic UUID4 is: Annotated[UUID, UuidVersion(4)]
|
||||
id: Optional[UUID4] = Field(default_factory=uuid.uuid4, primary_key=True)
|
||||
id: UUID4 | None = Field(default_factory=uuid.uuid4, primary_key=True)
|
||||
|
||||
engine = create_engine("sqlite:///:memory:")
|
||||
SQLModel.metadata.create_all(engine)
|
||||
|
||||
@@ -1,17 +1,15 @@
|
||||
from typing import Optional
|
||||
|
||||
from sqlalchemy import ForeignKey
|
||||
from sqlmodel import Field, SQLModel, create_engine
|
||||
|
||||
|
||||
def test_sa_column_args(clear_sqlmodel, caplog) -> None:
|
||||
class Team(SQLModel, table=True):
|
||||
id: Optional[int] = Field(default=None, primary_key=True)
|
||||
id: int | None = Field(default=None, primary_key=True)
|
||||
name: str
|
||||
|
||||
class Hero(SQLModel, table=True):
|
||||
id: Optional[int] = Field(default=None, primary_key=True)
|
||||
team_id: Optional[int] = Field(
|
||||
id: int | None = Field(default=None, primary_key=True)
|
||||
team_id: int | None = Field(
|
||||
default=None,
|
||||
sa_column_args=[ForeignKey("team.id")],
|
||||
)
|
||||
@@ -26,7 +24,7 @@ def test_sa_column_args(clear_sqlmodel, caplog) -> None:
|
||||
|
||||
def test_sa_column_kargs(clear_sqlmodel, caplog) -> None:
|
||||
class Item(SQLModel, table=True):
|
||||
id: Optional[int] = Field(
|
||||
id: int | None = Field(
|
||||
default=None,
|
||||
sa_column_kwargs={"primary_key": True},
|
||||
)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from typing import Annotated, Optional
|
||||
from typing import Annotated
|
||||
|
||||
import pytest
|
||||
from sqlalchemy import Column, Integer, String
|
||||
@@ -7,7 +7,7 @@ from sqlmodel import Field, SQLModel
|
||||
|
||||
def test_sa_column_takes_precedence() -> None:
|
||||
class Item(SQLModel, table=True):
|
||||
id: Optional[int] = Field(
|
||||
id: int | None = Field(
|
||||
default=None,
|
||||
sa_column=Column(String, primary_key=True, nullable=False),
|
||||
)
|
||||
@@ -19,7 +19,7 @@ def test_sa_column_takes_precedence() -> None:
|
||||
|
||||
def test_sa_column_with_annotated_metadata() -> None:
|
||||
class Item(SQLModel, table=True):
|
||||
id: Annotated[Optional[int], "meta"] = Field(
|
||||
id: Annotated[int | None, "meta"] = Field(
|
||||
default=None,
|
||||
sa_column=Column(String, primary_key=True, nullable=False),
|
||||
)
|
||||
@@ -32,7 +32,7 @@ def test_sa_column_no_sa_args() -> None:
|
||||
with pytest.raises(RuntimeError):
|
||||
|
||||
class Item(SQLModel, table=True):
|
||||
id: Optional[int] = Field(
|
||||
id: int | None = Field(
|
||||
default=None,
|
||||
sa_column_args=[Integer],
|
||||
sa_column=Column(Integer, primary_key=True),
|
||||
@@ -43,7 +43,7 @@ def test_sa_column_no_sa_kargs() -> None:
|
||||
with pytest.raises(RuntimeError):
|
||||
|
||||
class Item(SQLModel, table=True):
|
||||
id: Optional[int] = Field(
|
||||
id: int | None = Field(
|
||||
default=None,
|
||||
sa_column_kwargs={"primary_key": True},
|
||||
sa_column=Column(Integer, primary_key=True),
|
||||
@@ -54,7 +54,7 @@ def test_sa_column_no_type() -> None:
|
||||
with pytest.raises(RuntimeError):
|
||||
|
||||
class Item(SQLModel, table=True):
|
||||
id: Optional[int] = Field(
|
||||
id: int | None = Field(
|
||||
default=None,
|
||||
sa_type=Integer,
|
||||
sa_column=Column(Integer, primary_key=True),
|
||||
@@ -65,7 +65,7 @@ def test_sa_column_no_primary_key() -> None:
|
||||
with pytest.raises(RuntimeError):
|
||||
|
||||
class Item(SQLModel, table=True):
|
||||
id: Optional[int] = Field(
|
||||
id: int | None = Field(
|
||||
default=None,
|
||||
primary_key=True,
|
||||
sa_column=Column(Integer, primary_key=True),
|
||||
@@ -76,7 +76,7 @@ def test_sa_column_no_nullable() -> None:
|
||||
with pytest.raises(RuntimeError):
|
||||
|
||||
class Item(SQLModel, table=True):
|
||||
id: Optional[int] = Field(
|
||||
id: int | None = Field(
|
||||
default=None,
|
||||
nullable=True,
|
||||
sa_column=Column(Integer, primary_key=True),
|
||||
@@ -87,12 +87,12 @@ def test_sa_column_no_foreign_key() -> None:
|
||||
with pytest.raises(RuntimeError):
|
||||
|
||||
class Team(SQLModel, table=True):
|
||||
id: Optional[int] = Field(default=None, primary_key=True)
|
||||
id: int | None = Field(default=None, primary_key=True)
|
||||
name: str
|
||||
|
||||
class Hero(SQLModel, table=True):
|
||||
id: Optional[int] = Field(default=None, primary_key=True)
|
||||
team_id: Optional[int] = Field(
|
||||
id: int | None = Field(default=None, primary_key=True)
|
||||
team_id: int | None = Field(
|
||||
default=None,
|
||||
foreign_key="team.id",
|
||||
sa_column=Column(Integer, primary_key=True),
|
||||
@@ -103,7 +103,7 @@ def test_sa_column_no_unique() -> None:
|
||||
with pytest.raises(RuntimeError):
|
||||
|
||||
class Item(SQLModel, table=True):
|
||||
id: Optional[int] = Field(
|
||||
id: int | None = Field(
|
||||
default=None,
|
||||
unique=True,
|
||||
sa_column=Column(Integer, primary_key=True),
|
||||
@@ -114,7 +114,7 @@ def test_sa_column_no_index() -> None:
|
||||
with pytest.raises(RuntimeError):
|
||||
|
||||
class Item(SQLModel, table=True):
|
||||
id: Optional[int] = Field(
|
||||
id: int | None = Field(
|
||||
default=None,
|
||||
index=True,
|
||||
sa_column=Column(Integer, primary_key=True),
|
||||
@@ -125,7 +125,7 @@ def test_sa_column_no_ondelete() -> None:
|
||||
with pytest.raises(RuntimeError):
|
||||
|
||||
class Item(SQLModel, table=True):
|
||||
id: Optional[int] = Field(
|
||||
id: int | None = Field(
|
||||
default=None,
|
||||
sa_column=Column(Integer, primary_key=True),
|
||||
ondelete="CASCADE",
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
from typing import Optional
|
||||
|
||||
import pytest
|
||||
from sqlalchemy.orm import relationship
|
||||
from sqlmodel import Field, Relationship, SQLModel
|
||||
@@ -9,7 +7,7 @@ def test_sa_relationship_no_args() -> None:
|
||||
with pytest.raises(RuntimeError): # pragma: no cover
|
||||
|
||||
class Team(SQLModel, table=True):
|
||||
id: Optional[int] = Field(default=None, primary_key=True)
|
||||
id: int | None = Field(default=None, primary_key=True)
|
||||
name: str = Field(index=True)
|
||||
headquarters: str
|
||||
|
||||
@@ -20,20 +18,20 @@ def test_sa_relationship_no_args() -> None:
|
||||
)
|
||||
|
||||
class Hero(SQLModel, table=True):
|
||||
id: Optional[int] = Field(default=None, primary_key=True)
|
||||
id: int | None = Field(default=None, primary_key=True)
|
||||
name: str = Field(index=True)
|
||||
secret_name: str
|
||||
age: Optional[int] = Field(default=None, index=True)
|
||||
age: int | None = Field(default=None, index=True)
|
||||
|
||||
team_id: Optional[int] = Field(default=None, foreign_key="team.id")
|
||||
team: Optional[Team] = Relationship(back_populates="heroes")
|
||||
team_id: int | None = Field(default=None, foreign_key="team.id")
|
||||
team: Team | None = Relationship(back_populates="heroes")
|
||||
|
||||
|
||||
def test_sa_relationship_no_kwargs() -> None:
|
||||
with pytest.raises(RuntimeError): # pragma: no cover
|
||||
|
||||
class Team(SQLModel, table=True):
|
||||
id: Optional[int] = Field(default=None, primary_key=True)
|
||||
id: int | None = Field(default=None, primary_key=True)
|
||||
name: str = Field(index=True)
|
||||
headquarters: str
|
||||
|
||||
@@ -44,10 +42,10 @@ def test_sa_relationship_no_kwargs() -> None:
|
||||
)
|
||||
|
||||
class Hero(SQLModel, table=True):
|
||||
id: Optional[int] = Field(default=None, primary_key=True)
|
||||
id: int | None = Field(default=None, primary_key=True)
|
||||
name: str = Field(index=True)
|
||||
secret_name: str
|
||||
age: Optional[int] = Field(default=None, index=True)
|
||||
age: int | None = Field(default=None, index=True)
|
||||
|
||||
team_id: Optional[int] = Field(default=None, foreign_key="team.id")
|
||||
team: Optional[Team] = Relationship(back_populates="heroes")
|
||||
team_id: int | None = Field(default=None, foreign_key="team.id")
|
||||
team: Team | None = Relationship(back_populates="heroes")
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Annotated, Optional
|
||||
from typing import Annotated
|
||||
|
||||
from sqlmodel import Field, Session, SQLModel, create_engine, select
|
||||
|
||||
|
||||
def test_model_with_future_annotations(clear_sqlmodel):
|
||||
class Hero(SQLModel, table=True):
|
||||
id: Annotated[Optional[int], Field(primary_key=True)] = None
|
||||
id: Annotated[int | None, Field(primary_key=True)] = None
|
||||
name: str
|
||||
secret_name: str
|
||||
age: Optional[int] = None
|
||||
age: int | None = None
|
||||
|
||||
hero = Hero(name="Deadpond", secret_name="Dive Wilson", age=25)
|
||||
|
||||
@@ -35,13 +35,13 @@ def test_model_with_future_annotations(clear_sqlmodel):
|
||||
|
||||
def test_model_with_string_annotations(clear_sqlmodel):
|
||||
class Team(SQLModel, table=True):
|
||||
id: Annotated[Optional[int], Field(primary_key=True)] = None
|
||||
id: Annotated[int | None, Field(primary_key=True)] = None
|
||||
name: str
|
||||
|
||||
class Player(SQLModel, table=True):
|
||||
id: Annotated[Optional[int], Field(primary_key=True)] = None
|
||||
id: Annotated[int | None, Field(primary_key=True)] = None
|
||||
name: str
|
||||
team_id: Annotated[Optional[int], Field(foreign_key="team.id")] = None
|
||||
team_id: Annotated[int | None, Field(foreign_key="team.id")] = None
|
||||
|
||||
engine = create_engine("sqlite://")
|
||||
SQLModel.metadata.create_all(engine)
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
from typing import Optional
|
||||
|
||||
import pytest
|
||||
from pydantic import ValidationError
|
||||
from sqlmodel import Field, Session, SQLModel, create_engine, select
|
||||
@@ -7,9 +5,9 @@ from sqlmodel import Field, Session, SQLModel, create_engine, select
|
||||
|
||||
def test_allow_instantiation_without_arguments(clear_sqlmodel):
|
||||
class Item(SQLModel, table=True):
|
||||
id: Optional[int] = Field(default=None, primary_key=True)
|
||||
id: int | None = Field(default=None, primary_key=True)
|
||||
name: str
|
||||
description: Optional[str] = None
|
||||
description: str | None = None
|
||||
|
||||
engine = create_engine("sqlite:///:memory:")
|
||||
SQLModel.metadata.create_all(engine)
|
||||
@@ -27,9 +25,9 @@ def test_allow_instantiation_without_arguments(clear_sqlmodel):
|
||||
|
||||
def test_not_allow_instantiation_without_arguments_if_not_table():
|
||||
class Item(SQLModel):
|
||||
id: Optional[int] = Field(default=None, primary_key=True)
|
||||
id: int | None = Field(default=None, primary_key=True)
|
||||
name: str
|
||||
description: Optional[str] = None
|
||||
description: str | None = None
|
||||
|
||||
with pytest.raises(ValidationError):
|
||||
Item()
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from typing import Annotated, Optional
|
||||
from typing import Annotated
|
||||
|
||||
import pytest
|
||||
from sqlalchemy.exc import IntegrityError
|
||||
@@ -8,10 +8,10 @@ from sqlmodel import Field, Relationship, Session, SQLModel, create_engine, sele
|
||||
|
||||
def test_should_allow_duplicate_row_if_unique_constraint_is_not_passed(clear_sqlmodel):
|
||||
class Hero(SQLModel, table=True):
|
||||
id: Optional[int] = Field(default=None, primary_key=True)
|
||||
id: int | None = Field(default=None, primary_key=True)
|
||||
name: str
|
||||
secret_name: str
|
||||
age: Optional[int] = None
|
||||
age: int | None = None
|
||||
|
||||
hero_1 = Hero(name="Deadpond", secret_name="Dive Wilson")
|
||||
hero_2 = Hero(name="Deadpond", secret_name="Dive Wilson")
|
||||
@@ -38,10 +38,10 @@ def test_should_allow_duplicate_row_if_unique_constraint_is_not_passed(clear_sql
|
||||
|
||||
def test_should_allow_duplicate_row_if_unique_constraint_is_false(clear_sqlmodel):
|
||||
class Hero(SQLModel, table=True):
|
||||
id: Optional[int] = Field(default=None, primary_key=True)
|
||||
id: int | None = Field(default=None, primary_key=True)
|
||||
name: str
|
||||
secret_name: str = Field(unique=False)
|
||||
age: Optional[int] = None
|
||||
age: int | None = None
|
||||
|
||||
hero_1 = Hero(name="Deadpond", secret_name="Dive Wilson")
|
||||
hero_2 = Hero(name="Deadpond", secret_name="Dive Wilson")
|
||||
@@ -70,10 +70,10 @@ def test_should_raise_exception_when_try_to_duplicate_row_if_unique_constraint_i
|
||||
clear_sqlmodel,
|
||||
):
|
||||
class Hero(SQLModel, table=True):
|
||||
id: Optional[int] = Field(default=None, primary_key=True)
|
||||
id: int | None = Field(default=None, primary_key=True)
|
||||
name: str
|
||||
secret_name: str = Field(unique=True)
|
||||
age: Optional[int] = None
|
||||
age: int | None = None
|
||||
|
||||
hero_1 = Hero(name="Deadpond", secret_name="Dive Wilson")
|
||||
hero_2 = Hero(name="Deadpond", secret_name="Dive Wilson")
|
||||
@@ -97,17 +97,17 @@ def test_sa_relationship_property(clear_sqlmodel):
|
||||
"""Test https://github.com/tiangolo/sqlmodel/issues/315#issuecomment-1272122306"""
|
||||
|
||||
class Team(SQLModel, table=True):
|
||||
id: Optional[int] = Field(default=None, primary_key=True)
|
||||
id: int | None = Field(default=None, primary_key=True)
|
||||
name: str = Field(unique=True)
|
||||
heroes: list["Hero"] = Relationship( # noqa: F821
|
||||
sa_relationship=RelationshipProperty("Hero", back_populates="team")
|
||||
)
|
||||
|
||||
class Hero(SQLModel, table=True):
|
||||
id: Optional[int] = Field(default=None, primary_key=True)
|
||||
id: int | None = Field(default=None, primary_key=True)
|
||||
name: str = Field(unique=True)
|
||||
team_id: Optional[int] = Field(default=None, foreign_key="team.id")
|
||||
team: Optional[Team] = Relationship(
|
||||
team_id: int | None = Field(default=None, foreign_key="team.id")
|
||||
team: Team | None = Relationship(
|
||||
sa_relationship=RelationshipProperty("Team", back_populates="heroes")
|
||||
)
|
||||
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
from typing import Optional
|
||||
|
||||
import pytest
|
||||
from pydantic import BaseModel
|
||||
from sqlmodel import Field, SQLModel
|
||||
@@ -18,5 +16,5 @@ def test_missing_sql_type():
|
||||
with pytest.raises(ValueError):
|
||||
|
||||
class Item(SQLModel, table=True):
|
||||
id: Optional[int] = Field(default=None, primary_key=True)
|
||||
id: int | None = Field(default=None, primary_key=True)
|
||||
item: CustomType
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
from typing import Optional
|
||||
|
||||
import pytest
|
||||
from sqlalchemy.exc import IntegrityError
|
||||
from sqlmodel import Field, Session, SQLModel, create_engine
|
||||
@@ -7,41 +5,41 @@ from sqlmodel import Field, Session, SQLModel, create_engine
|
||||
|
||||
def test_nullable_fields(clear_sqlmodel, caplog):
|
||||
class Hero(SQLModel, table=True):
|
||||
primary_key: Optional[int] = Field(
|
||||
primary_key: int | None = Field(
|
||||
default=None,
|
||||
primary_key=True,
|
||||
)
|
||||
required_value: str
|
||||
optional_default_ellipsis: Optional[str] = Field(default=...)
|
||||
optional_default_none: Optional[str] = Field(default=None)
|
||||
optional_non_nullable: Optional[str] = Field(
|
||||
optional_default_ellipsis: str | None = Field(default=...)
|
||||
optional_default_none: str | None = Field(default=None)
|
||||
optional_non_nullable: str | None = Field(
|
||||
nullable=False,
|
||||
)
|
||||
optional_nullable: Optional[str] = Field(
|
||||
optional_nullable: str | None = Field(
|
||||
nullable=True,
|
||||
)
|
||||
optional_default_ellipses_non_nullable: Optional[str] = Field(
|
||||
optional_default_ellipses_non_nullable: str | None = Field(
|
||||
default=...,
|
||||
nullable=False,
|
||||
)
|
||||
optional_default_ellipses_nullable: Optional[str] = Field(
|
||||
optional_default_ellipses_nullable: str | None = Field(
|
||||
default=...,
|
||||
nullable=True,
|
||||
)
|
||||
optional_default_none_non_nullable: Optional[str] = Field(
|
||||
optional_default_none_non_nullable: str | None = Field(
|
||||
default=None,
|
||||
nullable=False,
|
||||
)
|
||||
optional_default_none_nullable: Optional[str] = Field(
|
||||
optional_default_none_nullable: str | None = Field(
|
||||
default=None,
|
||||
nullable=True,
|
||||
)
|
||||
default_ellipses_non_nullable: str = Field(default=..., nullable=False)
|
||||
optional_default_str: Optional[str] = "default"
|
||||
optional_default_str_non_nullable: Optional[str] = Field(
|
||||
optional_default_str: str | None = "default"
|
||||
optional_default_str_non_nullable: str | None = Field(
|
||||
default="default", nullable=False
|
||||
)
|
||||
optional_default_str_nullable: Optional[str] = Field(
|
||||
optional_default_str_nullable: str | None = Field(
|
||||
default="default", nullable=True
|
||||
)
|
||||
str_default_str: str = "default"
|
||||
@@ -82,12 +80,12 @@ def test_nullable_fields(clear_sqlmodel, caplog):
|
||||
# Test for regression in https://github.com/tiangolo/sqlmodel/issues/420
|
||||
def test_non_nullable_optional_field_with_no_default_set(clear_sqlmodel, caplog):
|
||||
class Hero(SQLModel, table=True):
|
||||
primary_key: Optional[int] = Field(
|
||||
primary_key: int | None = Field(
|
||||
default=None,
|
||||
primary_key=True,
|
||||
)
|
||||
|
||||
optional_non_nullable_no_default: Optional[str] = Field(nullable=False)
|
||||
optional_non_nullable_no_default: str | None = Field(nullable=False)
|
||||
|
||||
engine = create_engine("sqlite://", echo=True)
|
||||
SQLModel.metadata.create_all(engine)
|
||||
@@ -110,7 +108,7 @@ def test_non_nullable_optional_field_with_no_default_set(clear_sqlmodel, caplog)
|
||||
def test_nullable_primary_key(clear_sqlmodel, caplog):
|
||||
# Probably the weirdest corner case, it shouldn't happen anywhere, but let's test it
|
||||
class Hero(SQLModel, table=True):
|
||||
nullable_integer_primary_key: Optional[int] = Field(
|
||||
nullable_integer_primary_key: int | None = Field(
|
||||
default=None,
|
||||
primary_key=True,
|
||||
nullable=True,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from typing import Any, Union
|
||||
from typing import Any
|
||||
|
||||
import pytest
|
||||
from sqlmodel import Field, Relationship, SQLModel
|
||||
@@ -8,17 +8,17 @@ def test_ondelete_requires_nullable(clear_sqlmodel: Any) -> None:
|
||||
with pytest.raises(RuntimeError) as exc:
|
||||
|
||||
class Team(SQLModel, table=True):
|
||||
id: Union[int, None] = Field(default=None, primary_key=True)
|
||||
id: int | None = Field(default=None, primary_key=True)
|
||||
|
||||
heroes: list["Hero"] = Relationship(
|
||||
back_populates="team", passive_deletes="all"
|
||||
)
|
||||
|
||||
class Hero(SQLModel, table=True):
|
||||
id: Union[int, None] = Field(default=None, primary_key=True)
|
||||
id: int | None = Field(default=None, primary_key=True)
|
||||
name: str = Field(index=True)
|
||||
secret_name: str
|
||||
age: Union[int, None] = Field(default=None, index=True)
|
||||
age: int | None = Field(default=None, index=True)
|
||||
|
||||
team_id: int = Field(foreign_key="team.id", ondelete="SET NULL")
|
||||
team: Team = Relationship(back_populates="heroes")
|
||||
@@ -30,7 +30,7 @@ def test_ondelete_requires_foreign_key(clear_sqlmodel: Any) -> None:
|
||||
with pytest.raises(RuntimeError) as exc:
|
||||
|
||||
class Team(SQLModel, table=True):
|
||||
id: Union[int, None] = Field(default=None, primary_key=True)
|
||||
id: int | None = Field(default=None, primary_key=True)
|
||||
|
||||
age: int = Field(ondelete="CASCADE")
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from decimal import Decimal
|
||||
from typing import Literal, Optional, Union
|
||||
from typing import Literal
|
||||
|
||||
import pytest
|
||||
from pydantic import ValidationError
|
||||
@@ -38,7 +38,7 @@ def test_discriminator():
|
||||
scales: bool
|
||||
|
||||
class Model(SQLModel):
|
||||
pet: Union[Cat, Dog, Lizard] = Field(..., discriminator="pet_type")
|
||||
pet: Cat | Dog | Lizard = Field(..., discriminator="pet_type")
|
||||
n: int
|
||||
|
||||
Model(pet={"pet_type": "dog", "barks": 3.14}, n=1) # type: ignore[arg-type]
|
||||
@@ -49,7 +49,7 @@ def test_discriminator():
|
||||
|
||||
def test_repr():
|
||||
class Model(SQLModel):
|
||||
id: Optional[int] = Field(primary_key=True)
|
||||
id: int | None = Field(primary_key=True)
|
||||
foo: str = Field(repr=False)
|
||||
|
||||
instance = Model(id=123, foo="bar")
|
||||
|
||||
@@ -1,15 +1,13 @@
|
||||
from typing import Optional
|
||||
|
||||
import pytest
|
||||
from sqlmodel import Field, Session, SQLModel, create_engine
|
||||
|
||||
|
||||
def test_query(clear_sqlmodel):
|
||||
class Hero(SQLModel, table=True):
|
||||
id: Optional[int] = Field(default=None, primary_key=True)
|
||||
id: int | None = Field(default=None, primary_key=True)
|
||||
name: str
|
||||
secret_name: str
|
||||
age: Optional[int] = None
|
||||
age: int | None = None
|
||||
|
||||
hero_1 = Hero(name="Deadpond", secret_name="Dive Wilson")
|
||||
|
||||
|
||||
@@ -1,16 +1,14 @@
|
||||
from typing import Optional
|
||||
|
||||
from sqlmodel import Field, Session, SQLModel, create_engine, select
|
||||
from sqlmodel.pool import StaticPool
|
||||
|
||||
|
||||
def test_fields() -> None:
|
||||
class Hero(SQLModel, table=True):
|
||||
id: Optional[int] = Field(default=None, primary_key=True)
|
||||
id: int | None = Field(default=None, primary_key=True)
|
||||
name: str
|
||||
secret_name: str
|
||||
age: Optional[int] = None
|
||||
food: Optional[str] = None
|
||||
age: int | None = None
|
||||
food: str | None = None
|
||||
|
||||
engine = create_engine(
|
||||
"sqlite://", connect_args={"check_same_thread": False}, poolclass=StaticPool
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from typing import Any, Optional, Union
|
||||
from typing import Any
|
||||
|
||||
import pytest
|
||||
from sqlmodel import Field, SQLModel
|
||||
@@ -8,7 +8,7 @@ def test_type_list_breaks() -> None:
|
||||
with pytest.raises(ValueError):
|
||||
|
||||
class Hero(SQLModel, table=True):
|
||||
id: Optional[int] = Field(default=None, primary_key=True)
|
||||
id: int | None = Field(default=None, primary_key=True)
|
||||
tags: list[str]
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ def test_type_dict_breaks() -> None:
|
||||
with pytest.raises(ValueError):
|
||||
|
||||
class Hero(SQLModel, table=True):
|
||||
id: Optional[int] = Field(default=None, primary_key=True)
|
||||
id: int | None = Field(default=None, primary_key=True)
|
||||
tags: dict[str, Any]
|
||||
|
||||
|
||||
@@ -24,5 +24,5 @@ def test_type_union_breaks() -> None:
|
||||
with pytest.raises(ValueError):
|
||||
|
||||
class Hero(SQLModel, table=True):
|
||||
id: Optional[int] = Field(default=None, primary_key=True)
|
||||
tags: Union[int, str]
|
||||
id: int | None = Field(default=None, primary_key=True)
|
||||
tags: int | str
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import importlib
|
||||
from types import ModuleType
|
||||
from typing import Any, Union
|
||||
from typing import Any
|
||||
|
||||
import pytest
|
||||
from sqlmodel import create_engine
|
||||
@@ -8,7 +8,7 @@ from sqlmodel import create_engine
|
||||
from tests.conftest import PrintMock, needs_py310
|
||||
|
||||
|
||||
def check_calls(calls: list[list[Union[str, dict[str, Any]]]]) -> None:
|
||||
def check_calls(calls: list[list[str | dict[str, Any]]]) -> None:
|
||||
assert calls[0] == ["Before interacting with the database"]
|
||||
assert calls[1] == [
|
||||
"Hero 1:",
|
||||
@@ -138,8 +138,6 @@ def check_calls(calls: list[list[Union[str, dict[str, Any]]]]) -> None:
|
||||
@pytest.fixture(
|
||||
name="module",
|
||||
params=[
|
||||
"tutorial001_py39",
|
||||
"tutorial002_py39",
|
||||
pytest.param("tutorial001_py310", marks=needs_py310),
|
||||
pytest.param("tutorial002_py310", marks=needs_py310),
|
||||
],
|
||||
|
||||
@@ -34,7 +34,6 @@ class Modules:
|
||||
@pytest.fixture(
|
||||
name="modules",
|
||||
params=[
|
||||
pytest.param("tutorial001_py39"),
|
||||
pytest.param("tutorial001_py310", marks=needs_py310),
|
||||
],
|
||||
)
|
||||
|
||||
@@ -34,7 +34,6 @@ class Modules:
|
||||
@pytest.fixture(
|
||||
name="modules",
|
||||
params=[
|
||||
pytest.param("tutorial002_py39"),
|
||||
pytest.param("tutorial002_py310", marks=needs_py310),
|
||||
],
|
||||
)
|
||||
|
||||
@@ -12,7 +12,6 @@ from tests.conftest import needs_py310
|
||||
@pytest.fixture(
|
||||
name="module",
|
||||
params=[
|
||||
"tutorial001_py39",
|
||||
pytest.param("tutorial001_py310", marks=needs_py310),
|
||||
],
|
||||
)
|
||||
|
||||
@@ -63,7 +63,6 @@ expected_calls = [
|
||||
@pytest.fixture(
|
||||
name="module",
|
||||
params=[
|
||||
"tutorial001_py39",
|
||||
pytest.param("tutorial001_py310", marks=needs_py310),
|
||||
],
|
||||
)
|
||||
|
||||
@@ -43,7 +43,6 @@ expected_calls = [
|
||||
@pytest.fixture(
|
||||
name="module",
|
||||
params=[
|
||||
"tutorial001_py39",
|
||||
pytest.param("tutorial001_py310", marks=needs_py310),
|
||||
],
|
||||
)
|
||||
|
||||
@@ -77,7 +77,6 @@ def get_module(request: pytest.FixtureRequest) -> ModuleType:
|
||||
@pytest.mark.parametrize(
|
||||
"module",
|
||||
[
|
||||
"tutorial001_py39",
|
||||
pytest.param("tutorial001_py310", marks=needs_py310),
|
||||
],
|
||||
indirect=True,
|
||||
@@ -90,7 +89,6 @@ def test_tutorial001(print_mock: PrintMock, module: ModuleType):
|
||||
@pytest.mark.parametrize(
|
||||
"module",
|
||||
[
|
||||
"tutorial002_py39",
|
||||
pytest.param("tutorial002_py310", marks=needs_py310),
|
||||
],
|
||||
indirect=True,
|
||||
|
||||
@@ -79,7 +79,6 @@ expected_calls = [
|
||||
@pytest.fixture(
|
||||
name="module",
|
||||
params=[
|
||||
"tutorial003_py39",
|
||||
pytest.param("tutorial003_py310", marks=needs_py310),
|
||||
],
|
||||
)
|
||||
|
||||
@@ -53,7 +53,6 @@ expected_calls = [
|
||||
@pytest.fixture(
|
||||
name="module",
|
||||
params=[
|
||||
"tutorial004_py39",
|
||||
pytest.param("tutorial004_py310", marks=needs_py310),
|
||||
],
|
||||
)
|
||||
|
||||
@@ -55,7 +55,6 @@ expected_calls = [
|
||||
@pytest.fixture(
|
||||
name="module",
|
||||
params=[
|
||||
"tutorial005_py39",
|
||||
pytest.param("tutorial005_py310", marks=needs_py310),
|
||||
],
|
||||
)
|
||||
|
||||
@@ -53,7 +53,6 @@ expected_calls = [
|
||||
@pytest.fixture(
|
||||
name="module",
|
||||
params=[
|
||||
"tutorial001_py39",
|
||||
pytest.param("tutorial001_py310", marks=needs_py310),
|
||||
],
|
||||
)
|
||||
|
||||
@@ -8,7 +8,6 @@ from ...conftest import coverage_run, needs_py310
|
||||
@pytest.mark.parametrize(
|
||||
"module_name",
|
||||
[
|
||||
"tutorial001_py39",
|
||||
pytest.param("tutorial001_py310", marks=needs_py310),
|
||||
],
|
||||
)
|
||||
|
||||
@@ -12,7 +12,6 @@ from ...conftest import needs_py310
|
||||
@pytest.fixture(
|
||||
name="module",
|
||||
params=[
|
||||
"tutorial002_py39",
|
||||
pytest.param("tutorial002_py310", marks=needs_py310),
|
||||
],
|
||||
)
|
||||
|
||||
@@ -12,7 +12,6 @@ from ...conftest import needs_py310
|
||||
@pytest.fixture(
|
||||
name="module",
|
||||
params=[
|
||||
"tutorial003_py39",
|
||||
pytest.param("tutorial003_py310", marks=needs_py310),
|
||||
],
|
||||
)
|
||||
|
||||
@@ -71,7 +71,6 @@ def get_module(request: pytest.FixtureRequest) -> ModuleType:
|
||||
@pytest.mark.parametrize(
|
||||
"module",
|
||||
[
|
||||
"tutorial001_py39",
|
||||
pytest.param("tutorial001_py310", marks=needs_py310),
|
||||
],
|
||||
indirect=True,
|
||||
@@ -84,7 +83,6 @@ def test_tutorial001(print_mock: PrintMock, module: ModuleType):
|
||||
@pytest.mark.parametrize(
|
||||
"module",
|
||||
[
|
||||
"tutorial002_py39",
|
||||
pytest.param("tutorial002_py310", marks=needs_py310),
|
||||
],
|
||||
indirect=True,
|
||||
|
||||
@@ -17,7 +17,6 @@ class Modules:
|
||||
@pytest.fixture(
|
||||
name="modules_path",
|
||||
params=[
|
||||
pytest.param("tutorial001_py39"),
|
||||
pytest.param("tutorial001_py310", marks=needs_py310),
|
||||
],
|
||||
)
|
||||
|
||||
@@ -17,7 +17,6 @@ class Modules:
|
||||
@pytest.fixture(
|
||||
name="modules_path",
|
||||
params=[
|
||||
pytest.param("tutorial001_py39"),
|
||||
pytest.param("tutorial001_py310", marks=needs_py310),
|
||||
],
|
||||
)
|
||||
|
||||
@@ -17,7 +17,6 @@ class Modules:
|
||||
@pytest.fixture(
|
||||
name="modules_path",
|
||||
params=[
|
||||
pytest.param("tutorial001_py39"),
|
||||
pytest.param("tutorial001_py310", marks=needs_py310),
|
||||
],
|
||||
)
|
||||
|
||||
@@ -17,7 +17,6 @@ class Modules:
|
||||
@pytest.fixture(
|
||||
name="modules_path",
|
||||
params=[
|
||||
pytest.param("tutorial001_py39"),
|
||||
pytest.param("tutorial001_py310", marks=needs_py310),
|
||||
],
|
||||
)
|
||||
|
||||
@@ -3,11 +3,11 @@ import importlib
|
||||
import pytest
|
||||
from sqlmodel import Session
|
||||
|
||||
from docs_src.tutorial.fastapi.app_testing.tutorial001_py39 import main as app_mod
|
||||
from docs_src.tutorial.fastapi.app_testing.tutorial001_py39 import (
|
||||
from docs_src.tutorial.fastapi.app_testing.tutorial001_py310 import main as app_mod
|
||||
from docs_src.tutorial.fastapi.app_testing.tutorial001_py310 import (
|
||||
test_main_005 as test_mod,
|
||||
)
|
||||
from docs_src.tutorial.fastapi.app_testing.tutorial001_py39.test_main_005 import (
|
||||
from docs_src.tutorial.fastapi.app_testing.tutorial001_py310.test_main_005 import (
|
||||
session_fixture,
|
||||
)
|
||||
|
||||
|
||||
@@ -4,11 +4,11 @@ import pytest
|
||||
from fastapi.testclient import TestClient
|
||||
from sqlmodel import Session
|
||||
|
||||
from docs_src.tutorial.fastapi.app_testing.tutorial001_py39 import main as app_mod
|
||||
from docs_src.tutorial.fastapi.app_testing.tutorial001_py39 import (
|
||||
from docs_src.tutorial.fastapi.app_testing.tutorial001_py310 import main as app_mod
|
||||
from docs_src.tutorial.fastapi.app_testing.tutorial001_py310 import (
|
||||
test_main_006 as test_mod,
|
||||
)
|
||||
from docs_src.tutorial.fastapi.app_testing.tutorial001_py39.test_main_006 import (
|
||||
from docs_src.tutorial.fastapi.app_testing.tutorial001_py310.test_main_006 import (
|
||||
client_fixture,
|
||||
session_fixture,
|
||||
)
|
||||
|
||||
@@ -11,7 +11,6 @@ from ....conftest import needs_py310
|
||||
@pytest.fixture(
|
||||
name="module",
|
||||
params=[
|
||||
pytest.param("tutorial001_py39"),
|
||||
pytest.param("tutorial001_py310", marks=needs_py310),
|
||||
],
|
||||
)
|
||||
|
||||
@@ -13,7 +13,6 @@ from tests.conftest import needs_py310
|
||||
@pytest.fixture(
|
||||
name="module",
|
||||
params=[
|
||||
pytest.param("tutorial001_py39"),
|
||||
pytest.param("tutorial001_py310", marks=needs_py310),
|
||||
],
|
||||
)
|
||||
|
||||
@@ -13,7 +13,6 @@ from tests.conftest import needs_py310
|
||||
@pytest.fixture(
|
||||
name="module",
|
||||
params=[
|
||||
pytest.param("tutorial001_py39"),
|
||||
pytest.param("tutorial001_py310", marks=needs_py310),
|
||||
],
|
||||
)
|
||||
|
||||
@@ -15,7 +15,6 @@ from tests.conftest import needs_py310
|
||||
@pytest.fixture(
|
||||
name="module",
|
||||
params=[
|
||||
pytest.param("tutorial001_py39"),
|
||||
pytest.param("tutorial001_py310", marks=needs_py310),
|
||||
],
|
||||
)
|
||||
|
||||
@@ -15,7 +15,6 @@ from tests.conftest import needs_py310
|
||||
@pytest.fixture(
|
||||
name="module",
|
||||
params=[
|
||||
pytest.param("tutorial002_py39"),
|
||||
pytest.param("tutorial002_py310", marks=needs_py310),
|
||||
],
|
||||
)
|
||||
|
||||
@@ -13,7 +13,6 @@ from tests.conftest import needs_py310
|
||||
@pytest.fixture(
|
||||
name="module",
|
||||
params=[
|
||||
pytest.param("tutorial001_py39"),
|
||||
pytest.param("tutorial001_py310", marks=needs_py310),
|
||||
],
|
||||
)
|
||||
|
||||
@@ -13,7 +13,6 @@ from tests.conftest import needs_py310
|
||||
@pytest.fixture(
|
||||
name="module",
|
||||
params=[
|
||||
pytest.param("tutorial001_py39"),
|
||||
pytest.param("tutorial001_py310", marks=needs_py310),
|
||||
],
|
||||
)
|
||||
|
||||
@@ -13,7 +13,6 @@ from tests.conftest import needs_py310
|
||||
@pytest.fixture(
|
||||
name="module",
|
||||
params=[
|
||||
pytest.param("tutorial001_py39"),
|
||||
pytest.param("tutorial001_py310", marks=needs_py310),
|
||||
],
|
||||
)
|
||||
|
||||
@@ -13,7 +13,6 @@ from tests.conftest import needs_py310
|
||||
@pytest.fixture(
|
||||
name="module",
|
||||
params=[
|
||||
pytest.param("tutorial001_py39"),
|
||||
pytest.param("tutorial001_py310", marks=needs_py310),
|
||||
],
|
||||
)
|
||||
|
||||
@@ -13,7 +13,6 @@ from tests.conftest import needs_py310
|
||||
@pytest.fixture(
|
||||
name="module",
|
||||
params=[
|
||||
pytest.param("tutorial001_py39"),
|
||||
pytest.param("tutorial001_py310", marks=needs_py310),
|
||||
],
|
||||
)
|
||||
|
||||
@@ -13,7 +13,6 @@ from tests.conftest import needs_py310
|
||||
@pytest.fixture(
|
||||
name="module",
|
||||
params=[
|
||||
pytest.param("tutorial001_py39"),
|
||||
pytest.param("tutorial001_py310", marks=needs_py310),
|
||||
],
|
||||
)
|
||||
|
||||
@@ -13,7 +13,6 @@ from tests.conftest import needs_py310
|
||||
@pytest.fixture(
|
||||
name="module",
|
||||
params=[
|
||||
pytest.param("tutorial001_py39"),
|
||||
pytest.param("tutorial001_py310", marks=needs_py310),
|
||||
],
|
||||
)
|
||||
|
||||
@@ -13,7 +13,6 @@ from tests.conftest import needs_py310
|
||||
@pytest.fixture(
|
||||
name="module",
|
||||
params=[
|
||||
pytest.param("tutorial002_py39"),
|
||||
pytest.param("tutorial002_py310", marks=needs_py310),
|
||||
],
|
||||
)
|
||||
|
||||
@@ -12,7 +12,6 @@ from ...conftest import PrintMock, needs_py310
|
||||
@pytest.fixture(
|
||||
name="mod",
|
||||
params=[
|
||||
pytest.param("tutorial001_py39"),
|
||||
pytest.param("tutorial001_py310", marks=needs_py310),
|
||||
],
|
||||
)
|
||||
|
||||
@@ -12,7 +12,6 @@ from ...conftest import PrintMock, needs_py310
|
||||
@pytest.fixture(
|
||||
name="mod",
|
||||
params=[
|
||||
pytest.param("tutorial002_py39"),
|
||||
pytest.param("tutorial002_py310", marks=needs_py310),
|
||||
],
|
||||
)
|
||||
|
||||
@@ -10,7 +10,6 @@ from ...conftest import needs_py310
|
||||
@pytest.fixture(
|
||||
name="mod",
|
||||
params=[
|
||||
pytest.param("tutorial001_py39"),
|
||||
pytest.param("tutorial001_py310", marks=needs_py310),
|
||||
],
|
||||
)
|
||||
|
||||
@@ -10,7 +10,6 @@ from ...conftest import needs_py310
|
||||
@pytest.fixture(
|
||||
name="mod",
|
||||
params=[
|
||||
pytest.param("tutorial002_py39"),
|
||||
pytest.param("tutorial002_py310", marks=needs_py310),
|
||||
],
|
||||
)
|
||||
|
||||
@@ -10,7 +10,6 @@ from ...conftest import needs_py310
|
||||
@pytest.fixture(
|
||||
name="mod",
|
||||
params=[
|
||||
pytest.param("tutorial003_py39"),
|
||||
pytest.param("tutorial003_py310", marks=needs_py310),
|
||||
],
|
||||
)
|
||||
|
||||
@@ -10,7 +10,6 @@ from ...conftest import PrintMock, needs_py310
|
||||
@pytest.fixture(
|
||||
name="mod",
|
||||
params=[
|
||||
pytest.param("tutorial001_py39"),
|
||||
pytest.param("tutorial001_py310", marks=needs_py310),
|
||||
],
|
||||
)
|
||||
|
||||
@@ -10,7 +10,6 @@ from ...conftest import PrintMock, needs_py310
|
||||
@pytest.fixture(
|
||||
name="mod",
|
||||
params=[
|
||||
pytest.param("tutorial002_py39"),
|
||||
pytest.param("tutorial002_py310", marks=needs_py310),
|
||||
],
|
||||
)
|
||||
|
||||
@@ -10,7 +10,6 @@ from ...conftest import PrintMock, needs_py310
|
||||
@pytest.fixture(
|
||||
name="mod",
|
||||
params=[
|
||||
pytest.param("tutorial003_py39"),
|
||||
pytest.param("tutorial003_py310", marks=needs_py310),
|
||||
],
|
||||
)
|
||||
|
||||
@@ -10,7 +10,6 @@ from ...conftest import PrintMock, needs_py310
|
||||
@pytest.fixture(
|
||||
name="mod",
|
||||
params=[
|
||||
pytest.param("tutorial004_py39"),
|
||||
pytest.param("tutorial004_py310", marks=needs_py310),
|
||||
],
|
||||
)
|
||||
|
||||
@@ -10,7 +10,6 @@ from ...conftest import PrintMock, needs_py310
|
||||
@pytest.fixture(
|
||||
name="mod",
|
||||
params=[
|
||||
pytest.param("tutorial001_py39"),
|
||||
pytest.param("tutorial001_py310", marks=needs_py310),
|
||||
],
|
||||
)
|
||||
|
||||
@@ -10,7 +10,6 @@ from ...conftest import PrintMock, needs_py310
|
||||
@pytest.fixture(
|
||||
name="mod",
|
||||
params=[
|
||||
pytest.param("tutorial002_py39"),
|
||||
pytest.param("tutorial002_py310", marks=needs_py310),
|
||||
],
|
||||
)
|
||||
|
||||
@@ -10,7 +10,6 @@ from ...conftest import PrintMock, needs_py310
|
||||
@pytest.fixture(
|
||||
name="mod",
|
||||
params=[
|
||||
pytest.param("tutorial003_py39"),
|
||||
pytest.param("tutorial003_py310", marks=needs_py310),
|
||||
],
|
||||
)
|
||||
|
||||
@@ -10,7 +10,6 @@ from ...conftest import PrintMock, needs_py310
|
||||
@pytest.fixture(
|
||||
name="mod",
|
||||
params=[
|
||||
pytest.param("tutorial001_py39"),
|
||||
pytest.param("tutorial001_py310", marks=needs_py310),
|
||||
],
|
||||
)
|
||||
|
||||
@@ -10,7 +10,6 @@ from ...conftest import PrintMock, needs_py310
|
||||
@pytest.fixture(
|
||||
name="mod",
|
||||
params=[
|
||||
pytest.param("tutorial002_py39"),
|
||||
pytest.param("tutorial002_py310", marks=needs_py310),
|
||||
],
|
||||
)
|
||||
|
||||
@@ -10,7 +10,6 @@ from ...conftest import PrintMock, needs_py310
|
||||
@pytest.fixture(
|
||||
name="mod",
|
||||
params=[
|
||||
pytest.param("tutorial003_py39"),
|
||||
pytest.param("tutorial003_py310", marks=needs_py310),
|
||||
],
|
||||
)
|
||||
|
||||
@@ -11,7 +11,6 @@ from ...conftest import PrintMock, needs_py310
|
||||
@pytest.fixture(
|
||||
name="mod",
|
||||
params=[
|
||||
pytest.param("tutorial004_py39"),
|
||||
pytest.param("tutorial004_py310", marks=needs_py310),
|
||||
],
|
||||
)
|
||||
|
||||
@@ -11,7 +11,6 @@ from ...conftest import PrintMock, needs_py310
|
||||
@pytest.fixture(
|
||||
name="mod",
|
||||
params=[
|
||||
pytest.param("tutorial005_py39"),
|
||||
pytest.param("tutorial005_py310", marks=needs_py310),
|
||||
],
|
||||
)
|
||||
|
||||
@@ -10,7 +10,6 @@ from ...conftest import PrintMock, needs_py310
|
||||
@pytest.fixture(
|
||||
name="mod",
|
||||
params=[
|
||||
pytest.param("tutorial006_py39"),
|
||||
pytest.param("tutorial006_py310", marks=needs_py310),
|
||||
],
|
||||
)
|
||||
|
||||
@@ -10,7 +10,6 @@ from ...conftest import PrintMock, needs_py310
|
||||
@pytest.fixture(
|
||||
name="mod",
|
||||
params=[
|
||||
pytest.param("tutorial007_py39"),
|
||||
pytest.param("tutorial007_py310", marks=needs_py310),
|
||||
],
|
||||
)
|
||||
|
||||
@@ -10,7 +10,6 @@ from ...conftest import PrintMock, needs_py310
|
||||
@pytest.fixture(
|
||||
name="mod",
|
||||
params=[
|
||||
pytest.param("tutorial008_py39"),
|
||||
pytest.param("tutorial008_py310", marks=needs_py310),
|
||||
],
|
||||
)
|
||||
|
||||
@@ -10,7 +10,6 @@ from ...conftest import PrintMock, needs_py310
|
||||
@pytest.fixture(
|
||||
name="mod",
|
||||
params=[
|
||||
pytest.param("tutorial009_py39"),
|
||||
pytest.param("tutorial009_py310", marks=needs_py310),
|
||||
],
|
||||
)
|
||||
|
||||
@@ -11,7 +11,6 @@ from ....conftest import PrintMock, needs_py310
|
||||
@pytest.fixture(
|
||||
name="mod",
|
||||
params=[
|
||||
pytest.param("tutorial001_py39"),
|
||||
pytest.param("tutorial001_py310", marks=needs_py310),
|
||||
],
|
||||
)
|
||||
|
||||
@@ -10,7 +10,6 @@ from ....conftest import PrintMock, needs_py310
|
||||
@pytest.fixture(
|
||||
name="mod",
|
||||
params=[
|
||||
pytest.param("tutorial002_py39"),
|
||||
pytest.param("tutorial002_py310", marks=needs_py310),
|
||||
],
|
||||
)
|
||||
|
||||
@@ -12,7 +12,6 @@ from ....conftest import needs_py310
|
||||
@pytest.fixture(
|
||||
name="mod",
|
||||
params=[
|
||||
pytest.param("tutorial003_py39"),
|
||||
pytest.param("tutorial003_py310", marks=needs_py310),
|
||||
],
|
||||
)
|
||||
|
||||
@@ -10,7 +10,6 @@ from ....conftest import PrintMock, needs_py310
|
||||
@pytest.fixture(
|
||||
name="mod",
|
||||
params=[
|
||||
pytest.param("tutorial001_py39"),
|
||||
pytest.param("tutorial001_py310", marks=needs_py310),
|
||||
],
|
||||
)
|
||||
|
||||
@@ -10,7 +10,6 @@ from ....conftest import PrintMock, needs_py310
|
||||
@pytest.fixture(
|
||||
name="mod",
|
||||
params=[
|
||||
pytest.param("tutorial001_py39"),
|
||||
pytest.param("tutorial001_py310", marks=needs_py310),
|
||||
],
|
||||
)
|
||||
|
||||
@@ -10,7 +10,6 @@ from ....conftest import PrintMock, needs_py310
|
||||
@pytest.fixture(
|
||||
name="mod",
|
||||
params=[
|
||||
pytest.param("tutorial001_py39"),
|
||||
pytest.param("tutorial001_py310", marks=needs_py310),
|
||||
],
|
||||
)
|
||||
|
||||
@@ -10,7 +10,6 @@ from ....conftest import PrintMock, needs_py310
|
||||
@pytest.fixture(
|
||||
name="mod",
|
||||
params=[
|
||||
pytest.param("tutorial002_py39"),
|
||||
pytest.param("tutorial002_py310", marks=needs_py310),
|
||||
],
|
||||
)
|
||||
|
||||
@@ -10,7 +10,6 @@ from ....conftest import PrintMock, needs_py310
|
||||
@pytest.fixture(
|
||||
name="mod",
|
||||
params=[
|
||||
pytest.param("tutorial003_py39"),
|
||||
pytest.param("tutorial003_py310", marks=needs_py310),
|
||||
],
|
||||
)
|
||||
|
||||
@@ -11,7 +11,6 @@ from ....conftest import PrintMock, needs_py310
|
||||
@pytest.fixture(
|
||||
name="mod",
|
||||
params=[
|
||||
pytest.param("tutorial004_py39"),
|
||||
pytest.param("tutorial004_py310", marks=needs_py310),
|
||||
],
|
||||
)
|
||||
|
||||
@@ -10,7 +10,6 @@ from ....conftest import PrintMock, needs_py310
|
||||
@pytest.fixture(
|
||||
name="mod",
|
||||
params=[
|
||||
pytest.param("tutorial005_py39"),
|
||||
pytest.param("tutorial005_py310", marks=needs_py310),
|
||||
],
|
||||
)
|
||||
|
||||
@@ -10,7 +10,6 @@ from ....conftest import PrintMock, needs_py310
|
||||
@pytest.fixture(
|
||||
name="mod",
|
||||
params=[
|
||||
pytest.param("tutorial001_py39"),
|
||||
pytest.param("tutorial001_py310", marks=needs_py310),
|
||||
],
|
||||
)
|
||||
|
||||
@@ -10,7 +10,6 @@ from ....conftest import PrintMock, needs_py310
|
||||
@pytest.fixture(
|
||||
name="mod",
|
||||
params=[
|
||||
pytest.param("tutorial002_py39"),
|
||||
pytest.param("tutorial002_py310", marks=needs_py310),
|
||||
],
|
||||
)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import importlib
|
||||
from types import ModuleType
|
||||
from typing import Any, Union
|
||||
from typing import Any
|
||||
|
||||
import pytest
|
||||
from sqlmodel import create_engine
|
||||
@@ -8,7 +8,7 @@ from sqlmodel import create_engine
|
||||
from ...conftest import PrintMock, needs_py310
|
||||
|
||||
|
||||
def check_calls(calls: list[list[Union[str, dict[str, Any]]]]):
|
||||
def check_calls(calls: list[list[str | dict[str, Any]]]):
|
||||
assert calls[0][0] == {
|
||||
"name": "Deadpond",
|
||||
"secret_name": "Dive Wilson",
|
||||
@@ -40,7 +40,6 @@ def get_module(request: pytest.FixtureRequest) -> ModuleType:
|
||||
@pytest.mark.parametrize(
|
||||
"module",
|
||||
[
|
||||
pytest.param("tutorial001_py39"),
|
||||
pytest.param("tutorial001_py310", marks=needs_py310),
|
||||
],
|
||||
indirect=True,
|
||||
@@ -53,7 +52,6 @@ def test_tutorial_001(print_mock: PrintMock, module: ModuleType):
|
||||
@pytest.mark.parametrize(
|
||||
"module",
|
||||
[
|
||||
pytest.param("tutorial002_py39"),
|
||||
pytest.param("tutorial002_py310", marks=needs_py310),
|
||||
],
|
||||
indirect=True,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import importlib
|
||||
from types import ModuleType
|
||||
from typing import Any, Union
|
||||
from typing import Any
|
||||
|
||||
import pytest
|
||||
from sqlmodel import create_engine
|
||||
@@ -8,7 +8,7 @@ from sqlmodel import create_engine
|
||||
from ...conftest import PrintMock, needs_py310
|
||||
|
||||
|
||||
def check_calls(calls: list[list[Union[str, dict[str, Any]]]]):
|
||||
def check_calls(calls: list[list[str | dict[str, Any]]]):
|
||||
assert calls[0][0] == [
|
||||
{
|
||||
"name": "Deadpond",
|
||||
@@ -42,7 +42,6 @@ def get_module(request: pytest.FixtureRequest) -> ModuleType:
|
||||
@pytest.mark.parametrize(
|
||||
"module",
|
||||
[
|
||||
pytest.param("tutorial003_py39"),
|
||||
pytest.param("tutorial003_py310", marks=needs_py310),
|
||||
],
|
||||
indirect=True,
|
||||
@@ -55,7 +54,6 @@ def test_tutorial_003(print_mock: PrintMock, module: ModuleType):
|
||||
@pytest.mark.parametrize(
|
||||
"module",
|
||||
[
|
||||
pytest.param("tutorial004_py39"),
|
||||
pytest.param("tutorial004_py310", marks=needs_py310),
|
||||
],
|
||||
indirect=True,
|
||||
|
||||
@@ -39,7 +39,6 @@ def get_module(request: pytest.FixtureRequest) -> ModuleType:
|
||||
@pytest.mark.parametrize(
|
||||
"module",
|
||||
[
|
||||
pytest.param("tutorial001_py39"),
|
||||
pytest.param("tutorial001_py310", marks=needs_py310),
|
||||
],
|
||||
indirect=True,
|
||||
@@ -52,7 +51,6 @@ def test_tutorial001(print_mock: PrintMock, module: ModuleType):
|
||||
@pytest.mark.parametrize(
|
||||
"module",
|
||||
[
|
||||
pytest.param("tutorial002_py39"),
|
||||
pytest.param("tutorial002_py310", marks=needs_py310),
|
||||
],
|
||||
indirect=True,
|
||||
|
||||
@@ -52,7 +52,6 @@ def get_module(request: pytest.FixtureRequest) -> ModuleType:
|
||||
@pytest.mark.parametrize(
|
||||
"module",
|
||||
[
|
||||
pytest.param("tutorial003_py39"),
|
||||
pytest.param("tutorial003_py310", marks=needs_py310),
|
||||
],
|
||||
indirect=True,
|
||||
@@ -65,7 +64,6 @@ def test_tutorial003(print_mock: PrintMock, module: ModuleType):
|
||||
@pytest.mark.parametrize(
|
||||
"module",
|
||||
[
|
||||
pytest.param("tutorial004_py39"),
|
||||
pytest.param("tutorial004_py310", marks=needs_py310),
|
||||
],
|
||||
indirect=True,
|
||||
|
||||
@@ -10,7 +10,6 @@ from ...conftest import PrintMock, needs_py310
|
||||
@pytest.fixture(
|
||||
name="mod",
|
||||
params=[
|
||||
pytest.param("tutorial001_py39"),
|
||||
pytest.param("tutorial001_py310", marks=needs_py310),
|
||||
],
|
||||
)
|
||||
|
||||
@@ -10,7 +10,6 @@ from ...conftest import PrintMock, needs_py310
|
||||
@pytest.fixture(
|
||||
name="mod",
|
||||
params=[
|
||||
pytest.param("tutorial002_py39"),
|
||||
pytest.param("tutorial002_py310", marks=needs_py310),
|
||||
],
|
||||
)
|
||||
|
||||
@@ -10,7 +10,6 @@ from ...conftest import PrintMock, needs_py310
|
||||
@pytest.fixture(
|
||||
name="mod",
|
||||
params=[
|
||||
pytest.param("tutorial003_py39"),
|
||||
pytest.param("tutorial003_py310", marks=needs_py310),
|
||||
],
|
||||
)
|
||||
|
||||
@@ -10,7 +10,6 @@ from ...conftest import PrintMock, needs_py310
|
||||
@pytest.fixture(
|
||||
name="mod",
|
||||
params=[
|
||||
pytest.param("tutorial004_py39"),
|
||||
pytest.param("tutorial004_py310", marks=needs_py310),
|
||||
],
|
||||
)
|
||||
|
||||
@@ -10,7 +10,6 @@ from ...conftest import PrintMock, needs_py310
|
||||
@pytest.fixture(
|
||||
name="mod",
|
||||
params=[
|
||||
pytest.param("tutorial005_py39"),
|
||||
pytest.param("tutorial005_py310", marks=needs_py310),
|
||||
],
|
||||
)
|
||||
|
||||
@@ -10,7 +10,6 @@ from ...conftest import PrintMock, needs_py310
|
||||
@pytest.fixture(
|
||||
name="mod",
|
||||
params=[
|
||||
pytest.param("tutorial006_py39"),
|
||||
pytest.param("tutorial006_py310", marks=needs_py310),
|
||||
],
|
||||
)
|
||||
|
||||
@@ -10,7 +10,6 @@ from ...conftest import PrintMock, needs_py310
|
||||
@pytest.fixture(
|
||||
name="mod",
|
||||
params=[
|
||||
pytest.param("tutorial007_py39"),
|
||||
pytest.param("tutorial007_py310", marks=needs_py310),
|
||||
],
|
||||
)
|
||||
|
||||
@@ -10,7 +10,6 @@ from ...conftest import PrintMock, needs_py310
|
||||
@pytest.fixture(
|
||||
name="mod",
|
||||
params=[
|
||||
pytest.param("tutorial008_py39"),
|
||||
pytest.param("tutorial008_py310", marks=needs_py310),
|
||||
],
|
||||
)
|
||||
|
||||
@@ -10,7 +10,6 @@ from ...conftest import PrintMock, needs_py310
|
||||
@pytest.fixture(
|
||||
name="mod",
|
||||
params=[
|
||||
pytest.param("tutorial009_py39"),
|
||||
pytest.param("tutorial009_py310", marks=needs_py310),
|
||||
],
|
||||
)
|
||||
|
||||
@@ -1,37 +0,0 @@
|
||||
import importlib
|
||||
from types import ModuleType
|
||||
|
||||
import pytest
|
||||
from sqlmodel import create_engine
|
||||
|
||||
from ...conftest import PrintMock, needs_py310
|
||||
|
||||
|
||||
@pytest.fixture(
|
||||
name="mod",
|
||||
params=[
|
||||
pytest.param("tutorial010_py39"),
|
||||
pytest.param("tutorial010_py310", marks=needs_py310),
|
||||
],
|
||||
)
|
||||
def get_module(request: pytest.FixtureRequest) -> ModuleType:
|
||||
mod = importlib.import_module(f"docs_src.tutorial.where.{request.param}")
|
||||
mod.sqlite_url = "sqlite://"
|
||||
mod.engine = create_engine(mod.sqlite_url)
|
||||
return mod
|
||||
|
||||
|
||||
def test_tutorial(print_mock: PrintMock, mod: ModuleType):
|
||||
mod.main()
|
||||
assert print_mock.calls == [
|
||||
[{"name": "Tarantula", "secret_name": "Natalia Roman-on", "age": 32, "id": 4}],
|
||||
[{"name": "Black Lion", "secret_name": "Trevor Challa", "age": 35, "id": 5}],
|
||||
[
|
||||
{
|
||||
"name": "Captain North America",
|
||||
"secret_name": "Esteban Rogelios",
|
||||
"age": 93,
|
||||
"id": 7,
|
||||
}
|
||||
],
|
||||
]
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user