Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .github/workflows/model-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ on:
description: 'Extra pytest parameters (e.g. -k testname)'
required: false
default: ''
oasis_data_manager_branch:
description: 'oasis-data-manager git branch to install (leave empty to skip)'
required: false
default: ''
pytest_params:
description: 'Extra pytest parameters (e.g. -k testname)'
required: false
default: ''

jobs:
run-model-tests:
Expand Down
6 changes: 6 additions & 0 deletions PiWindAzure/docker-compose.azurite.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
services:
azurite:
image: mcr.microsoft.com/azure-storage/azurite
command: azurite-blob --blobHost 0.0.0.0
ports:
- "10000"
48 changes: 48 additions & 0 deletions tests/azurite_setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import os
from pathlib import Path

import pytest

REPO_ROOT = Path(__file__).parent.parent


def _seed_azurite(conn_str):
from azure.storage.blob import BlobServiceClient
client = BlobServiceClient.from_connection_string(conn_str)
try:
client.create_container("data")
except Exception:
pass
for src, prefix in [
(REPO_ROOT / "PiWind" / "model_data", "OasisPiWind/model_data/PiWind"),
(REPO_ROOT / "PiWind" / "keys_data", "OasisPiWind/keys_data/PiWind"),
]:
for f in Path(src).rglob("*"):
if f.is_file():
blob = f"{prefix}/{f.relative_to(src)}"
client.get_blob_client("data", blob).upload_blob(
f.read_bytes(), overwrite=True
)


@pytest.fixture(scope="session")
def azurite_service():
from testcontainers.core.container import DockerContainer
from testcontainers.core.waiting_utils import wait_for_logs

with DockerContainer("mcr.microsoft.com/azure-storage/azurite") \
.with_command("azurite-blob --blobHost 0.0.0.0") \
.with_exposed_ports(10000) as container:
wait_for_logs(container, "Azurite Blob service is successfully listening")
host = container.get_container_host_ip()
port = container.get_exposed_port(10000)
conn_str = (
f"DefaultEndpointsProtocol=http;"
f"AccountName=devstoreaccount1;"
f"AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OtO+kSHAHNaIQgFQAAFdtE0jDdqoiQqT6i0xqQpqHfNKOEFAAAABQk=;"
f"BlobEndpoint=http://{host}:{port}/devstoreaccount1;"
)
_seed_azurite(conn_str)
os.environ["AZURE_STORAGE_CONNECTION_STRING"] = conn_str
yield
os.environ.pop("AZURE_STORAGE_CONNECTION_STRING", None)
2 changes: 2 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import shutil
from pathlib import Path

pytest_plugins = ["tests.azurite_setup"]

import pandas as pd
import pytest

Expand Down
2 changes: 1 addition & 1 deletion tests/test_model_runs.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def _build_params():


@pytest.mark.parametrize("config_path", _build_params())
def test_model_run(config_path, tmp_path, check_results, update_results):
def test_model_run(config_path, tmp_path, check_results, update_results, azurite_service):
"""Run ``oasislmf model run`` for the given config and assert it succeeds."""
run_dir = tmp_path / "run"
cmd = [
Expand Down