def test_config_object(): """Test that the config is of the right type.""" assert isinstance(CFG, MutableMapping) del CFG["output_dir"] assert "output_dir" not in CFG CFG.reload() assert "output_dir" in CFG
def test_no_config(self, tmp_path): # Load default config shipped with package CFG["ewatercycle_config"] = DEFAULT_CONFIG CFG.reload() with pytest.raises(ValueError) as excinfo: available_parameter_sets() assert "No configuration file found" in str(excinfo.value)
def test_download_example_parameter_sets(mocked_download, setup_config, tmp_path): download_example_parameter_sets() assert mocked_download.call_count > 0 assert CFG["ewatercycle_config"].read_text() == CFG.dump_to_yaml() assert len(CFG["parameter_sets"]) > 0
def download_example_parameter_sets(skip_existing=True): """Downloads all of the example parameter sets and adds them to the config_file. Downloads to `parameterset_dir` directory defined in :py:data:`ewatercycle.config.CFG`. Args: skip_existing: When true will not download any parameter set which already has a local directory. When false will raise ValueError exception when parameter set already exists. """ examples = example_parameter_sets() i = 0 for example in examples.values(): example.download(skip_existing) example.to_config() i += 1 logger.info(f"{i} example parameter sets were downloaded") try: config_file = CFG.save_to_file() logger.info(f"Saved parameter sets to configuration file {config_file}") except OSError as e: raise OSError( f"Failed to write parameter sets to configuration file. " f"Manually save content below to {USER_HOME_CONFIG} " f"or {SYSTEM_CONFIG} file: {linesep}" f"{CFG.dump_to_yaml()}" ) from e
def __init__( self, name: str, directory: str, config: str, doi="N/A", target_model="generic", supported_model_versions: Optional[Set[str]] = None, ): self.name = name self.directory = to_absolute_path(directory, parent=CFG.get("parameterset_dir"), must_be_in_parent=False) self.config = to_absolute_path(config, parent=CFG.get("parameterset_dir"), must_be_in_parent=False) self.doi = doi self.target_model = target_model self.supported_model_versions = (set() if supported_model_versions is None else supported_model_versions)
def _set_singularity_image(self): images = {"2020.11": "ewatercycle-marrmot-grpc4bmi_2020.11.sif"} if CFG.get("singularity_dir"): self.singularity_image = CFG["singularity_dir"] / images[ self.version]
def setup_config(tmp_path): CFG["parameterset_dir"] = tmp_path CFG["ewatercycle_config"] = tmp_path / "ewatercycle.yaml" yield CFG CFG["ewatercycle_config"] = DEFAULT_CONFIG CFG.reload()
def setup_config(tmp_path): CFG["parameterset_dir"] = tmp_path yield CFG # Rollback changes made to CFG by tests CFG.reload()