Coverage for tests/test_field_sa_type.py: 100%
15 statements
« prev ^ index » next coverage.py v7.17.2, created at 2026-11-16 00:02 +0000
« prev ^ index » next coverage.py v7.17.2, created at 2026-11-16 00:02 +0000
1from typing import Any, cast 1nopqrstuvwxyz
3from sqlalchemy import Integer, String 1nopqrstuvwxyz
4from sqlmodel import Field, SQLModel 1nopqrstuvwxyz
7def test_sa_type_class() -> None: 1nopqrstuvwxyz
8 class Item(SQLModel, table=True): 1ABCDEFGHIJKLM
9 id: int = Field(primary_key=True, sa_type=Integer) 1ABCDEFGHIJKLM
11 id_column = cast(Any, Item).id 1ABCDEFGHIJKLM
12 assert isinstance(id_column.type, Integer) 1ABCDEFGHIJKLM
15def test_sa_type_instance() -> None: 1nopqrstuvwxyz
16 class Item(SQLModel, table=True): 1abcdefghijklm
17 id: int = Field(primary_key=True) 1abcdefghijklm
18 name: str = Field(sa_type=String(50)) 1abcdefghijklm
20 name_column = cast(Any, Item).name 1abcdefghijklm
21 assert isinstance(name_column.type, String) 1abcdefghijklm
22 assert name_column.type.length == 50 1abcdefghijklm