Exemple #1
0
    def compare(self, other, with_progress_bar=False):
        '''
        :param other: cts_core.metadata.metadata_container.MetadataContainer
        :param with_progress_bar:
        :return: cts_core.metadata.compare_result.CompareResult
        '''
        if with_progress_bar:
            entities = set(self.entities.keys())
            entities_other = set(other.entities.keys())
            num_entities = len(list(entities.union(entities_other)))

            types = set(self.types.keys())
            types_other = set(other.types.keys())
            num_types = len(list(types.union(types_other)))

            progress_bar = ProgressBar(50, num_steps=num_entities + num_types)
            progress_bar.draw()
        else:
            progress_bar = None

        cmp = Comparator()

        entities_compare_results = self.entities.compare(other.entities, progress_bar)
        types_compare_results = self.types.compare(other.types, progress_bar)

        cmp.merge_result(entities_compare_results, types_compare_results)
        return cmp
Exemple #2
0
    def compare(self, other, with_progress_bar=False):
        '''
        :param other: cts_core.metadata.metadata_container.MetadataContainer
        :param with_progress_bar:
        :return: cts_core.metadata.compare_result.CompareResult
        '''
        if with_progress_bar:
            entities = set(self.entities.keys())
            entities_other = set(other.entities.keys())
            num_entities = len(list(entities.union(entities_other)))

            types = set(self.types.keys())
            types_other = set(other.types.keys())
            num_types = len(list(types.union(types_other)))

            progress_bar = ProgressBar(50, num_steps=num_entities + num_types)
            progress_bar.draw()
        else:
            progress_bar = None

        cmp = Comparator()

        entities_compare_results = self.entities.compare(
            other.entities, progress_bar)
        types_compare_results = self.types.compare(other.types, progress_bar)

        cmp.merge_result(entities_compare_results, types_compare_results)
        return cmp
Exemple #3
0
 def compare(self, other, level):
     """
     :type other: cts_core.metadata.model.property.Property
     :rtype: int
     """
     cmp = Comparator(level)
     cmp.message_both("Property: {name}".format(name=self.name))
     return cmp.merge_result(self.compare_type(other, level + 1),
                             self.compare_nullable(other, level + 1),
                             self.compare_is_required(other, level + 1),
                             self.compare_patch_status(other, level + 1),
                             self.compare_annotations(other, level + 1))
Exemple #4
0
 def compare_dynamic_property_patterns(self, other, level):
     """
     :type other: cts_core.metadata.model.metadata_types.complex_type.ComplexType
     :type cmp: cts_core.metadata.comparator.Comparator
     :rtype: int
     """
     return Comparator(level)
Exemple #5
0
    def compare_nullable(self, other, level):
        """
        :type other: cts_core.metadata.model.property.Property
        :rtype: int
        """
        cmp = Comparator(level)
        if self.nullable != other.nullable:
            cmp.message_left("Nullable" if self.nullable else "Not Nullable")
            cmp.message_right("Nullable" if other.nullable else "Not Nullable")
            cmp.set_not_equal()

        return cmp
Exemple #6
0
    def compare_patch_status(self, other, level):
        """
        :type other: cts_core.metadata.model.property.Property
        :rtype: int
        """
        cmp = Comparator(level)
        if self.patch_status != other.patch_status:
            cmp.message_left(self.patch_status)
            cmp.message_right(other.patch_status)
            cmp.set_not_equal()

        return cmp
Exemple #7
0
    def compare_is_required(self, other, level):
        """
        :type other: cts_core.metadata.model.property.Property
        :rtype: int
        """

        cmp = Comparator(level)
        if self.is_required != other.is_required:
            cmp.message_left("Required" if self.is_required else "Optional")
            cmp.message_right("Required" if other.is_required else "Optional")
            cmp.set_not_equal()

        return cmp
    def compare_base_type(self, other, level):
        """
        :type other: cts_core.metadata.model.metadata_model.MetadataModel
        :type cmp: cts_core.metadata.comparator.Comparator
        :rtype: int
        """
        cmp = Comparator(level)
        if self.base_type != other.base_type:
            fmt = "Base type: {base}"
            cmp.message_left(fmt.format(base=self.base_type))
            cmp.message_right(fmt.format(base=other.base_type))
            cmp.set_not_equal()

        return cmp
