From 04346673219efa0b5a9a6f77ddac6bc2ae5f12e2 Mon Sep 17 00:00:00 2001 From: mcflugen Date: Thu, 3 Nov 2022 10:00:57 -0600 Subject: [PATCH] add tests for combinations of components --- tests/test_sequence_model.py | 89 +++++++++++++++++++++++++++++++----- 1 file changed, 78 insertions(+), 11 deletions(-) diff --git a/tests/test_sequence_model.py b/tests/test_sequence_model.py index 6655cb3..2dd8869 100644 --- a/tests/test_sequence_model.py +++ b/tests/test_sequence_model.py @@ -1,10 +1,25 @@ import os import shutil +from itertools import chain, combinations, permutations +import pytest from landlab.core import load_params from sequence.sequence_model import SequenceModel +try: + import tomllib +except ModuleNotFoundError: + import tomli as tomllib + +ALL_PROCESSES = [ + "sea_level", + "subsidence", + "compaction", + "submarine_diffusion", + "flexure", +] + # @pytest.mark.skip("test fails with a core dump from numpy") def test_marmara(tmpdir, datadir): @@ -15,17 +30,69 @@ def test_marmara(tmpdir, datadir): grid = SequenceModel.load_grid(params["grid"], bathymetry=params["bathymetry"]) processes = SequenceModel.load_processes( grid, - processes=params.get( - "processes", - [ - "sea_level", - "subsidence", - "compaction", - "submarine_diffusion", - "fluvial", - "flexure", - ], - ), + processes=params.get("processes", ALL_PROCESSES), + context=params, + ) + model = SequenceModel( + grid, clock=params["clock"], processes=processes, output=params["output"] + ) + model.run() + + assert os.path.isfile("marmara.nc") + + +@pytest.mark.parametrize("processes", permutations(ALL_PROCESSES)) +def test_component_ordering(tmpdir, datadir, processes): + with tmpdir.as_cwd(): + for fname in datadir.iterdir(): + shutil.copy(str(datadir / fname), ".") + with open("marmara.toml", "rb") as fp: + params = tomllib.load(fp)["sequence"] + grid = SequenceModel.load_grid(params["grid"], bathymetry=params["bathymetry"]) + processes = SequenceModel.load_processes( + grid, + processes=processes, + context=params, + ) + model = SequenceModel( + grid, clock=params["clock"], processes=processes, output=params["output"] + ) + model.run() + + assert os.path.isfile("marmara.nc") + + +@pytest.mark.parametrize( + "processes", + chain( + combinations(ALL_PROCESSES, 0), + combinations(ALL_PROCESSES, 1), + combinations(ALL_PROCESSES, 2), + combinations(ALL_PROCESSES, 3), + combinations(ALL_PROCESSES, 4), + ), + ids=[ + "-".join(combo) + for combo in chain( + combinations(ALL_PROCESSES, 0), + combinations(ALL_PROCESSES, 1), + combinations(ALL_PROCESSES, 2), + combinations(ALL_PROCESSES, 3), + combinations(ALL_PROCESSES, 4), + ) + ], +) +def test_component_combos(tmpdir, datadir, processes): + + with tmpdir.as_cwd(): + for fname in datadir.iterdir(): + shutil.copy(str(datadir / fname), ".") + with open("marmara.toml", "rb") as fp: + params = tomllib.load(fp)["sequence"] + grid = SequenceModel.load_grid(params["grid"], bathymetry=params["bathymetry"]) + processes = SequenceModel.load_processes( + grid, + processes=processes, context=params, ) model = SequenceModel(