diff --git a/tests/conftest.py b/tests/conftest.py index a67ba59d..66049dfa 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -57,18 +57,3 @@ def minio(local_ip): proc.wait() assert proc.returncode == 0 - - -@pytest.fixture -def recipes_version_ref(): - # FIXME: recipes version matrix is currently determined by github workflows matrix - # in the future, it should be set by pangeo-forge-runner venv feature? - pip_list = subprocess.check_output("pip list".split()).decode("utf-8").splitlines() - recipes_version = [ - p.split()[-1] for p in pip_list if p.startswith("pangeo-forge-recipes") - ][0] - # the recipes_version is a 3-element semantic version of form `0.A.B` where A is either minor - # version `9` or `10`. the test feedstock (pforgetest/gpcp-from-gcs-feedstock) has tags for - # each of these minor versions, of the format `0.A.x`, so we translate the installed version - # of pangeo-forge-recipes to one of the valid tags (either `0.9.x` or `0.10.x`) here. - return f"0.{recipes_version.split('.')[1]}.x" diff --git a/tests/integration/test_dataflow_integration.py b/tests/integration/test_dataflow_integration.py index 20a4f146..9b5aa54b 100644 --- a/tests/integration/test_dataflow_integration.py +++ b/tests/integration/test_dataflow_integration.py @@ -2,12 +2,19 @@ import subprocess import tempfile import time +from importlib.metadata import version import pytest import xarray as xr +from packaging.version import parse as parse_version -def test_dataflow_integration(recipes_version_ref): +def test_dataflow_integration(): + pfr_version = parse_version(version("pangeo-forge-recipes")) + if pfr_version >= parse_version("0.10"): + recipe_version_ref = "0.10.x" + else: + recipe_version_ref = "0.9.x" bucket = "gs://pangeo-forge-runner-ci-testing" config = { "Bake": { @@ -40,7 +47,7 @@ def test_dataflow_integration(recipes_version_ref): "--ref", # in the test feedstock, tags are named for the recipes version # which was used to write the recipe module - recipes_version_ref, + recipe_version_ref, "--json", "-f", f.name, @@ -93,8 +100,8 @@ def test_dataflow_integration(recipes_version_ref): # open the generated dataset with xarray! target_path = config["TargetStorage"]["root_path"].format(job_name=job_name) - if recipes_version_ref == "0.10.x": - # in pangeo-forge-recipes>=0.10.0, an additional `StoreToZarr.store_name` kwarg + if pfr_version >= parse_version("0.10"): + # in pangeo-forge-eecipes>=0.10.0, an additional `StoreToZarr.store_name` kwarg # is appended to the formatted root path at execution time. for ref `0.10.x`, # the value of that kwarg is "gpcp", so we append that here. target_path += "/gpcp" diff --git a/tests/unit/test_bake.py b/tests/unit/test_bake.py index 6f3752bf..08defa0f 100644 --- a/tests/unit/test_bake.py +++ b/tests/unit/test_bake.py @@ -2,9 +2,11 @@ import re import subprocess import tempfile +from importlib.metadata import version import pytest import xarray as xr +from packaging.version import parse as parse_version from pangeo_forge_runner.commands.bake import Bake @@ -50,9 +52,7 @@ def test_job_name_validation(job_name, raises): [None, None, "special-name-for-job"], ), ) -def test_gpcp_bake( - minio, recipe_id, expected_error, custom_job_name, recipes_version_ref -): +def test_gpcp_bake(minio, recipe_id, expected_error, custom_job_name): fsspec_args = { "key": minio["username"], "secret": minio["password"], @@ -86,6 +86,12 @@ def test_gpcp_bake( if custom_job_name: config["Bake"].update({"job_name": custom_job_name}) + pfr_version = parse_version(version("pangeo-forge-recipes")) + if pfr_version >= parse_version("0.10"): + recipe_version_ref = "0.10.x" + else: + recipe_version_ref = "0.9.x" + with tempfile.NamedTemporaryFile("w", suffix=".json") as f: json.dump(config, f) f.flush() @@ -97,7 +103,7 @@ def test_gpcp_bake( "--ref", # in the test feedstock, tags are named for the recipes version # which was used to write the recipe module - recipes_version_ref, + recipe_version_ref, "--json", "-f", f.name, @@ -126,7 +132,8 @@ def test_gpcp_bake( # root path itself. This is a compatibility break vs the previous # versions of pangeo-forge-recipes. https://github.com/pangeo-forge/pangeo-forge-recipes/pull/495 # has more information - if recipes_version_ref == "0.10.x": + + if pfr_version >= parse_version("0.10"): zarr_store_path = config["TargetStorage"]["root_path"] + "gpcp/" else: zarr_store_path = config["TargetStorage"]["root_path"]