Exemple #9
0
 def compare(self, other):
     """
     :type other: cts_core.metadata.model.metadata_types.complex_type.ComplexType
     :rtype: int
     """
     cmp = Comparator()
     cmp.message_both("Type: {type}".format(type=self.name))
     cmp.merge_result(
         self.compare_base_type(other, level=1),
         self.compare_properties(other, level=1),
         self.compare_annotations(other, level=1),
         self.compare_dynamic_property_patterns(other, level=1))
     cmp.separator()
     return cmp
Exemple #10
0
 def compare(self, other):
     """
     :type other: cts_core.metadata.model.entity.Entity
     :rtype: int
     """
     cmp = Comparator(level=0)
     cmp.message_both("Entity: {entity}".format(entity=self.name))
     cmp.merge_result(
         self.compare_base_type(other, level=1),
         self.compare_properties(other, level=1),
         self.compare_annotations(other, level=1),
         self.compare_dynamic_property_patterns(other, level=1))
     cmp.separator()
     return cmp
Exemple #11
0
 def compare(self, other):
     """
     :type other: cts_core.metadata.model.entity.Entity
     :rtype: int
     """
     cmp = Comparator(level=0)
     cmp.message_both("Entity: {entity}".format(entity=self.name))
     cmp.merge_result(
         self.compare_base_type(other, level=1),
         self.compare_properties(other, level=1),
         self.compare_annotations(other, level=1),
         self.compare_dynamic_property_patterns(other, level=1))
     cmp.separator()
     return cmp
Exemple #12
0
    def compare_type(self, other, level):
        """
        :type other: cts_core.metadata.model.property.Property
        :rtype: int
        """
        cmp = Comparator(level)
        if self.type != other.type or self.is_collection != other.is_collection:
            fmt = "Type: {type}"
            fmt_collection = "Type: Collection({type})"
            cmp.message_left(
                (fmt_collection if self.is_collection else fmt).format(
                    type=self.type))
            cmp.message_right(
                (fmt_collection if other.is_collection else fmt).format(
                    type=other.type))
            cmp.set_not_equal()

        return cmp
Exemple #13
0
 def compare(self, other):
     return Comparator()
Exemple #14
0
    def compare(self, other, progress_bar):
        '''
        :type other: cts_core.metadata.metadata_container.EntitiesContainer
        :return: int
        '''
        cmp = Comparator(level=0)

        entities = set(self.keys())
        entities_other = set(other.keys())
        all = sorted(list(entities.union(entities_other)))
        both = entities.intersection(entities_other)

        fmt = "Entity: {entity}"
        for entity in all:
            if progress_bar is not None:
                progress_bar.set_label(entity)

            if entity in both:
                cmp.merge_result(self.__getitem__(entity).compare(other.__getitem__(entity)))
            elif entity in entities:
                cmp.set_not_equal()
                cmp.message_left(fmt.format(entity=entity))
                cmp.message_right('?')
                cmp.separator()
            else:
                cmp.set_not_equal()
                cmp.message_left('?')
                cmp.message_right(fmt.format(entity=entity))
                cmp.separator()

            if progress_bar is not None:
                progress_bar.make_progress()
        return cmp
    def compare_properties(self, other, level):
        """
        :type other: cts_core.metadata.model.metadata_model.MetadataModel
        :rtype: int
        """
        cmp = Comparator(level)

        properties = set(self.properties.keys())
        properties_other = set(other.properties.keys())
        all = sorted(list(properties.union(properties_other)))
        both = properties.intersection(properties_other)
        fmt = "Property: {name}"

        for property in all:
            if property in both:
                cmp.merge_result(self.properties[property].compare(other.properties[property], level))
            elif property in properties:
                cmp.set_not_equal()
                cmp.message_left(fmt.format(name=property))
                cmp.message_right('?')
            else:
                cmp.set_not_equal()
                cmp.message_left('?')
                cmp.message_right(fmt.format(name=property))
        return cmp
