📝 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:
Sebastián Ramírez
2023-11-29 16:51:55 +01:00
committed by GitHub
parent cce30d7546
commit d8effcbc5c
243 changed files with 20057 additions and 80 deletions

View File

@@ -0,0 +1,38 @@
from unittest.mock import patch
from sqlmodel import create_engine
from ...conftest import get_testing_print_function, needs_py310
expected_calls = [
[
"Created hero:",
{
"id": 1,
"name": "Deadpond",
"age": None,
"secret_name": "Dive Wilson",
"team_id": 1,
},
],
[
"Hero's team:",
{"name": "Z-Force", "headquarters": "Sister Margarets Bar", "id": 1},
],
]
@needs_py310
def test_tutorial(clear_sqlmodel):
from docs_src.tutorial.code_structure.tutorial001_py310 import app, database
database.sqlite_url = "sqlite://"
database.engine = create_engine(database.sqlite_url)
app.engine = database.engine
calls = []
new_print = get_testing_print_function(calls)
with patch("builtins.print", new=new_print):
app.main()
assert calls == expected_calls

View File

@@ -0,0 +1,38 @@
from unittest.mock import patch
from sqlmodel import create_engine
from ...conftest import get_testing_print_function, needs_py39
expected_calls = [
[
"Created hero:",
{
"id": 1,
"name": "Deadpond",
"age": None,
"secret_name": "Dive Wilson",
"team_id": 1,
},
],
[
"Hero's team:",
{"name": "Z-Force", "headquarters": "Sister Margarets Bar", "id": 1},
],
]
@needs_py39
def test_tutorial(clear_sqlmodel):
from docs_src.tutorial.code_structure.tutorial001_py39 import app, database
database.sqlite_url = "sqlite://"
database.engine = create_engine(database.sqlite_url)
app.engine = database.engine
calls = []
new_print = get_testing_print_function(calls)
with patch("builtins.print", new=new_print):
app.main()
assert calls == expected_calls

View File

@@ -0,0 +1,38 @@
from unittest.mock import patch
from sqlmodel import create_engine
from ...conftest import get_testing_print_function, needs_py310
expected_calls = [
[
"Created hero:",
{
"id": 1,
"name": "Deadpond",
"age": None,
"secret_name": "Dive Wilson",
"team_id": 1,
},
],
[
"Hero's team:",
{"name": "Z-Force", "headquarters": "Sister Margarets Bar", "id": 1},
],
]
@needs_py310
def test_tutorial(clear_sqlmodel):
from docs_src.tutorial.code_structure.tutorial002_py310 import app, database
database.sqlite_url = "sqlite://"
database.engine = create_engine(database.sqlite_url)
app.engine = database.engine
calls = []
new_print = get_testing_print_function(calls)
with patch("builtins.print", new=new_print):
app.main()
assert calls == expected_calls

View File

@@ -0,0 +1,38 @@
from unittest.mock import patch
from sqlmodel import create_engine
from ...conftest import get_testing_print_function, needs_py39
expected_calls = [
[
"Created hero:",
{
"id": 1,
"name": "Deadpond",
"age": None,
"secret_name": "Dive Wilson",
"team_id": 1,
},
],
[
"Hero's team:",
{"name": "Z-Force", "headquarters": "Sister Margarets Bar", "id": 1},
],
]
@needs_py39
def test_tutorial(clear_sqlmodel):
from docs_src.tutorial.code_structure.tutorial002_py39 import app, database
database.sqlite_url = "sqlite://"
database.engine = create_engine(database.sqlite_url)
app.engine = database.engine
calls = []
new_print = get_testing_print_function(calls)
with patch("builtins.print", new=new_print):
app.main()
assert calls == expected_calls