✅ Add tests
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
from pathlib import Path
|
||||
|
||||
from ...conftest import coverage_run
|
||||
|
||||
|
||||
def test_create_db_and_table(cov_tmp_path: Path):
|
||||
module = "docs_src.tutorial.create_db_and_table.tutorial001"
|
||||
result = coverage_run(module=module, cwd=cov_tmp_path)
|
||||
assert "BEGIN" in result.stdout
|
||||
assert 'PRAGMA main.table_info("hero")' in result.stdout
|
||||
assert "CREATE TABLE hero (" in result.stdout
|
||||
assert "id INTEGER," in result.stdout
|
||||
assert "name VARCHAR NOT NULL," in result.stdout
|
||||
assert "secret_name VARCHAR NOT NULL," in result.stdout
|
||||
assert "age INTEGER," in result.stdout
|
||||
assert "PRIMARY KEY (id)" in result.stdout
|
||||
assert ")" in result.stdout
|
||||
assert "COMMIT" in result.stdout
|
||||
@@ -0,0 +1,15 @@
|
||||
from pathlib import Path
|
||||
|
||||
from sqlalchemy import inspect
|
||||
from sqlalchemy.engine.reflection import Inspector
|
||||
from sqlmodel import create_engine
|
||||
|
||||
|
||||
def test_create_db_and_table(clear_sqlmodel):
|
||||
from docs_src.tutorial.create_db_and_table import tutorial002 as mod
|
||||
|
||||
mod.sqlite_url = "sqlite://"
|
||||
mod.engine = create_engine(mod.sqlite_url)
|
||||
mod.create_db_and_tables()
|
||||
insp: Inspector = inspect(mod.engine)
|
||||
assert insp.has_table(str(mod.Hero.__tablename__))
|
||||
@@ -0,0 +1,13 @@
|
||||
from sqlalchemy import inspect
|
||||
from sqlalchemy.engine.reflection import Inspector
|
||||
from sqlmodel import create_engine
|
||||
|
||||
|
||||
def test_create_db_and_table(clear_sqlmodel):
|
||||
from docs_src.tutorial.create_db_and_table import tutorial003 as mod
|
||||
|
||||
mod.sqlite_url = "sqlite://"
|
||||
mod.engine = create_engine(mod.sqlite_url)
|
||||
mod.create_db_and_tables()
|
||||
insp: Inspector = inspect(mod.engine)
|
||||
assert insp.has_table(str(mod.Hero.__tablename__))
|
||||
Reference in New Issue
Block a user