| import os | |
| import sqlite3 | |
| import pytest | |
| from alembic import command | |
| from alembic.config import Config | |
| def _make_config(db_path: str) -> Config: | |
| root = os.path.join(os.path.dirname(__file__), "../..") | |
| cfg = Config(os.path.abspath(os.path.join(root, "alembic.ini"))) | |
| cfg.set_main_option("script_location", os.path.abspath(os.path.join(root, "alembic_db"))) | |
| cfg.set_main_option("sqlalchemy.url", f"sqlite:///{db_path}") | |
| return cfg | |
| def _user_tables(db_path: str) -> set[str]: | |
| conn = sqlite3.connect(db_path) | |
| try: | |
| return { | |
| row[0] | |
| for row in conn.execute( | |
| "SELECT name FROM sqlite_master WHERE type='table' " | |
| "AND name NOT LIKE 'alembic%' AND name NOT LIKE 'sqlite%'" | |
| ) | |
| } | |
| finally: | |
| conn.close() | |
| def db_at_head(tmp_path): | |
| db_path = str(tmp_path / "roundtrip.db") | |
| cfg = _make_config(db_path) | |
| command.upgrade(cfg, "head") | |
| yield cfg, db_path | |
| def test_downgrade_to_base_empties_the_schema(db_at_head): | |
| cfg, db_path = db_at_head | |
| assert _user_tables(db_path), "fixture did not build a schema" | |
| command.downgrade(cfg, "base") | |
| assert _user_tables(db_path) == set() | |
| def test_upgrade_to_head_again_after_downgrade_to_base(db_at_head): | |
| cfg, db_path = db_at_head | |
| expected = _user_tables(db_path) | |
| command.downgrade(cfg, "base") | |
| command.upgrade(cfg, "head") | |
| assert _user_tables(db_path) == expected | |
Xet Storage Details
- Size:
- 1.48 kB
- Xet hash:
- a350d294c462c4d0bedb1dc334d2bf5cf59684bd8bc53c4fee60bc7a3d8240bf
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.