Skip to content

Commit

Permalink
Load docker image from test config file instead of hardcoded
Browse files Browse the repository at this point in the history
  • Loading branch information
BSchilperoort committed Aug 28, 2024
1 parent d82af5e commit 81b820b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
3 changes: 2 additions & 1 deletion PyStemmusScope/bmi/implementation.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
from bmipy.bmi import Bmi
from PyStemmusScope.bmi.utils import InapplicableBmiMethods
from PyStemmusScope.bmi.utils import nested_set
from PyStemmusScope.bmi.variable_reference import VARIABLES, BmiVariable
from PyStemmusScope.bmi.variable_reference import VARIABLES
from PyStemmusScope.bmi.variable_reference import BmiVariable
from PyStemmusScope.config_io import read_config


Expand Down
20 changes: 15 additions & 5 deletions tests/test_bmi_docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from PyStemmusScope import forcing_io
from PyStemmusScope import soil_io
from PyStemmusScope.bmi.docker_utils import pull_image
from PyStemmusScope.bmi.implementation import MODEL_VARNAMES
from PyStemmusScope.bmi.implementation import StemmusScopeBmi
from . import data_folder

Expand Down Expand Up @@ -39,13 +40,14 @@
# fmt: on


def docker_available():
def docker_available(cfg_file):
try:
docker.APIClient()

config = config_io.read_config(cfg_file)
# Github Actions windows runners couldn't pull the image:
if platform.system() == "Windows":
pull_image("ghcr.io/ecoextreml/stemmus_scope:1.5.0")
pull_image(config["DockerImage"])

return True
except docker.errors.DockerException as err:
Expand Down Expand Up @@ -144,7 +146,7 @@ def updated_model(uninitialized_model, prepare_data_config):
model.finalize()


@pytest.mark.skipif(not docker_available(), reason="Docker not available")
@pytest.mark.skipif(not docker_available(cfg_file), reason="Docker not available")
class TestUninitialized:
def test_component_name(self, uninitialized_model):
assert uninitialized_model.get_component_name() == "STEMMUS_SCOPE"
Expand All @@ -168,7 +170,7 @@ def test_initialize(self, uninitialized_model, prepare_data_config):
uninitialized_model.initialize(str(prepare_data_config))


@pytest.mark.skipif(not docker_available(), reason="Docker not available")
@pytest.mark.skipif(not docker_available(cfg_file), reason="Docker not available")
class TestInitializedModel:
def test_input_item(self, initialized_model):
assert isinstance(initialized_model.get_input_item_count(), int)
Expand Down Expand Up @@ -218,7 +220,7 @@ def test_model_update(self, initialized_model):
initialized_model.update()


@pytest.mark.skipif(not docker_available(), reason="Docker not available")
@pytest.mark.skipif(not docker_available(cfg_file), reason="Docker not available")
class TestUpdatedModel:
# Many of these should be available after init
def test_get_current_time(self, updated_model):
Expand Down Expand Up @@ -295,3 +297,11 @@ def test_itemsize(self, updated_model):

def test_get_var_nbytes(self, updated_model):
assert updated_model.get_var_nbytes("soil_temperature") == 8 * 55

@pytest.mark.parametrize("varname", MODEL_VARNAMES)
def test_get_vars(self, updated_model: StemmusScopeBmi, varname):
dest = np.zeros(
shape=updated_model.get_grid_size(updated_model.get_var_grid(varname)),
dtype=updated_model.get_var_type(varname),
)
updated_model.get_value(varname, dest)

0 comments on commit 81b820b

Please sign in to comment.