def test_good_package(self, tmp_path, config): plugin_dir = tmp_path / "plugin" plugin_dir.mkdir() (plugin_dir / "__init__.py").touch() (plugin_dir / "__main__.py").touch() config.PLUGIN_ENTRY = "-m plugin" ConfigLoader._entry_point(config, tmp_path)
def test_invalid_args(self, tmp_path): write_file( tmp_path, textwrap.dedent( """ NAME='foo' VERSION='1.0' PLUGIN_ENTRY='entry.py' PLUGIN_ARGS="invalid" """ ), ) with pytest.raises(PluginValidationError): ConfigLoader.load(tmp_path / CONFIG_NAME)
def test_required_attributes(self, tmp_path, config_all): write_file( tmp_path, textwrap.dedent( """ NAME='foo' VERSION='1.0' PLUGIN_ENTRY='entry.py' """ ), ) assert ConfigLoader.load(tmp_path / CONFIG_NAME) == config_all
def test_explicit_max_instances(self, tmp_path): write_file( tmp_path, textwrap.dedent( """ NAME='foo' VERSION='1.0' PLUGIN_ENTRY='entry.py' INSTANCES=["foo", "bar"] MAX_INSTANCES=-1 """ ), ) loaded_config = ConfigLoader.load(tmp_path / CONFIG_NAME) assert sorted(loaded_config["INSTANCES"]) == sorted(["foo", "bar"]) assert loaded_config["MAX_INSTANCES"] == -1
def test_instance_and_args_list(self, tmp_path): write_file( tmp_path, textwrap.dedent( """ NAME='foo' VERSION='1.0' PLUGIN_ENTRY='entry.py' INSTANCES=["foo", "bar"] PLUGIN_ARGS=["arg1"] """ ), ) loaded_config = ConfigLoader.load(tmp_path / CONFIG_NAME) assert sorted(loaded_config["INSTANCES"]) == sorted(["foo", "bar"]) assert loaded_config["PLUGIN_ARGS"] == {"foo": ["arg1"], "bar": ["arg1"]} assert loaded_config["MAX_INSTANCES"] == -1
def test_plugin_args_list_no_instances(self, tmp_path): write_file( tmp_path, textwrap.dedent( """ NAME='foo' VERSION='1.0' PLUGIN_ENTRY='entry.py' INSTANCES=None PLUGIN_ARGS=["arg1"] """ ), ) loaded_config = ConfigLoader.load(tmp_path / CONFIG_NAME) assert loaded_config["INSTANCES"] == ["default"] assert loaded_config["PLUGIN_ARGS"] == {"default": ["arg1"]} assert loaded_config["MAX_INSTANCES"] == -1
def test_instances_no_plugin_args(self, tmp_path): write_file( tmp_path, textwrap.dedent( """ NAME='foo' VERSION='1.0' PLUGIN_ENTRY='entry.py' INSTANCES=["instance1", "instance2"] PLUGIN_ARGS=None """ ), ) loaded_config = ConfigLoader.load(tmp_path / CONFIG_NAME) assert loaded_config["INSTANCES"] == ["instance1", "instance2"] assert loaded_config["PLUGIN_ARGS"] == {"instance1": None, "instance2": None} assert loaded_config["MAX_INSTANCES"] == -1
def test_success(self, config, instances, args): config.INSTANCES = instances config.PLUGIN_ARGS = args assert ConfigLoader._args(config) is None
def test_failure(self, config): config.INSTANCES = "not a list" with pytest.raises(PluginValidationError): ConfigLoader._instances(config)
def test_success(self, config): config.INSTANCES = ["i1"] assert ConfigLoader._instances(config) is None
def test_missing(self, config): assert ConfigLoader._instances(config) is None
def test_all_attributes(self, tmp_path, config_all, config_all_serialized): write_file(tmp_path, config_all_serialized) assert ConfigLoader.load(tmp_path / CONFIG_NAME) == config_all
def test_success(self, config): config.ENVIRONMENT = {"foo": "bar"} assert ConfigLoader._environment(config) is None
def test_failure(self, args): with pytest.raises(PluginValidationError): ConfigLoader._individual_args(args)
def test_success(self, tmp_path, config, entry_point): assert ConfigLoader._validate(config, tmp_path) is None
def test_failure(self, config, instances, args): config.INSTANCES = instances config.PLUGIN_ARGS = args with pytest.raises(PluginValidationError): ConfigLoader._args(config)
def test_success(self, args): assert ConfigLoader._individual_args(args) is None
def test_not_a_file(self, tmp_path, config): # Not having the entry_point fixture makes this fail with pytest.raises(PluginValidationError): ConfigLoader._entry_point(config, tmp_path)
def test_missing(self, config): assert ConfigLoader._environment(config) is None
def test_good_file(self, tmp_path, config, entry_point): assert ConfigLoader._entry_point(config, tmp_path) is None
def test_failure(self, config, env): config.ENVIRONMENT = env with pytest.raises(PluginValidationError): ConfigLoader._environment(config)
def test_failure_missing_conf_file(self, tmp_path, loader): with pytest.raises(PluginValidationError): ConfigLoader._load_config(tmp_path)