diff --git a/.github/workflows/model-tests.yml b/.github/workflows/model-tests.yml index bc4bfa9..9d49c51 100644 --- a/.github/workflows/model-tests.yml +++ b/.github/workflows/model-tests.yml @@ -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: diff --git a/PiWindAzure/docker-compose.azurite.yml b/PiWindAzure/docker-compose.azurite.yml new file mode 100644 index 0000000..7669af5 --- /dev/null +++ b/PiWindAzure/docker-compose.azurite.yml @@ -0,0 +1,6 @@ +services: + azurite: + image: mcr.microsoft.com/azure-storage/azurite + command: azurite-blob --blobHost 0.0.0.0 + ports: + - "10000" diff --git a/tests/azurite_setup.py b/tests/azurite_setup.py new file mode 100644 index 0000000..1b8076f --- /dev/null +++ b/tests/azurite_setup.py @@ -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) diff --git a/tests/conftest.py b/tests/conftest.py index 7a57a2f..c38570e 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -3,6 +3,8 @@ import shutil from pathlib import Path +pytest_plugins = ["tests.azurite_setup"] + import pandas as pd import pytest diff --git a/tests/test_model_runs.py b/tests/test_model_runs.py index 673e3f0..5b198eb 100644 --- a/tests/test_model_runs.py +++ b/tests/test_model_runs.py @@ -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 = [