def test_attributes_compare_with(old_attributes_data, new_attributes_data, result): old_attributes = Attributes() old_attributes.data.update(old_attributes_data) new_attributes = Attributes() new_attributes.data.update(new_attributes_data) delta_result = new_attributes.compare_with(old_attributes) assert (delta_result.counter['new'], delta_result.counter['changed'], delta_result.counter['removed']) == result
def mk_root(): # This tree contains all possibilities: # {'0_cna': {'__Att__': '{:}', # '__Con__': {'1_ca': {'__Att__': '{:}', # '__Con__': {'2_a': {'__Att__': '{:}', # '__path__': ('0_cna', # '1_ca', # '2_a')}}, # '__path__': ('0_cna', '1_ca')}, # '1_cn': {'__Con__': {'2_n': {'__Num__': '[:]', # '__path__': ('0_cna', # '1_ca', # '2_n')}}, # '__Num__': '[:]', # '__path__': ('0_cna', '1_cn')}, # '1_na': {'__Att__': '{:}', # '__Num__': '[:]', # '__path__': ('0_cna', '1_na')}}, # '__Num__': '[:]', # '__path__': ('0_cna',)}} root = Container() container_0 = Container() numeration_0 = Numeration() attributes_0 = Attributes() root.add_child("0_cna", container_0) root.add_child("0_cna", numeration_0) root.add_child("0_cna", attributes_0) numeration_1 = Numeration() container_1 = Container() container_0.add_child("1_cn", numeration_1) container_0.add_child("1_cn", container_1) attributes_1 = Attributes() container_2 = Container() container_0.add_child("1_ca", attributes_1) container_0.add_child("1_ca", container_2) numeration_2 = Numeration() attributes_2 = Attributes() container_0.add_child("1_na", numeration_2) container_0.add_child("1_na", attributes_2) numeration_3 = Numeration() attributes_3 = Attributes() container_1.add_child("2_n", numeration_3) container_2.add_child("2_a", attributes_3) return root
def test_attributes_compare_with(old_attributes_data, new_attributes_data, result): old_attributes = Attributes() old_attributes.add_pairs(old_attributes_data) new_attributes = Attributes() new_attributes.add_pairs(new_attributes_data) delta_result = new_attributes.compare_with(old_attributes) assert ( delta_result.counter["new"], delta_result.counter["changed"], delta_result.counter["removed"], ) == result
def sort_children(children): if not children: return [] ordering = { type(Attributes()): 1, type(Numeration()): 2, type(Container()): 3, } return sorted(children, key=lambda x: ordering[type(x)])
def test_add_attributes(): path = ("path-to", "node") retentions = {"key": RetentionIntervals(1, 2, 3)} node = StructuredDataNode(name="node", path=path) attributes = Attributes(retentions=retentions) node.add_attributes(attributes) assert node.attributes.path == path assert node.attributes.retentions == retentions
def mk_filled_root(): root = Container() container_0 = Container() numeration_0 = Numeration() attributes_0 = Attributes() root.add_child("0_cna", container_0) root.add_child("0_cna", numeration_0) root.add_child("0_cna", attributes_0) numeration_1 = Numeration() numeration_1.set_child_data([{"n10": "N-1-0"}]) container_1 = Container() container_0.add_child("1_cn", numeration_1) container_0.add_child("1_cn", container_1) attributes_1 = Attributes() attributes_1.set_child_data({"a10": "A-1-0"}) container_2 = Container() container_0.add_child("1_ca", attributes_1) container_0.add_child("1_ca", container_2) numeration_2 = Numeration() numeration_2.set_child_data([{"n20": "N-2-0"}, {"n21": "N-2-1"}]) attributes_2 = Attributes() attributes_2.set_child_data({"a20": "A-2-0", "a21": "A-1-1"}) container_0.add_child("1_na", numeration_2) container_0.add_child("1_na", attributes_2) numeration_3 = Numeration() numeration_3.set_child_data([{ "n30": "N-3-0" }, { "n31": "N-3-1" }, { "n32": "N-3-2" }]) attributes_3 = Attributes() attributes_3.set_child_data({ "a30": "A-3-0", "a31": "A-3-1", "a32": "A-3-2" }) container_1.add_child("2_n", numeration_3) container_2.add_child("2_a", attributes_3) return root