Exemple #16
0
    def compare(self, other, progress_bar):
        '''
        :type other: cts_core.metadata.metadata_container.TypesContainer
        :return: cts_core.metadata.compare_result.CompareResult
        '''

        cmp = Comparator(level=0)

        types = set(self.keys())
        types_other = set(other.keys())
        all = sorted(list(types.union(types_other)))
        both = types.intersection(types_other)

        fmt = "Type: {type}"
        for type in all:
            if progress_bar is not None:
                progress_bar.set_label(type)

            if type in both:
                cmp.merge_result(self.__getitem__(type).compare(other.__getitem__(type)))
            elif type in types:
                cmp.set_not_equal()
                cmp.message_left(fmt.format(type=type))
                cmp.message_right('?')
                cmp.separator()
            else:
                cmp.set_not_equal()
                cmp.message_left('?')
                cmp.message_right(fmt.format(type=type))
                cmp.separator()

            if progress_bar is not None:
                progress_bar.make_progress()
        return cmp
Exemple #17
0
    def compare(self, other, level):
        """
        :type other: cts_core.metadata.model.annotation.Annotation
        :rtype: int
        """
        cmp = Comparator(level)
        cmp.message_both("Annotation: {name}".format(name=self.term))

        attributes = set(self.annotations_attributes_list.keys())
        attributes_other = set(other.annotations_attributes_list.keys())
        all = sorted(list(attributes.union(attributes_other)))
        both = attributes.intersection(attributes_other)
        fmt = "  {name}={value}"
        for attribute in all:
            if attribute in both:
                if self.annotations_attributes_list[attribute] != other.annotations_attributes_list[attribute]:
                    cmp.set_not_equal()
                    cmp.message_left(fmt.format(name=attribute, value=self.annotations_attributes_list[attribute]))
                    cmp.message_right(fmt.format(name=attribute, value=other.annotations_attributes_list[attribute]))
            elif attribute in attributes:
                cmp.set_not_equal()
                cmp.message_left(fmt.format(name=attribute, value=self.annotations_attributes_list[attribute]))
                cmp.message_right('?')
            else:
                cmp.set_not_equal()
                cmp.message_left('?')
                cmp.message_right(fmt.format(name=attribute, value=other.annotations_attributes_list[attribute]))
        return cmp
    def compare_annotations(self, other, level):
        """
        :type other: cts_core.metadata.model.metadata_model.MetadataModel
        :rtype: int
        """
        cmp = Comparator(level)

        annotations = set(self.annotations.keys())
        annotations_other = set(other.annotations.keys())
        all = sorted(list(annotations.union(annotations_other)))
        both = annotations.intersection(annotations_other)

        fmt = "Annotation: {name}"
        for annotation in all:
            if annotation in both:
                cmp.merge_result(self.annotations[annotation].compare(other.annotations[annotation], level))
            elif annotation in annotations:
                cmp.set_not_equal()
                cmp.message_left(fmt.format(name=annotation))
                cmp.message_right('?')
            else:
                cmp.set_not_equal()
                cmp.message_left('?')
                cmp.message_right(fmt.format(name=annotation))

        return cmp
