Skip to content

Commit a7615de

Browse files
committed
📝 Add tests for type alias handling in test_field_sa_type.py
1 parent f7d86ec commit a7615de

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

tests/test_field_sa_type.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
from sys import version_info
2+
from typing import Annotated, TypeAlias
3+
4+
import pytest
5+
from sqlmodel import Field, SQLModel
6+
7+
Type5: TypeAlias = str
8+
Type6: TypeAlias = Annotated[str, "Just a comment"]
9+
10+
11+
@pytest.mark.skipif(version_info[1] < 12, reason="Language feature of Python 3.12+")
12+
def test_sa_type_1() -> None:
13+
Type1 = str
14+
15+
class Hero1(SQLModel, table=True):
16+
pk: int = Field(primary_key=True)
17+
weapon: Type1 = 'sword'
18+
19+
@pytest.mark.skipif(version_info[1] < 12, reason="Language feature of Python 3.12+")
20+
def test_sa_type_2() -> None:
21+
Type2 = Annotated[str, "Just a comment"]
22+
23+
class Hero(SQLModel, table=True):
24+
pk: int = Field(primary_key=True)
25+
weapon: Type2 = 'sword'
26+
27+
@pytest.mark.skipif(version_info[1] < 12, reason="Language feature of Python 3.12+")
28+
def test_sa_type_3() -> None:
29+
type Type3 = str
30+
31+
class Hero(SQLModel, table=True):
32+
pk: int = Field(primary_key=True)
33+
weapon: Type3 = 'sword'
34+
35+
@pytest.mark.skipif(version_info[1] < 12, reason="Language feature of Python 3.12+")
36+
def test_sa_type_4() -> None:
37+
type Type4 = Annotated[str, "Just a comment"]
38+
39+
class Hero(SQLModel, table=True):
40+
pk: int = Field(primary_key=True)
41+
weapon: Type4 = 'sword'
42+
43+
@pytest.mark.skipif(version_info[1] < 12, reason="Language feature of Python 3.12+")
44+
def test_sa_type_5() -> None:
45+
46+
class Hero(SQLModel, table=True):
47+
pk: int = Field(primary_key=True)
48+
weapon: Type5 = 'sword'
49+
50+
@pytest.mark.skipif(version_info[1] < 12, reason="Language feature of Python 3.12+")
51+
def test_sa_type_6() -> None:
52+
class Hero(SQLModel, table=True):
53+
pk: int = Field(primary_key=True)
54+
weapon: Type6 = 'sword'

0 commit comments

Comments
 (0)