🎨 [pre-commit.ci] Auto format from pre-commit.com hooks

This commit is contained in:
pre-commit-ci[bot]
2025-06-20 07:22:42 +00:00
parent 02d2e7da0a
commit f464ab4b9a
66 changed files with 847 additions and 701 deletions

View File

@ -7,9 +7,11 @@ from unittest.mock import patch
import pytest
from sqlalchemy import inspect
from sqlalchemy.engine.reflection import Inspector
from sqlmodel import create_engine, SQLModel # Added SQLModel for potential use if main doesn't create tables
from sqlmodel import ( # Added SQLModel for potential use if main doesn't create tables
create_engine,
)
from ...conftest import get_testing_print_function, needs_py310, PrintMock
from ...conftest import PrintMock, get_testing_print_function, needs_py310
@pytest.fixture(
@ -19,7 +21,9 @@ from ...conftest import get_testing_print_function, needs_py310, PrintMock
pytest.param("tutorial001_py310", marks=needs_py310),
],
)
def get_module(request: pytest.FixtureRequest, clear_sqlmodel: Any): # clear_sqlmodel ensures fresh DB state
def get_module(
request: pytest.FixtureRequest, clear_sqlmodel: Any
): # clear_sqlmodel ensures fresh DB state
module_name = request.param
full_module_name = f"docs_src.tutorial.indexes.{module_name}"
@ -31,16 +35,19 @@ def get_module(request: pytest.FixtureRequest, clear_sqlmodel: Any): # clear_sql
# These tests usually define engine in their main() or globally.
# We'll ensure it's set up for the test a standard way.
mod.sqlite_url = "sqlite://"
mod.engine = create_engine(mod.sqlite_url) # connect_args not typically in these non-FastAPI examples
mod.engine = create_engine(
mod.sqlite_url
) # connect_args not typically in these non-FastAPI examples
# Ensure tables are created. Some tutorials do it in main, others expect it externally.
# If mod.main() is expected to create tables, this might be redundant but safe.
# If Hero model is defined globally, SQLModel.metadata.create_all(mod.engine) can be used.
if hasattr(mod, "Hero") and hasattr(mod.Hero, "metadata"):
mod.Hero.metadata.create_all(mod.engine)
elif hasattr(mod, "SQLModel") and hasattr(mod.SQLModel, "metadata"): # Fallback if Hero specific metadata not found
mod.SQLModel.metadata.create_all(mod.engine)
mod.Hero.metadata.create_all(mod.engine)
elif hasattr(mod, "SQLModel") and hasattr(
mod.SQLModel, "metadata"
): # Fallback if Hero specific metadata not found
mod.SQLModel.metadata.create_all(mod.engine)
return mod
@ -83,23 +90,30 @@ def test_tutorial(print_mock: PrintMock, module: types.ModuleType):
found_indexes_simplified = []
for index in indexes:
found_indexes_simplified.append({
"name": index["name"],
"column_names": sorted(index["column_names"]), # Sort for consistency
"unique": index["unique"],
# Not including dialect_options as it can vary or be empty
})
found_indexes_simplified.append(
{
"name": index["name"],
"column_names": sorted(index["column_names"]), # Sort for consistency
"unique": index["unique"],
# Not including dialect_options as it can vary or be empty
}
)
expected_indexes_simplified = []
for index in expected_indexes:
expected_indexes_simplified.append({
"name": index["name"],
"column_names": sorted(index["column_names"]),
"unique": index["unique"],
})
expected_indexes_simplified.append(
{
"name": index["name"],
"column_names": sorted(index["column_names"]),
"unique": index["unique"],
}
)
for expected_index in expected_indexes_simplified:
assert expected_index in found_indexes_simplified, f"Expected index {expected_index['name']} not found or mismatch."
assert expected_index in found_indexes_simplified, (
f"Expected index {expected_index['name']} not found or mismatch."
)
assert len(found_indexes_simplified) == len(expected_indexes_simplified), \
assert len(found_indexes_simplified) == len(expected_indexes_simplified), (
f"Mismatch in number of indexes. Found: {len(found_indexes_simplified)}, Expected: {len(expected_indexes_simplified)}"
)