Exemple #19
0
    def compare(self, other, level):
        """
        :type other: cts_core.metadata.model.annotation.Annotation
        :rtype: int
        """
        cmp = Comparator(level)
        cmp.message_both("Annotation: {name}".format(name=self.term))

        attributes = set(self.annotations_attributes_list.keys())
        attributes_other = set(other.annotations_attributes_list.keys())
        all = sorted(list(attributes.union(attributes_other)))
        both = attributes.intersection(attributes_other)
        fmt = "  {name}={value}"
        for attribute in all:
            if attribute in both:
                if self.annotations_attributes_list[
                        attribute] != other.annotations_attributes_list[
                            attribute]:
                    cmp.set_not_equal()
                    cmp.message_left(
                        fmt.format(
                            name=attribute,
                            value=self.annotations_attributes_list[attribute]))
                    cmp.message_right(
                        fmt.format(name=attribute,
                                   value=other.
                                   annotations_attributes_list[attribute]))
            elif attribute in attributes:
                cmp.set_not_equal()
                cmp.message_left(
                    fmt.format(
                        name=attribute,
                        value=self.annotations_attributes_list[attribute]))
                cmp.message_right('?')
            else:
                cmp.set_not_equal()
                cmp.message_left('?')
                cmp.message_right(
                    fmt.format(
                        name=attribute,
                        value=other.annotations_attributes_list[attribute]))
        return cmp
Exemple #20
0
    def compare(self, other, progress_bar):
        '''
        :type other: cts_core.metadata.metadata_container.TypesContainer
        :return: cts_core.metadata.compare_result.CompareResult
        '''

        cmp = Comparator(level=0)

        types = set(self.keys())
        types_other = set(other.keys())
        all = sorted(list(types.union(types_other)))
        both = types.intersection(types_other)

        fmt = "Type: {type}"
        for type in all:
            if progress_bar is not None:
                progress_bar.set_label(type)

            if type in both:
                cmp.merge_result(
                    self.__getitem__(type).compare(other.__getitem__(type)))
            elif type in types:
                cmp.set_not_equal()
                cmp.message_left(fmt.format(type=type))
                cmp.message_right('?')
                cmp.separator()
            else:
                cmp.set_not_equal()
                cmp.message_left('?')
                cmp.message_right(fmt.format(type=type))
                cmp.separator()

            if progress_bar is not None:
                progress_bar.make_progress()
        return cmp
Exemple #21
0
 def test_merger_results(self):
     self.assertEqual(Comparator.EQUAL,
                      Comparator().merge_result(Comparator()).result)
     self.assertEqual(
         Comparator.EQUAL,
         Comparator().merge_result(Comparator(), Comparator()).result)
     self.assertEqual(
         Comparator.NON_EQUAL,
         Comparator().merge_result(Comparator().set_not_equal()).result)
     self.assertEqual(
         Comparator.NON_EQUAL,
         Comparator().merge_result(Comparator(),
                                   Comparator().set_not_equal()).result)
     self.assertEqual(
         Comparator.NON_EQUAL,
         Comparator().merge_result(Comparator().set_not_equal(),
                                   Comparator()).result)
Exemple #22
0
    def compare(self, other, progress_bar):
        '''
        :type other: cts_core.metadata.metadata_container.EntitiesContainer
        :return: int
        '''
        cmp = Comparator(level=0)

        entities = set(self.keys())
        entities_other = set(other.keys())
        all = sorted(list(entities.union(entities_other)))
        both = entities.intersection(entities_other)

        fmt = "Entity: {entity}"
        for entity in all:
            if progress_bar is not None:
                progress_bar.set_label(entity)

            if entity in both:
                cmp.merge_result(
                    self.__getitem__(entity).compare(
                        other.__getitem__(entity)))
            elif entity in entities:
                cmp.set_not_equal()
                cmp.message_left(fmt.format(entity=entity))
                cmp.message_right('?')
                cmp.separator()
            else:
                cmp.set_not_equal()
                cmp.message_left('?')
                cmp.message_right(fmt.format(entity=entity))
                cmp.separator()

            if progress_bar is not None:
                progress_bar.make_progress()
        return cmp