Пример #1
0
def parameter_set(tmp_path, mocked_config):
    """Fake parameter set for tests."""
    directory = tmp_path / "wflow_testcase"
    directory.mkdir()
    config = directory / "wflow_sbm_nc.ini"
    # Trimmed down config from
    # https://github.com/openstreams/wflow/blob/master/examples/wflow_rhine_sbm_nc/wflow_sbm_NC.ini
    config_body = dedent("""[inputmapstacks]
        Precipitation = /inmaps/P
        EvapoTranspiration = /inmaps/PET
        Temperature = /inmaps/TEMP
        Inflow = /inmaps/IF

        [run]
        starttime=1991-02-01 00:00:00
        endtime=1991-03-01 00:00:00
        timestepsecs = 86400

        [framework]
        netcdfinput= inmaps.nc
    """)
    config.write_text(config_body)
    return ParameterSet(
        "wflow_testcase",
        directory=str(directory),
        config=str(config),
        target_model="wflow",
    )
Пример #2
0
 def test_correct_version(self, setup_config):
     ps = ParameterSet(
         name="justatest",
         directory="justatest",
         config="justatest/config.ini",
         target_model="mockedmodel",  # == lowered class name
         supported_model_versions={"0.4.2"},
     )
     m = MockedModel(parameter_set=ps)
     assert m.parameter_set == ps
Пример #3
0
    def test_unsupported_version(self, setup_config):
        ps = ParameterSet(
            name="justatest",
            directory="justatest",
            config="justatest/config.ini",
            target_model="mockedmodel",
            supported_model_versions={"1.2.3"},
        )
        with pytest.raises(ValueError) as excinfo:
            MockedModel(parameter_set=ps)

        expected = "Parameter set is not compatible with version"
        assert expected in str(excinfo.value)
Пример #4
0
    def test_any_version(self, caplog, setup_config):
        ps = ParameterSet(
            name="justatest",
            directory="justatest",
            config="justatest/config.ini",
            target_model="mockedmodel",  # == lowered class name
            supported_model_versions=set(),
        )
        with caplog.at_level(logging.INFO):
            MockedModel(parameter_set=ps)

        expected = "is not explicitly listed in the supported model versions"
        assert expected in caplog.text
Пример #5
0
    def test_wrong_model(self, setup_config):
        ps = ParameterSet(
            name="justatest",
            directory="justatest",
            config="justatest/config.ini",
            target_model="wrongmodel",
            supported_model_versions={"0.4.2"},
        )
        with pytest.raises(ValueError) as excinfo:
            MockedModel(parameter_set=ps)

        expected = "Parameter set has wrong target model"
        assert expected in str(excinfo.value)
Пример #6
0
 def parameter_set(self, tmp_path, mocked_config: Path):
     return ParameterSet(
         name="justatest",
         directory=str(tmp_path / "my-parameter-set"),
         config=mocked_config.name,
     )