Skip to content

Commit

Permalink
WIP - Add backend tests on Windows to tests workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
treiher committed Sep 19, 2023
1 parent 4065fab commit a8475ec
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 11 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,31 @@ jobs:
run: |
make test_backend
test_backend_windows:
name: Backend Tests on Windows
runs-on: windows-2022
strategy:
fail-fast: false
matrix:
python-version: ["3.11"]
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
cache: pip
cache-dependency-path: |
setup.cfg
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install --user -e .[devel]
echo "PYTHONPATH=$PWD" >> $GITHUB_ENV
- name: Test
run: |
make test_backend
test_e2e:
name: End-to-End Tests
runs-on: ubuntu-20.04
Expand Down
2 changes: 1 addition & 1 deletion tests/backend/api_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

@pytest.fixture(name="client")
def fixture_client(tmp_path: Path) -> Generator[Client, None, None]:
app.config["DATABASE"] = f"sqlite:///{tmp_path}/valens.db"
app.config["DATABASE"] = rf"sqlite:///{tmp_path}/valens.db"
app.config["SECRET_KEY"] = b"TEST_KEY"
app.config["TESTING"] = True

Expand Down
2 changes: 1 addition & 1 deletion tests/backend/assets_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

@pytest.fixture(name="client")
def fixture_client(tmp_path: Path) -> Generator[Client, None, None]:
app.config["DATABASE"] = f"sqlite:///{tmp_path}/valens.db"
app.config["DATABASE"] = rf"sqlite:///{tmp_path}/valens.db"
app.config["SECRET_KEY"] = b"TEST_KEY"
app.config["TESTING"] = True

Expand Down
2 changes: 1 addition & 1 deletion tests/backend/database_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
@pytest.fixture(name="test_db")
def fixture_test_db(tmp_path: Path) -> Generator[Path, None, None]:
db_file = tmp_path / "db"
app.config["DATABASE"] = f"sqlite:///{db_file}"
app.config["DATABASE"] = rf"sqlite:///{db_file}"
app.config["SECRET_KEY"] = b"TEST_KEY"
app.config["TESTING"] = True

Expand Down
2 changes: 1 addition & 1 deletion tests/backend/demo_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@

def test_run(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.setattr(app, "run", lambda x, y: None)
demo.run(f"sqlite:///{tmp_path}/db")
demo.run(rf"sqlite:///{tmp_path}/db")
8 changes: 4 additions & 4 deletions tests/backend/migrations_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def assert_db_equality(
tmp_path: Path, source: str, target: str, infix: str, migrate: Callable[[], None]
) -> None:
test_db = tmp_path / "test.db"
app.config["DATABASE"] = f"sqlite:///{test_db}"
app.config["DATABASE"] = rf"sqlite:///{test_db}"

connection = sqlite3.connect(test_db)
connection.executescript((DATA_DIR / f"{source}.sql").read_text(encoding="utf-8"))
Expand All @@ -48,7 +48,7 @@ def test_completeness(tmp_path: Path) -> None:

cfg = Config("alembic.ini")
test_db = f"/{tmp_path}/valens_test.db"
app.config["DATABASE"] = f"sqlite://{test_db}"
app.config["DATABASE"] = rf"sqlite://{test_db}"

connection = sqlite3.connect(test_db)
connection.executescript(BASE_SCHEMA.read_text(encoding="utf-8"))
Expand Down Expand Up @@ -90,7 +90,7 @@ def constraints(connection: sqlite3.Connection) -> list[str]:

with app.app_context():
migrations_db = f"{tmp_path}/migrations.db"
app.config["DATABASE"] = f"sqlite:///{migrations_db}"
app.config["DATABASE"] = rf"sqlite:///{migrations_db}"

connection = sqlite3.connect(migrations_db)
connection.executescript(BASE_SCHEMA.read_text(encoding="utf-8"))
Expand All @@ -100,7 +100,7 @@ def constraints(connection: sqlite3.Connection) -> list[str]:
migrated_constraints = constraints(connection)

models_db = f"{tmp_path}/models.db"
app.config["DATABASE"] = f"sqlite:///{models_db}"
app.config["DATABASE"] = rf"sqlite:///{models_db}"

db.init()
connection = sqlite3.connect(models_db)
Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def alembic_config() -> dict[str, str]:
@pytest.fixture()
def alembic_engine() -> object:
with NamedTemporaryFile() as tmp_file:
app.config["DATABASE"] = f"sqlite:///{tmp_file.name}"
app.config["DATABASE"] = rf"sqlite:///{tmp_file.name}"
with app.app_context():
db.init()
yield db.get_engine()
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/web_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def _fixture_backend() -> Generator[None, None, None]:
config = create_config_file(data_dir, db_file)

with app.app_context():
app.config["DATABASE"] = f"sqlite:///{db_file}"
app.config["DATABASE"] = rf"sqlite:///{db_file}"
app.config["SECRET_KEY"] = b"TEST_KEY"
tests.utils.init_db_data()

Expand Down
2 changes: 1 addition & 1 deletion valens/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def check_config_file(environ: dict[str, str]) -> None:
def create_config_file(config_directory: Path, database_file: Path) -> Path:
config = config_directory / "config.py"
config.write_text(
f"DATABASE = 'sqlite:///{database_file}'\nSECRET_KEY = {os.urandom(24)!r}\n",
f"DATABASE = r'sqlite:///{database_file}'\nSECRET_KEY = {os.urandom(24)!r}\n",
encoding="utf-8",
)
return config
1 change: 1 addition & 0 deletions valens/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def upgrade_lock_file() -> Path:


def get_engine() -> Engine:
print("get_engine()", current_app.config["DATABASE"])
config.check_app_config()
db_dir().mkdir(exist_ok=True)
return create_engine(current_app.config["DATABASE"])
Expand Down

0 comments on commit a8475ec

Please sign in to comment.