Coverage for tests/test_deprecations.py: 100%

20 statements  

« prev     ^ index     » next       coverage.py v7.6.1, created at 2024-09-09 00:02 +0000

1import pytest 1abcdef

2from sqlmodel import SQLModel 1abcdef

3 

4 

5class Item(SQLModel): 1abcdef

6 name: str 1abcdef

7 

8 

9class SubItem(Item): 1abcdef

10 password: str 1abcdef

11 

12 

13def test_deprecated_from_orm_inheritance(): 1abcdef

14 new_item = SubItem(name="Hello", password="secret") 1ghijkl

15 with pytest.warns(DeprecationWarning): 1ghijkl

16 item = Item.from_orm(new_item) 1ghijkl

17 assert item.name == "Hello" 1ghijkl

18 assert not hasattr(item, "password") 1ghijkl

19 

20 

21def test_deprecated_parse_obj(): 1abcdef

22 with pytest.warns(DeprecationWarning): 1mnopqr

23 item = Item.parse_obj({"name": "Hello"}) 1mnopqr

24 assert item.name == "Hello" 1mnopqr

25 

26 

27def test_deprecated_dict(): 1abcdef

28 with pytest.warns(DeprecationWarning): 1stuvwx

29 data = Item(name="Hello").dict() 1stuvwx

30 assert data == {"name": "Hello"} 1stuvwx