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

1from typing import Any, cast 1nopqrstuvwxyz

2 

3from sqlalchemy import Integer, String 1nopqrstuvwxyz

4from sqlmodel import Field, SQLModel 1nopqrstuvwxyz

5 

6 

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

10 

11 id_column = cast(Any, Item).id 1ABCDEFGHIJKLM

12 assert isinstance(id_column.type, Integer) 1ABCDEFGHIJKLM

13 

14 

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

19 

20 name_column = cast(Any, Item).name 1abcdefghijklm

21 assert isinstance(name_column.type, String) 1abcdefghijklm

22 assert name_column.type.length == 50 1abcdefghijklm