def test_class_loads_root_task_type_correctly(self, minimal_yaml_dict): """Root tasks are checked for validity when accessing the :attr:`ScenarionConfig.root_class` attirbute.""" task_name = "serial", "parallel" minimal_yaml_dict["scenario"] = {task_name: {}} config = ScenarioConfig(minimal_yaml_dict) self.fail("Not testable due to cyclic import issue!")
def __init__( self, yaml_path: pathlib.Path, data_path: pathlib.Path, environment: EnvironmentConfig, ) -> None: self._scenario_dir = None self.path = yaml_path # Use the scenario file as jinja template and only parse the yaml, afterwards. with yaml_path.open() as f: yaml_template = jinja2.Template(f.read(), undefined=jinja2.StrictUndefined) rendered_yaml = yaml_template.render(**asdict(environment)) self._loaded = yaml.safe_load(rendered_yaml) self.settings = SettingsConfig(self._loaded, environment) self.settings.sp_root_dir = data_path self.token = TokenConfig(self._loaded, self.scenario_dir.joinpath("token.info")) deploy_token = self.token.address is None self.nodes = NodesConfig( self._loaded, environment="development" if deploy_token else None) self.scenario = ScenarioConfig(self._loaded) # If the environment sets a list of matrix servers, the nodes must not # choose other servers, so let's set the first server from the list as # default. self.nodes.dict["default_options"][ "matrix-server"] = environment.matrix_servers[0] self.nodes.dict["default_options"][ "environment-type"] = environment.environment_type
def test_class_returns_root_config_correctly_regardless_of_root_task_name( self, root_task_key, minimal_yaml_dict): """:attr:`ScenarioConfig.root_config` returns config without checking task_name validity.""" injected_task_config = {"foo": "bar"} minimal_yaml_dict["scenario"] = {root_task_key: injected_task_config} config = ScenarioConfig(minimal_yaml_dict) assert config.root_config == injected_task_config
def test_is_subclass_of_config_mapping(self, minimal_definition_dict): """The class is a subclass of :class:`ConfigMapping`.""" assert isinstance(ScenarioConfig(minimal_definition_dict), ConfigMapping)
def test_defining_multiple_root_tasks_raises_configuration_error( self, minimal_definition_dict): """Defining multiple root tasks raises a :exc:`ScenarioConfigurationError`.""" minimal_definition_dict["scenario"]["second_root"] = {} with pytest.raises(ScenarioConfigurationError): ScenarioConfig(minimal_definition_dict)
def test_instantiating_with_an_empty_dict_raises_configuration_error(self): """Passing the ScenarioConfig class an empty dict is not allowed.""" with pytest.raises(ScenarioConfigurationError): ScenarioConfig({})
def test_missing_required_key_raises_configuration_error( self, minimal_definition_dict): """Missing required keys in the config dict raises a ScenarioConfigurationError.""" minimal_definition_dict["scenario"].pop("serial") with pytest.raises(ScenarioConfigurationError): ScenarioConfig(minimal_definition_dict)