Skip to content
This repository has been archived by the owner on Jul 11, 2024. It is now read-only.

Commit

Permalink
Merge pull request #102 from Avaiga/fix/core#793-deepdiff-should-igno…
Browse files Browse the repository at this point in the history
…re-order
  • Loading branch information
trgiangdo authored Oct 16, 2023
2 parents 4c348ba + 15f4120 commit caa269d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/taipy/config/_config_comparator/_config_comparator.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def __get_config_diff(self, config_1, config_2):
json_config_1 = json.loads(_JsonSerializer._serialize(config_1))
json_config_2 = json.loads(_JsonSerializer._serialize(config_2))

config_deepdiff = DeepDiff(json_config_1, json_config_2)
config_deepdiff = DeepDiff(json_config_1, json_config_2, ignore_order=True)

comparator_result = _ComparatorResult(copy(self._unconflicted_sections))

Expand Down
9 changes: 5 additions & 4 deletions src/taipy/config/config.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,6 @@ class Config:
def tasks(cls) -> Dict[str, TaskConfig]:
""""""

@_Classproperty
def sequences(cls) -> Dict[str, SequenceConfig]:
""""""

@_Classproperty
def scenarios(cls) -> Dict[str, ScenarioConfig]:
""""""
Expand All @@ -187,6 +183,7 @@ class Config:
additional_data_node_configs: Optional[List[DataNodeConfig]] = None,
frequency: Optional[Frequency] = None,
comparators: Optional[Dict[str, Union[List[Callable], Callable]]] = None,
sequences: Optional[Dict[str, List[TaskConfig]]] = None,
**properties,
) -> "ScenarioConfig":
"""Configure a new scenario configuration.
Expand All @@ -208,6 +205,8 @@ class Config:
comparison, each comparator is applied to all the data nodes instantiated from
the data node configuration attached to the comparator. See
`(taipy.)compare_scenarios()^` more more details.
sequences (Optional[Dict[str, List[TaskConfig]]]): Dictionary of sequence descriptions.
The default value is None.
**properties (dict[str, any]): A keyworded variable length list of additional arguments.
Returns:
Expand All @@ -220,6 +219,7 @@ class Config:
additional_data_node_configs: List[DataNodeConfig] = None,
frequency: Optional[Frequency] = None,
comparators: Optional[Dict[str, Union[List[Callable], Callable]]] = None,
sequences: Optional[Dict[str, List[TaskConfig]]] = None,
**properties,
) -> "ScenarioConfig":
"""Set the default values for scenario configurations.
Expand All @@ -244,6 +244,7 @@ class Config:
comparison, each comparator is applied to all the data nodes instantiated from
the data node configuration attached to the comparator. See
`taipy.compare_scenarios()^` more more details.
sequences (Optional[Dict[str, List[TaskConfig]]]): Dictionary of sequences. The default value is None.
**properties (dict[str, any]): A keyworded variable length list of additional arguments.
Returns:
Expand Down
18 changes: 16 additions & 2 deletions tests/config/test_config_comparator.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ class TestConfigComparator:
section_1 = SectionForTest("section_1", attribute="attribute_1", prop="prop_1")
section_2 = SectionForTest("section_2", attribute=2, prop="prop_2")
section_2b = SectionForTest("section_2", attribute="attribute_2", prop="prop_2b")
section_3 = SectionForTest("section_5", attribute=[1, 2, 3, 4], prop=["prop_1"])
section_3b = SectionForTest("section_5", attribute=[1, 2], prop=["prop_1", "prop_2", "prop_3"])
section_3 = SectionForTest("section_3", attribute=[1, 2, 3, 4], prop=["prop_1"])
section_3b = SectionForTest("section_3", attribute=[1, 2], prop=["prop_1", "prop_2", "prop_3"])
section_3c = SectionForTest("section_3", attribute=[2, 1], prop=["prop_3", "prop_1", "prop_2"])

def test_comparator_compare_method_call(self):
_config_1 = _Config._default_config()
Expand Down Expand Up @@ -176,6 +177,19 @@ def test_comparator_with_modified_list_attribute(self):
assert conflicted_config_diff.get("removed_items") is None
assert conflicted_config_diff.get("added_items") is None

def test_comparator_with_different_order_list_attributes(self):
_config_1 = _Config._default_config()
_config_1._unique_sections
_config_1._sections[SectionForTest.name] = {"section_3": self.section_3b}

# Create _config_2 with different order of list attributes
_config_2 = _Config._default_config()
_config_2._sections[SectionForTest.name] = {"section_3": self.section_3c}
config_diff = Config._comparator._find_conflict_config(_config_1, _config_2)

# There should be no difference since the order of list attributes is ignored
assert config_diff == {}

def test_comparator_with_new_unique_section(self):
_config_1 = _Config._default_config()

Expand Down

0 comments on commit caa269d

Please sign in to comment.