Ver Fonte

fix wrong typing (#2396)

* fix wrong typing

* linter
Jean-Robin há 4 meses atrás
pai
commit
91ac4a5653

+ 2 - 2
taipy/core/config/data_node_config.py

@@ -11,7 +11,7 @@
 
 import json
 from copy import copy
-from datetime import timedelta, datetime
+from datetime import datetime, timedelta
 from typing import Any, Callable, Dict, List, Optional, Union
 
 import numpy
@@ -41,7 +41,7 @@ class DataNodeConfig(Section):
     """
 
     name = "DATA_NODE"
-    _ALL_TYPES = (str, int, float, bool, list, dict, tuple, set, type(None), callable, datetime, timedelta)
+    _ALL_TYPES = (str, int, float, bool, list, dict, tuple, set, type(None), type(callable), datetime, timedelta)
     _STORAGE_TYPE_KEY = "storage_type"
     _STORAGE_TYPE_VALUE_PICKLE = "pickle"
     _STORAGE_TYPE_VALUE_SQL_TABLE = "sql_table"

+ 65 - 1
tests/core/config/checkers/test_data_node_config_checker.py

@@ -10,7 +10,7 @@
 # specific language governing permissions and limitations under the License.
 
 from copy import copy
-from datetime import timedelta
+from datetime import datetime, timedelta
 
 import pytest
 
@@ -710,3 +710,67 @@ class TestDataNodeConfigChecker:
         config._sections[DataNodeConfig.name]["default"].properties = {"exposed_type": MyCustomClass}
         Config.check()
         assert len(Config._collector.errors) == 0
+
+    def test_check_property_types(self, caplog):
+        config = Config._applied_config
+        Config._compile_configs()
+        config._sections[DataNodeConfig.name]["default"].storage_type = "pickle"
+        config._sections[DataNodeConfig.name]["default"].properties = {"default_data": "string"}
+        Config._collector = IssueCollector()
+        Config.check()
+        assert len(Config._collector.errors) == 0
+
+        config._sections[DataNodeConfig.name]["default"].properties = {"default_data": 1}
+        Config._collector = IssueCollector()
+        Config.check()
+        assert len(Config._collector.errors) == 0
+
+        config._sections[DataNodeConfig.name]["default"].properties = {"default_data": 1.}
+        Config._collector = IssueCollector()
+        Config.check()
+        assert len(Config._collector.errors) == 0
+
+        config._sections[DataNodeConfig.name]["default"].properties = {"default_data": True}
+        Config._collector = IssueCollector()
+        Config.check()
+        assert len(Config._collector.errors) == 0
+
+        config._sections[DataNodeConfig.name]["default"].properties = {"default_data": ["foo", "bar"]}
+        Config._collector = IssueCollector()
+        Config.check()
+        assert len(Config._collector.errors) == 0
+
+        config._sections[DataNodeConfig.name]["default"].properties = {"default_data": ("foo", "bar")}
+        Config._collector = IssueCollector()
+        Config.check()
+        assert len(Config._collector.errors) == 0
+
+        config._sections[DataNodeConfig.name]["default"].properties = {"default_data": {"foo": "bar"}}
+        Config._collector = IssueCollector()
+        Config.check()
+        assert len(Config._collector.errors) == 0
+
+        config._sections[DataNodeConfig.name]["default"].properties = {"default_data": {"foo", "bar"}}
+        Config._collector = IssueCollector()
+        Config.check()
+        assert len(Config._collector.errors) == 0
+
+        config._sections[DataNodeConfig.name]["default"].properties = {"default_data": None}
+        Config._collector = IssueCollector()
+        Config.check()
+        assert len(Config._collector.errors) == 0
+
+        config._sections[DataNodeConfig.name]["default"].properties = {"default_data": print}
+        Config._collector = IssueCollector()
+        Config.check()
+        assert len(Config._collector.errors) == 0
+
+        config._sections[DataNodeConfig.name]["default"].properties = {"default_data": datetime(2021, 7, 26)}
+        Config._collector = IssueCollector()
+        Config.check()
+        assert len(Config._collector.errors) == 0
+
+        config._sections[DataNodeConfig.name]["default"].properties = {"default_data": timedelta(7)}
+        Config._collector = IssueCollector()
+        Config.check()
+        assert len(Config._collector.errors) == 0