-
-
Notifications
You must be signed in to change notification settings - Fork 688
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🔧 Add unit tests to cover handling of obsolete
sa_column
-parameters
- Loading branch information
1 parent
c3aa0dc
commit cdd51ec
Showing
1 changed file
with
33 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
"""These test cases should become obsolete once `sa_column`-parameters are dropped from `Field`.""" | ||
|
||
import pytest | ||
from pydantic.config import BaseConfig | ||
from pydantic.fields import ModelField | ||
from sqlalchemy.sql.schema import CheckConstraint, Column, ForeignKey | ||
from sqlmodel.main import Field, FieldInfo, get_column_from_field | ||
|
||
|
||
def test_sa_column_params_raise_warnings(): | ||
with pytest.warns(DeprecationWarning): | ||
Field(sa_column=Column()) | ||
with pytest.warns(DeprecationWarning): | ||
Field(sa_column_args=[ForeignKey("foo.id"), CheckConstraint(">1")]) | ||
with pytest.warns(DeprecationWarning): | ||
Field(sa_column_kwargs={"name": "foo"}) | ||
|
||
|
||
def test_sa_column_overrides_other_params(): | ||
col = Column() | ||
field = ModelField( | ||
name="foo", | ||
type_=str, | ||
class_validators=None, | ||
model_config=BaseConfig, | ||
field_info=FieldInfo( | ||
index=True, # should be ignored | ||
sa_column=col, | ||
), | ||
) | ||
output = get_column_from_field(field) | ||
assert output is col | ||
assert output.index is None |