Files
life-echo/api/tests/test_alembic_revision_ids.py

26 lines
846 B
Python

from pathlib import Path
import re
REVISION_RE = re.compile(r'^revision: str = "([^"]+)"$', re.MULTILINE)
ALEMBIC_VERSION_NUM_MAX_LEN = 32
def test_alembic_revision_ids_fit_default_version_num_column() -> None:
versions_dir = Path(__file__).resolve().parent.parent / "alembic" / "versions"
too_long: list[tuple[str, int]] = []
for path in sorted(versions_dir.glob("*.py")):
text = path.read_text(encoding="utf-8")
match = REVISION_RE.search(text)
if match is None:
continue
revision = match.group(1)
if len(revision) > ALEMBIC_VERSION_NUM_MAX_LEN:
too_long.append((revision, len(revision)))
assert not too_long, (
"Alembic revision ids exceed the default alembic_version.version_num "
f"limit ({ALEMBIC_VERSION_NUM_MAX_LEN}): {too_long}"
)