Skip to content

Commit

Permalink
do some things
Browse files Browse the repository at this point in the history
  • Loading branch information
ranchodeluxe committed Feb 17, 2024
1 parent 6c20f48 commit 08d3565
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 56 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/dataflow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ jobs:
- name: Install dependencies & our package
run: |
python -m pip install --upgrade pip
python -m pip install xarray
python -m pip install -e .[test]
- name: 'Run Dataflow Integration Test'
run: |
pytest -vvvxs tests/integration/test_dataflow_integration.py
pytest -vvvxs tests/integration/test_dataflow_integration.py \
--recipesversion=${{ matrix.recipes-version }}
4 changes: 2 additions & 2 deletions .github/workflows/flink.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ jobs:
- name: Install dependencies & our package
run: |
python -m pip install --upgrade pip
python -m pip install xarray
python -m pip install -e .[test]
- name: Set up min.io as a k3s service
Expand All @@ -135,7 +134,8 @@ jobs:
pytest -vvv -s --cov=pangeo_forge_runner tests/integration/flink/test_flink_integration.py \
--flinkversion=${{ matrix.flink-version }} \
--pythonversion=${{ matrix.python-version }} \
--beamversion=$beamversion
--beamversion=$beamversion \
--recipesversion=${{ matrix.recipes-version }}
- name: Dump logs from pods after failure so we don't have ssh
if: steps.testrunner.outcome == 'failure'
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,10 @@ jobs:
run: |
python -m pip install --upgrade pip
python -m pip install -e ".[test]"
python -m pip install -U ${{ matrix.recipes-version }}
- name: Test with pytest
run: |
pytest -vvv -s --cov=pangeo_forge_runner tests/unit/
pytest -vvv -s --cov=pangeo_forge_runner tests/unit/ --recipesversion=${{ matrix.recipes-version }}
- name: Upload Coverage to Codecov
uses: codecov/codecov-action@v2
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ test = [
"s3fs",
# used in some unit tests
"apache-beam",
"xarray",
]

[project.scripts]
Expand Down
11 changes: 8 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,14 @@ def minio_service():


def pytest_addoption(parser):
parser.addoption("--flinkversion", action="store", default="1.16")
parser.addoption("--pythonversion", action="store", default="3.9")
parser.addoption("--beamversion", action="store", default="2.47.0")
parser.addoption("--flinkversion", action="store")
parser.addoption("--pythonversion", action="store")
parser.addoption("--beamversion", action="store")
parser.addoption("--recipesversion", action="store")

@pytest.fixture
def recipesversion(request):
return request.config.getoption("--recipesversion")


@pytest.fixture
Expand Down
5 changes: 2 additions & 3 deletions tests/integration/flink/test_flink_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import subprocess
import tempfile
import time
from importlib.metadata import version
from pathlib import Path

import xarray as xr
Expand All @@ -11,14 +10,14 @@
TEST_DATA_DIR = Path(__file__).parent.parent.parent / "test-data"


def test_flink_bake(minio_service, flinkversion, pythonversion, beamversion):
def test_flink_bake(minio_service, flinkversion, pythonversion, beamversion, recipesversion):
fsspec_args = {
"key": minio_service["username"],
"secret": minio_service["password"],
"client_kwargs": {"endpoint_url": minio_service["endpoint"]},
}

pfr_version = parse_version(version("pangeo-forge-recipes"))
pfr_version = parse_version(recipesversion)
if pfr_version >= parse_version("0.10"):
recipe_version_ref = "0.10.x"

Expand Down
5 changes: 2 additions & 3 deletions tests/integration/test_dataflow_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import sys
import tempfile
import time
from importlib.metadata import version
from pathlib import Path

import pytest
Expand All @@ -13,11 +12,11 @@
TEST_DATA_DIR = Path(__file__).parent.parent / "test-data"


def test_dataflow_integration():
def test_dataflow_integration(recipesversion):
python_version = (
f"{sys.version_info.major}.{sys.version_info.minor}.{sys.version_info.micro}"
)
pfr_version = parse_version(version("pangeo-forge-recipes"))
pfr_version = parse_version(recipesversion)
if pfr_version >= parse_version("0.10"):
recipe_version_ref = "0.10.x"
else:
Expand Down
89 changes: 48 additions & 41 deletions tests/unit/test_bake.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,45 +16,45 @@
TEST_DATA_DIR = Path(__file__).parent.parent / "test-data"


