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

Code before:
            Config._collector = IssueCollector()
            Config.check()
        assert len(Config._collector.errors) == 1

        config._sections[DataNodeConfig.name]["new"].storage_type = "generic"
        config._sections[DataNodeConfig.name]["new"].properties = {"write_fct": print, "read_fct": print}
        Config._collector = IssueCollector()
        Config.check()
        assert len(Config._collector.errors) == 0

        config._sections[DataNodeConfig.name]["new"].storage_type = "generic"
        config._sections[DataNodeConfig.name]["new"].properties = {"write_fct": lambda x: x, "read_fct": lambda y: y}
        with pytest.raises(SystemExit):
            Config._collector = IssueCollector()
            Config.check()
        assert len(Config._collector.errors) == 2
        expected_error_messages = [
            "`write_fct` of DataNodeConfig `new` must be populated with a Callable and not a lambda."
            " Current value of property `write_fct` is <function TestDataNodeConfigChecker."
            "test_check_callable_properties.<locals>.<lambda>",
            "`read_fct` of DataNodeConfig `new` must be populated with a Callable and not a lambda."
            " Current value of property `read_fct` is <function TestDataNodeConfigChecker."
            "test_check_callable_properties.<locals>.<lambda>",
        ]
        assert all(message in caplog.text for message in expected_error_messages)

    def test_check_read_write_fct_args(self, caplog):
        config = Config._applied_config
        Config._compile_configs()

        config._sections[DataNodeConfig.name]["default"].storage_type = "generic"
        config._sections[DataNodeConfig.name]["default"].properties = {"write_fct": print, "read_fct": print}
        Config._collector = IssueCollector()
        Config.check()
        assert len(Config._collector.errors) == 0

        config._sections[DataNodeConfig.name]["default"].storage_type = "generic"
        config._sections[DataNodeConfig.name]["default"].properties = {
            "write_fct": print,
            "read_fct": print,
            "write_fct_args": "foo",
        }
        with pytest.raises(SystemExit):
            Config._collector = IssueCollector()
            Config.check()
        assert len(Config._collector.errors) == 1
        expected_error_message = (
            "`write_fct_args` field of DataNodeConfig `default` must be populated with a List value."
            ' Current value of property `write_fct_args` is "foo".'
        )
        assert expected_error_message in caplog.text

Review comment (suggestion):
BTW, this deserves: 
- an entry in the release notes as an improvement of the checkers for checking the property types.
- A new item in the list: https://docs.taipy.io/en/develop/userman/advanced_features/configuration/config-checker/




Code after:
            Config._collector = IssueCollector()
            Config.check()
        assert len(Config._collector.errors) == 1

        config._sections[DataNodeConfig.name]["new"].storage_type = "generic"
        config._sections[DataNodeConfig.name]["new"].properties = {"write_fct": print, "read_fct": print}
        Config._collector = IssueCollector()
        Config.check()
        assert len(Config._collector.errors) == 0

        config._sections[DataNodeConfig.name]["new"].storage_type = "generic"
        config._sections[DataNodeConfig.name]["new"].properties = {"write_fct": lambda x: x, "read_fct": lambda y: y}
        with pytest.raises(SystemExit):
            Config._collector = IssueCollector()
            Config.check()
        assert len(Config._collector.errors) == 2
        expected_error_messages = [
            "`write_fct` of DataNodeConfig `new` must be populated with a serializable Callable function but"
            " not a lambda. Current value of property `write_fct` is <function TestDataNodeConfigChecker."
            "test_check_callable_properties.<locals>.<lambda>",
            "`read_fct` of DataNodeConfig `new` must be populated with a serializable Callable function but"
            " not a lambda. Current value of property `read_fct` is <function TestDataNodeConfigChecker."
            "test_check_callable_properties.<locals>.<lambda>",
        ]
        assert all(message in caplog.text for message in expected_error_messages)

    def test_check_read_write_fct_args(self, caplog):
        config = Config._applied_config
        Config._compile_configs()

        config._sections[DataNodeConfig.name]["default"].storage_type = "generic"
        config._sections[DataNodeConfig.name]["default"].properties = {"write_fct": print, "read_fct": print}
        Config._collector = IssueCollector()
        Config.check()
        assert len(Config._collector.errors) == 0

        config._sections[DataNodeConfig.name]["default"].storage_type = "generic"
        config._sections[DataNodeConfig.name]["default"].properties = {
            "write_fct": print,
            "read_fct": print,
            "write_fct_args": "foo",
        }
        with pytest.raises(SystemExit):
            Config._collector = IssueCollector()
            Config.check()
        assert len(Config._collector.errors) == 1
        expected_error_message = (
            "`write_fct_args` field of DataNodeConfig `default` must be populated with a List value."
            ' Current value of property `write_fct_args` is "foo".'
        )
        assert expected_error_message in caplog.text