Пример #1
0
        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)
Пример #2
0
    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)
Пример #3
0
    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
Пример #4
0
    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
Пример #5
0
    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
Пример #6
0
    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
Пример #7
0
    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
Пример #8
0
 def test_success(self, config, instances, args):
     config.INSTANCES = instances
     config.PLUGIN_ARGS = args
     assert ConfigLoader._args(config) is None
Пример #9
0
 def test_failure(self, config):
     config.INSTANCES = "not a list"
     with pytest.raises(PluginValidationError):
         ConfigLoader._instances(config)
Пример #10
0
 def test_success(self, config):
     config.INSTANCES = ["i1"]
     assert ConfigLoader._instances(config) is None
Пример #11
0
 def test_missing(self, config):
     assert ConfigLoader._instances(config) is None
Пример #12
0
    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
Пример #13
0
 def test_success(self, config):
     config.ENVIRONMENT = {"foo": "bar"}
     assert ConfigLoader._environment(config) is None
Пример #14
0
 def test_failure(self, args):
     with pytest.raises(PluginValidationError):
         ConfigLoader._individual_args(args)
Пример #15
0
 def test_success(self, tmp_path, config, entry_point):
     assert ConfigLoader._validate(config, tmp_path) is None
Пример #16
0
 def test_failure(self, config, instances, args):
     config.INSTANCES = instances
     config.PLUGIN_ARGS = args
     with pytest.raises(PluginValidationError):
         ConfigLoader._args(config)
Пример #17
0
 def test_success(self, args):
     assert ConfigLoader._individual_args(args) is None
Пример #18
0
 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)
Пример #19
0
 def test_missing(self, config):
     assert ConfigLoader._environment(config) is None
Пример #20
0
 def test_good_file(self, tmp_path, config, entry_point):
     assert ConfigLoader._entry_point(config, tmp_path) is None
Пример #21
0
 def test_failure(self, config, env):
     config.ENVIRONMENT = env
     with pytest.raises(PluginValidationError):
         ConfigLoader._environment(config)
Пример #22
0
 def test_failure_missing_conf_file(self, tmp_path, loader):
     with pytest.raises(PluginValidationError):
         ConfigLoader._load_config(tmp_path)