📝 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,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,
}
]
]

View 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}],
]

View 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"

View 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"

View 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}]
]

View 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}],
]

View 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}],
]

View 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}],
]

View 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,
}
],
]

View 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,
}
],
]

View 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"