From e61c49072dde0b99057b24cadf80bd55599fdee1 Mon Sep 17 00:00:00 2001 From: trgiangdo Date: Mon, 16 Oct 2023 16:59:07 +0700 Subject: [PATCH] fix: deepdiff should ignore order of list attributes --- .../_config_comparator/_config_comparator.py | 2 +- tests/config/test_config_comparator.py | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/taipy/config/_config_comparator/_config_comparator.py b/src/taipy/config/_config_comparator/_config_comparator.py index 0e77a9b..9d80799 100644 --- a/src/taipy/config/_config_comparator/_config_comparator.py +++ b/src/taipy/config/_config_comparator/_config_comparator.py @@ -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)) diff --git a/tests/config/test_config_comparator.py b/tests/config/test_config_comparator.py index b6b00f0..450c5f4 100644 --- a/tests/config/test_config_comparator.py +++ b/tests/config/test_config_comparator.py @@ -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() @@ -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()