@pytest.fixture
def recipes_uninstalled():
"""Uninstall `pangeo-forge-recipes` for `test_bake_requires_recipes_installed`."""
# first confirm that it's installed to begin with
assert "pangeo-forge-recipes" in [d.metadata["Name"] for d in distributions()]
# and capture the version, which we'll reinstall after the test
recipes_version = parse_version(version("pangeo-forge-recipes"))
# now uninstall it
uninstall = subprocess.run(
f"{sys.executable} -m pip uninstall pangeo-forge-recipes -y".split()
)
assert uninstall.returncode == 0
assert "pangeo-forge-recipes" not in [d.metadata["Name"] for d in distributions()]
# and yield to the test
yield True
# test is complete, now reinstall pangeo-forge-recipes in the test env
reinstall = subprocess.run(
f"{sys.executable} -m pip install pangeo-forge-recipes=={recipes_version}".split()
)
assert reinstall.returncode == 0
# make sure it's there, and in the expected version
assert "pangeo-forge-recipes" in [d.metadata["Name"] for d in distributions()]
assert parse_version(version("pangeo-forge-recipes")) == recipes_version


def test_bake_requires_recipes_installed(recipes_uninstalled):
"""`pangeo-forge-runner` does not require `pangeo-forge-recipes` to be installed,
but `pangeo-forge-recipes` *is* required to use the `bake` command, so test that
we get a descriptive error if we try to invoke this command without it installed.
"""
assert recipes_uninstalled
bake = Bake()
bake.repo = str(TEST_DATA_DIR / "gpcp-from-gcs")
bake.feedstock_subdir = "feedstock-0.10.x-norequirements"
with pytest.raises(
ValueError,
match="To use the 'bake' command, the packages .* must be listed in your recipe's requirements.txt",
):
bake.start()
# @pytest.fixture
# def recipes_uninstalled():
# """Uninstall `pangeo-forge-recipes` for `test_bake_requires_recipes_installed`."""
# # first confirm that it's installed to begin with
# assert "pangeo-forge-recipes" in [d.metadata["Name"] for d in distributions()]
# # and capture the version, which we'll reinstall after the test
# recipes_version = parse_version(version("pangeo-forge-recipes"))
# # now uninstall it
# uninstall = subprocess.run(
# f"{sys.executable} -m pip uninstall pangeo-forge-recipes -y".split()
# )
# assert uninstall.returncode == 0
# assert "pangeo-forge-recipes" not in [d.metadata["Name"] for d in distributions()]
# # and yield to the test
# yield True
# # test is complete, now reinstall pangeo-forge-recipes in the test env
# reinstall = subprocess.run(
# f"{sys.executable} -m pip install pangeo-forge-recipes=={recipes_version}".split()
# )
# assert reinstall.returncode == 0
# # make sure it's there, and in the expected version
# assert "pangeo-forge-recipes" in [d.metadata["Name"] for d in distributions()]
# assert parse_version(version("pangeo-forge-recipes")) == recipes_version
#
#
# def test_bake_requires_recipes_installed(recipes_uninstalled):
# """`pangeo-forge-runner` does not require `pangeo-forge-recipes` to be installed,
# but `pangeo-forge-recipes` *is* required to use the `bake` command, so test that
# we get a descriptive error if we try to invoke this command without it installed.
# """
# assert recipes_uninstalled
# bake = Bake()
# bake.repo = str(TEST_DATA_DIR / "gpcp-from-gcs")
# bake.feedstock_subdir = "feedstock-0.10.x-norequirements"
# with pytest.raises(
# ValueError,
# match="To use the 'bake' command, the packages .* must be listed in your recipe's requirements.txt",
# ):
# bake.start()


@pytest.mark.parametrize(
Expand Down Expand Up @@ -108,8 +108,15 @@ def test_container_name_validation(container_image, raises):


@pytest.fixture(params=["recipe_object", "dict_object"])
def recipes_version_ref(request):
pfr_version = parse_version(version("pangeo-forge-recipes"))
def recipes_version_ref(request, recipesversion):
# .github/workflows/unit-test.yml provides
# `--recipesversion` arg during the pytest cli call
# but if not provided (e.g. in local runs) then alert
if not recipesversion:
raise ValueError("running these tests requires you "
"pass `--recipesversion='<version-string>'` as a `pytest` arg")

pfr_version = parse_version(recipesversion)
if pfr_version >= parse_version("0.10"):
recipes_version_ref = "0.10.x"
else:
Expand Down

0 comments on commit 08d3565

Please sign in to comment.