Skip to content

Commit

Permalink
♻️ Clean up migration tests (#73)
Browse files Browse the repository at this point in the history
* ♻️ Clean up

* 🎨 Re-organize

* 💚 Fix

* ♻️ More cleaning

* ⬆️ Upgrade lndb-setup

* 💚 Fix

* ♻️ Clean up noxfile more
  • Loading branch information
falexwolf authored Dec 8, 2022
1 parent 4531bfd commit 9f66efa
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 58 deletions.
1 change: 0 additions & 1 deletion lnschema_core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
dev
link
"""
# This is lnschema-module yvzi.
_schema_id = "yvzi"
_name = "core"
_migration = "db1df7b2aaad"
Expand Down
47 changes: 7 additions & 40 deletions noxfile.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,11 @@
import os
from pathlib import Path
from time import sleep

import nox
from lndb_setup._clone import setup_local_test_postgres

# from lndb_setup._nox_tools import setup_test_instances_from_main_branch
# from lndb_setup._test_migrate import model_definitions_match_ddl
from lndb_setup.test.nox import (
build_docs,
login_testuser1,
setup_test_instances_from_main_branch,
)

nox.options.reuse_existing_virtualenvs = True
nox.options.error_on_external_run = False
nox.options.default_venv_backend = None


def setup_test_instances_from_main_branch(session):
login_user_1 = "lndb login testuser1@lamin.ai --password cEvcwMJFX4OwbsYVaMt2Os6GxxGgDUlBGILs2RyS" # noqa
session.run(*(login_user_1.split(" ")), external=True)
# init a test instance from the main branch
if "GITHUB_BASE_REF" in os.environ and os.environ["GITHUB_BASE_REF"] != "":
session.run("git", "checkout", os.environ["GITHUB_BASE_REF"], external=True)
# install the current package from main
# currently not needed
# session.install(".")
# session.run(*"lndb init --storage testdb".split(" "), external=True)
# postgres test instance
url = setup_local_test_postgres()
sleep(2)
session.run(*f"lndb init --storage pgtest --db {url}".split(" "), external=True)
# go back to the PR branch
if "GITHUB_HEAD_REF" in os.environ and os.environ["GITHUB_HEAD_REF"] != "":
session.run("git", "checkout", os.environ["GITHUB_HEAD_REF"], external=True)


@nox.session(python=["3.7", "3.8", "3.9", "3.10", "3.11"])
Expand All @@ -41,16 +17,9 @@ def lint(session: nox.Session) -> None:

@nox.session(python=["3.7", "3.8", "3.9", "3.10", "3.11"])
def build(session):
login_testuser1(session)
setup_test_instances_from_main_branch(session)
session.install(".[dev,test]")
# do not test sqlite
# try:
# # cannot run from within pytest right now
# model_definitions_match_ddl("lnschema_core", dialect_name="sqlite")
# except Exception as e:
# print(e)
# url = "postgresql://postgres:pwd@0.0.0.0:5432/pgtest"
# session.run(*f"lndb init --storage pgtest --db {url}".split(" "))
session.run(
"pytest",
"-s",
Expand All @@ -59,6 +28,4 @@ def build(session):
"--cov-report=term-missing",
)
session.run("coverage", "xml")
prefix = "." if Path("./lndocs").exists() else ".."
session.install(f"{prefix}/lndocs")
session.run("lndocs")
build_docs(session)
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ dev = [
test = [
"pytest>=6.0",
"pytest-cov",
"lndb_setup>=0.22.2",
"lndb_setup>=0.23.1",
"pytest_alembic",
]

Expand Down
32 changes: 16 additions & 16 deletions tests/test_migrations.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
import yaml # type: ignore
from lndb_setup._test_migrate import migrate_test, model_definitions_match_ddl
from lndb_setup.test import (
get_package_name,
migrate_clones,
migration_id_is_consistent,
model_definitions_match_ddl,
)

with open("./lamin-project.yaml") as f:
package_name = yaml.safe_load(f)["package_name"]
package_name = get_package_name()


# we can't run both the postgres and the sqlite test from the same process
# right now as it seems to have a strange side effect on how indexes
# are discovered, hence, we run this in the noxfile
# def test_model_definitions_match_ddl_sqlite():
# model_definitions_match_ddl(package_name, dialect_name="sqlite")
def test_migration_id_is_consistent():
assert migration_id_is_consistent(package_name)


def test_model_definitions_match_ddl_postgres():
model_definitions_match_ddl(package_name, dialect_name="postgres")
model_definitions_match_ddl(package_name, dialect_name="postgresql")


def test_migrate_sqlite():
results = migrate_test(package_name, n_instances=1, dialect_name="sqlite")
def test_migrate_clones_sqlite():
results = migrate_clones(package_name, n_instances=1, dialect_name="sqlite")
if "migrate-failed" in results:
raise RuntimeError("Migration failed.")
raise RuntimeError("Migration e2e test failed.")


# def test_migrate_postgres():
# results = migrate_test(package_name, n_instances=1, dialect_name="postgresql")
# def test_migrate_clones_postgres():
# results = migrate_clones(package_name, n_instances=1, dialect_name="postgresql")
# if "migrate-failed" in results:
# raise RuntimeError("Migration failed.")
# raise RuntimeError("Migration e2e test failed.")

0 comments on commit 9f66efa

Please sign in to comment.