Repository: Avaiga/taipy
File: tests/core/config/checkers/test_task_config_checker.py (Python)

Code before:
        with pytest.raises(SystemExit):
            Config._collector = IssueCollector()
            Config.check()
        assert len(Config._collector.errors) == 1
        assert "function field of TaskConfig `new` is empty." in caplog.text
        assert len(Config._collector.warnings) == 2

        config._sections[TaskConfig.name]["new"].function = "bar"
        with pytest.raises(SystemExit):
            Config._collector = IssueCollector()
            Config.check()
        assert len(Config._collector.errors) == 1
        expected_error_message = (
            "function field of TaskConfig `new` must be populated with Callable value."
            ' Current value of property `function` is "bar".'
        )
        assert expected_error_message in caplog.text
        assert len(Config._collector.warnings) == 2

        config._sections[TaskConfig.name]["new"].function = mock_func
        Config._collector = IssueCollector()
        Config.check()
        assert len(Config._collector.errors) == 0
        assert len(Config._collector.warnings) == 2

    def test_check_required_property(self, caplog):
        prev_required_properties = TaskConfig._REQUIRED_PROPERTIES.copy()

        TaskConfig._REQUIRED_PROPERTIES = {"task_type": ["required_key_1", "required_key_2"]}

        config = Config._applied_config
        Config._compile_configs()

        config._sections[TaskConfig.name]["default"]._outputs = "bar"
        Config._collector = IssueCollector()
        Config.check()
        assert len(Config._collector.errors) == 0
        assert len(Config._collector.warnings) == 0

        config._sections[TaskConfig.name]["new"] = config._sections[TaskConfig.name]["default"]
        config._sections[TaskConfig.name]["new"].id = "new"
        config._sections[TaskConfig.name]["new"].function = print
        config._sections[TaskConfig.name]["new"]._outputs = [DataNodeConfig("bar")]
        config._sections[TaskConfig.name]["new"]._properties = {"task_type": True, "required_key_1": None}
        with pytest.raises(SystemExit):
            Config._collector = IssueCollector()
            Config.check()
        assert len(Config._collector.errors) == 2
        expected_error_message_1 = (
            "TaskConfig `new` is either missing the required property " "`required_key_1` or the value is set to None."
        )

Review comment (suggestion):
Usually for checker tests, we also test the case where there's no error.

I would also configure a task with `"task_type": True, "required_key_1": "sth", "required_key_2": "sth_2"` to make sure it passes

Code after:
        with pytest.raises(SystemExit):
            Config._collector = IssueCollector()
            Config.check()
        assert len(Config._collector.errors) == 1
        assert "function field of TaskConfig `new` is empty." in caplog.text
        assert len(Config._collector.warnings) == 2

        config._sections[TaskConfig.name]["new"].function = "bar"
        with pytest.raises(SystemExit):
            Config._collector = IssueCollector()
            Config.check()
        assert len(Config._collector.errors) == 1
        expected_error_message = (
            "function field of TaskConfig `new` must be populated with Callable value."
            ' Current value of property `function` is "bar".'
        )
        assert expected_error_message in caplog.text
        assert len(Config._collector.warnings) == 2

        config._sections[TaskConfig.name]["new"].function = mock_func
        Config._collector = IssueCollector()
        Config.check()
        assert len(Config._collector.errors) == 0
        assert len(Config._collector.warnings) == 2

    def test_check_required_property(self, caplog):
        prev_required_properties = TaskConfig._REQUIRED_PROPERTIES.copy()

        TaskConfig._REQUIRED_PROPERTIES = {"task_type": ["required_key_1", "required_key_2"]}

        config = Config._applied_config
        Config._compile_configs()

        config._sections[TaskConfig.name]["default"]._outputs = "bar"
        Config._collector = IssueCollector()
        Config.check()
        assert len(Config._collector.errors) == 0
        assert len(Config._collector.warnings) == 0

        config._sections[TaskConfig.name]["new"] = config._sections[TaskConfig.name]["default"]
        config._sections[TaskConfig.name]["new"].id = "new"
        config._sections[TaskConfig.name]["new"].function = print
        config._sections[TaskConfig.name]["new"]._outputs = [DataNodeConfig("bar")]
        config._sections[TaskConfig.name]["new"]._properties = {"task_type": True, "required_key_1": None}
        with pytest.raises(SystemExit):
            Config._collector = IssueCollector()
            Config.check()
        assert len(Config._collector.errors) == 2
        expected_error_message_1 = (
            "TaskConfig `new` is either missing the required property `required_key_1` or the value is set to None."
        )