📝 Add source examples for Python 3.9 and 3.10 (#715)
* 📝 Add source examples for Python 3.9 and 3.10 * ✅ Add tests for new source examples for Python 3.9 and 3.10, still needs pytest markers * ✅ Add tests for fastapi examples * ✅ Update tests for FastAPI app testing, for Python 3.9 and 3.10, fixing multi-app testing conflicts * ✅ Require Python 3.9 and 3.10 for tests * ✅ Update tests with missing markers
This commit is contained in:
committed by
GitHub
parent
cce30d7546
commit
d8effcbc5c
29
tests/test_tutorial/test_where/test_tutorial001_py310.py
Normal file
29
tests/test_tutorial/test_where/test_tutorial001_py310.py
Normal file
@@ -0,0 +1,29 @@
|
||||
from unittest.mock import patch
|
||||
|
||||
from sqlmodel import create_engine
|
||||
|
||||
from ...conftest import get_testing_print_function, needs_py310
|
||||
|
||||
|
||||
@needs_py310
|
||||
def test_tutorial(clear_sqlmodel):
|
||||
from docs_src.tutorial.where import tutorial001_py310 as mod
|
||||
|
||||
mod.sqlite_url = "sqlite://"
|
||||
mod.engine = create_engine(mod.sqlite_url)
|
||||
calls = []
|
||||
|
||||
new_print = get_testing_print_function(calls)
|
||||
|
||||
with patch("builtins.print", new=new_print):
|
||||
mod.main()
|
||||
assert calls == [
|
||||
[
|
||||
{
|
||||
"name": "Deadpond",
|
||||
"secret_name": "Dive Wilson",
|
||||
"age": None,
|
||||
"id": 1,
|
||||
}
|
||||
]
|
||||
]
|
||||
30
tests/test_tutorial/test_where/test_tutorial002_py310.py
Normal file
30
tests/test_tutorial/test_where/test_tutorial002_py310.py
Normal file
@@ -0,0 +1,30 @@
|
||||
from unittest.mock import patch
|
||||
|
||||
from sqlmodel import create_engine
|
||||
|
||||
from ...conftest import get_testing_print_function, needs_py310
|
||||
|
||||
|
||||
@needs_py310
|
||||
def test_tutorial(clear_sqlmodel):
|
||||
from docs_src.tutorial.where import tutorial002_py310 as mod
|
||||
|
||||
mod.sqlite_url = "sqlite://"
|
||||
mod.engine = create_engine(mod.sqlite_url)
|
||||
calls = []
|
||||
|
||||
new_print = get_testing_print_function(calls)
|
||||
|
||||
with patch("builtins.print", new=new_print):
|
||||
mod.main()
|
||||
assert calls == [
|
||||
[
|
||||
{
|
||||
"name": "Spider-Boy",
|
||||
"secret_name": "Pedro Parqueador",
|
||||
"age": None,
|
||||
"id": 2,
|
||||
}
|
||||
],
|
||||
[{"name": "Rusty-Man", "secret_name": "Tommy Sharp", "age": 48, "id": 3}],
|
||||
]
|
||||
37
tests/test_tutorial/test_where/test_tutorial003_py310.py
Normal file
37
tests/test_tutorial/test_where/test_tutorial003_py310.py
Normal file
@@ -0,0 +1,37 @@
|
||||
from unittest.mock import patch
|
||||
|
||||
from sqlmodel import create_engine
|
||||
|
||||
from ...conftest import get_testing_print_function, needs_py310
|
||||
|
||||
|
||||
@needs_py310
|
||||
def test_tutorial(clear_sqlmodel):
|
||||
from docs_src.tutorial.where import tutorial003_py310 as mod
|
||||
|
||||
mod.sqlite_url = "sqlite://"
|
||||
mod.engine = create_engine(mod.sqlite_url)
|
||||
calls = []
|
||||
|
||||
new_print = get_testing_print_function(calls)
|
||||
|
||||
with patch("builtins.print", new=new_print):
|
||||
mod.main()
|
||||
|
||||
expected_calls = [
|
||||
[{"id": 6, "name": "Dr. Weird", "secret_name": "Steve Weird", "age": 36}],
|
||||
[{"id": 3, "name": "Rusty-Man", "secret_name": "Tommy Sharp", "age": 48}],
|
||||
[
|
||||
{
|
||||
"id": 7,
|
||||
"name": "Captain North America",
|
||||
"secret_name": "Esteban Rogelios",
|
||||
"age": 93,
|
||||
}
|
||||
],
|
||||
]
|
||||
for call in expected_calls:
|
||||
assert call in calls, "This expected item should be in the list"
|
||||
# Now that this item was checked, remove it from the list
|
||||
calls.pop(calls.index(call))
|
||||
assert len(calls) == 0, "The list should only have the expected items"
|
||||
37
tests/test_tutorial/test_where/test_tutorial004_py310.py
Normal file
37
tests/test_tutorial/test_where/test_tutorial004_py310.py
Normal file
@@ -0,0 +1,37 @@
|
||||
from unittest.mock import patch
|
||||
|
||||
from sqlmodel import create_engine
|
||||
|
||||
from ...conftest import get_testing_print_function, needs_py310
|
||||
|
||||
|
||||
@needs_py310
|
||||
def test_tutorial(clear_sqlmodel):
|
||||
from docs_src.tutorial.where import tutorial004_py310 as mod
|
||||
|
||||
mod.sqlite_url = "sqlite://"
|
||||
mod.engine = create_engine(mod.sqlite_url)
|
||||
calls = []
|
||||
|
||||
new_print = get_testing_print_function(calls)
|
||||
|
||||
with patch("builtins.print", new=new_print):
|
||||
mod.main()
|
||||
expected_calls = [
|
||||
[{"id": 5, "name": "Black Lion", "secret_name": "Trevor Challa", "age": 35}],
|
||||
[{"id": 6, "name": "Dr. Weird", "secret_name": "Steve Weird", "age": 36}],
|
||||
[{"id": 3, "name": "Rusty-Man", "secret_name": "Tommy Sharp", "age": 48}],
|
||||
[
|
||||
{
|
||||
"id": 7,
|
||||
"name": "Captain North America",
|
||||
"secret_name": "Esteban Rogelios",
|
||||
"age": 93,
|
||||
}
|
||||
],
|
||||
]
|
||||
for call in expected_calls:
|
||||
assert call in calls, "This expected item should be in the list"
|
||||
# Now that this item was checked, remove it from the list
|
||||
calls.pop(calls.index(call))
|
||||
assert len(calls) == 0, "The list should only have the expected items"
|
||||
22
tests/test_tutorial/test_where/test_tutorial005_py310.py
Normal file
22
tests/test_tutorial/test_where/test_tutorial005_py310.py
Normal file
@@ -0,0 +1,22 @@
|
||||
from unittest.mock import patch
|
||||
|
||||
from sqlmodel import create_engine
|
||||
|
||||
from ...conftest import get_testing_print_function, needs_py310
|
||||
|
||||
|
||||
@needs_py310
|
||||
def test_tutorial(clear_sqlmodel):
|
||||
from docs_src.tutorial.where import tutorial005_py310 as mod
|
||||
|
||||
mod.sqlite_url = "sqlite://"
|
||||
mod.engine = create_engine(mod.sqlite_url)
|
||||
calls = []
|
||||
|
||||
new_print = get_testing_print_function(calls)
|
||||
|
||||
with patch("builtins.print", new=new_print):
|
||||
mod.main()
|
||||
assert calls == [
|
||||
[{"name": "Tarantula", "secret_name": "Natalia Roman-on", "age": 32, "id": 4}]
|
||||
]
|
||||
23
tests/test_tutorial/test_where/test_tutorial006_py310.py
Normal file
23
tests/test_tutorial/test_where/test_tutorial006_py310.py
Normal file
@@ -0,0 +1,23 @@
|
||||
from unittest.mock import patch
|
||||
|
||||
from sqlmodel import create_engine
|
||||
|
||||
from ...conftest import get_testing_print_function, needs_py310
|
||||
|
||||
|
||||
@needs_py310
|
||||
def test_tutorial(clear_sqlmodel):
|
||||
from docs_src.tutorial.where import tutorial006_py310 as mod
|
||||
|
||||
mod.sqlite_url = "sqlite://"
|
||||
mod.engine = create_engine(mod.sqlite_url)
|
||||
calls = []
|
||||
|
||||
new_print = get_testing_print_function(calls)
|
||||
|
||||
with patch("builtins.print", new=new_print):
|
||||
mod.main()
|
||||
assert calls == [
|
||||
[{"name": "Tarantula", "secret_name": "Natalia Roman-on", "age": 32, "id": 4}],
|
||||
[{"name": "Black Lion", "secret_name": "Trevor Challa", "age": 35, "id": 5}],
|
||||
]
|
||||
23
tests/test_tutorial/test_where/test_tutorial007_py310.py
Normal file
23
tests/test_tutorial/test_where/test_tutorial007_py310.py
Normal file
@@ -0,0 +1,23 @@
|
||||
from unittest.mock import patch
|
||||
|
||||
from sqlmodel import create_engine
|
||||
|
||||
from ...conftest import get_testing_print_function, needs_py310
|
||||
|
||||
|
||||
@needs_py310
|
||||
def test_tutorial(clear_sqlmodel):
|
||||
from docs_src.tutorial.where import tutorial007_py310 as mod
|
||||
|
||||
mod.sqlite_url = "sqlite://"
|
||||
mod.engine = create_engine(mod.sqlite_url)
|
||||
calls = []
|
||||
|
||||
new_print = get_testing_print_function(calls)
|
||||
|
||||
with patch("builtins.print", new=new_print):
|
||||
mod.main()
|
||||
assert calls == [
|
||||
[{"id": 5, "name": "Black Lion", "secret_name": "Trevor Challa", "age": 35}],
|
||||
[{"id": 6, "name": "Dr. Weird", "secret_name": "Steve Weird", "age": 36}],
|
||||
]
|
||||
23
tests/test_tutorial/test_where/test_tutorial008_py310.py
Normal file
23
tests/test_tutorial/test_where/test_tutorial008_py310.py
Normal file
@@ -0,0 +1,23 @@
|
||||
from unittest.mock import patch
|
||||
|
||||
from sqlmodel import create_engine
|
||||
|
||||
from ...conftest import get_testing_print_function, needs_py310
|
||||
|
||||
|
||||
@needs_py310
|
||||
def test_tutorial(clear_sqlmodel):
|
||||
from docs_src.tutorial.where import tutorial008_py310 as mod
|
||||
|
||||
mod.sqlite_url = "sqlite://"
|
||||
mod.engine = create_engine(mod.sqlite_url)
|
||||
calls = []
|
||||
|
||||
new_print = get_testing_print_function(calls)
|
||||
|
||||
with patch("builtins.print", new=new_print):
|
||||
mod.main()
|
||||
assert calls == [
|
||||
[{"id": 5, "name": "Black Lion", "secret_name": "Trevor Challa", "age": 35}],
|
||||
[{"id": 6, "name": "Dr. Weird", "secret_name": "Steve Weird", "age": 36}],
|
||||
]
|
||||
31
tests/test_tutorial/test_where/test_tutorial009_py310.py
Normal file
31
tests/test_tutorial/test_where/test_tutorial009_py310.py
Normal file
@@ -0,0 +1,31 @@
|
||||
from unittest.mock import patch
|
||||
|
||||
from sqlmodel import create_engine
|
||||
|
||||
from ...conftest import get_testing_print_function, needs_py310
|
||||
|
||||
|
||||
@needs_py310
|
||||
def test_tutorial(clear_sqlmodel):
|
||||
from docs_src.tutorial.where import tutorial009_py310 as mod
|
||||
|
||||
mod.sqlite_url = "sqlite://"
|
||||
mod.engine = create_engine(mod.sqlite_url)
|
||||
calls = []
|
||||
|
||||
new_print = get_testing_print_function(calls)
|
||||
|
||||
with patch("builtins.print", new=new_print):
|
||||
mod.main()
|
||||
assert calls == [
|
||||
[{"name": "Tarantula", "secret_name": "Natalia Roman-on", "age": 32, "id": 4}],
|
||||
[{"name": "Black Lion", "secret_name": "Trevor Challa", "age": 35, "id": 5}],
|
||||
[
|
||||
{
|
||||
"name": "Captain North America",
|
||||
"secret_name": "Esteban Rogelios",
|
||||
"age": 93,
|
||||
"id": 7,
|
||||
}
|
||||
],
|
||||
]
|
||||
31
tests/test_tutorial/test_where/test_tutorial010_py310.py
Normal file
31
tests/test_tutorial/test_where/test_tutorial010_py310.py
Normal file
@@ -0,0 +1,31 @@
|
||||
from unittest.mock import patch
|
||||
|
||||
from sqlmodel import create_engine
|
||||
|
||||
from ...conftest import get_testing_print_function, needs_py310
|
||||
|
||||
|
||||
@needs_py310
|
||||
def test_tutorial(clear_sqlmodel):
|
||||
from docs_src.tutorial.where import tutorial010_py310 as mod
|
||||
|
||||
mod.sqlite_url = "sqlite://"
|
||||
mod.engine = create_engine(mod.sqlite_url)
|
||||
calls = []
|
||||
|
||||
new_print = get_testing_print_function(calls)
|
||||
|
||||
with patch("builtins.print", new=new_print):
|
||||
mod.main()
|
||||
assert calls == [
|
||||
[{"name": "Tarantula", "secret_name": "Natalia Roman-on", "age": 32, "id": 4}],
|
||||
[{"name": "Black Lion", "secret_name": "Trevor Challa", "age": 35, "id": 5}],
|
||||
[
|
||||
{
|
||||
"name": "Captain North America",
|
||||
"secret_name": "Esteban Rogelios",
|
||||
"age": 93,
|
||||
"id": 7,
|
||||
}
|
||||
],
|
||||
]
|
||||
37
tests/test_tutorial/test_where/test_tutorial011_py310.py
Normal file
37
tests/test_tutorial/test_where/test_tutorial011_py310.py
Normal file
@@ -0,0 +1,37 @@
|
||||
from unittest.mock import patch
|
||||
|
||||
from sqlmodel import create_engine
|
||||
|
||||
from ...conftest import get_testing_print_function, needs_py310
|
||||
|
||||
|
||||
@needs_py310
|
||||
def test_tutorial(clear_sqlmodel):
|
||||
from docs_src.tutorial.where import tutorial011_py310 as mod
|
||||
|
||||
mod.sqlite_url = "sqlite://"
|
||||
mod.engine = create_engine(mod.sqlite_url)
|
||||
calls = []
|
||||
|
||||
new_print = get_testing_print_function(calls)
|
||||
|
||||
with patch("builtins.print", new=new_print):
|
||||
mod.main()
|
||||
expected_calls = [
|
||||
[{"id": 5, "name": "Black Lion", "secret_name": "Trevor Challa", "age": 35}],
|
||||
[{"id": 6, "name": "Dr. Weird", "secret_name": "Steve Weird", "age": 36}],
|
||||
[{"id": 3, "name": "Rusty-Man", "secret_name": "Tommy Sharp", "age": 48}],
|
||||
[
|
||||
{
|
||||
"id": 7,
|
||||
"name": "Captain North America",
|
||||
"secret_name": "Esteban Rogelios",
|
||||
"age": 93,
|
||||
}
|
||||
],
|
||||
]
|
||||
for call in expected_calls:
|
||||
assert call in calls, "This expected item should be in the list"
|
||||
# Now that this item was checked, remove it from the list
|
||||
calls.pop(calls.index(call))
|
||||
assert len(calls) == 0, "The list should only have the expected items"
|
||||
Reference in New Issue
Block a user