Exemple #1
0
    def test_string_diff(self):
        self.assertEqual('', string_diff(None, None))
        self.assertEqual('foo', string_diff('foo', 'foo'))
        self.assertEqual('foo3', string_diff('foo', 'foo3'))
        self.assertEqual(
            '...7890foo3',
            string_diff('12345678901234567890foo', '12345678901234567890foo3'))
        self.assertEqual(
            '...7890foo3',
            string_diff('12345678901234567890foo4',
                        '12345678901234567890foo3'))
        self.assertEqual(
            '...7890foo3',
            string_diff('12345678901234567890foo45',
                        '12345678901234567890foo3'))
        self.assertEqual(
            '...4567890foo123456789123456789',
            string_diff('12345678901234567890',
                        '12345678901234567890foo123456789123456789'))

        self.assertEqual("['foo']", string_diff(['foo'], ['foo']))
        self.assertEqual("['bar']", string_diff(['foo'], ['bar']))
    def test_string_diff(self):
        self.assertEqual('', string_diff(None, None))
        self.assertEqual('foo', string_diff('foo', 'foo'))
        self.assertEqual('foo3', string_diff('foo', 'foo3'))
        self.assertEqual(
            '...7890foo3',
            string_diff('12345678901234567890foo',
                        '12345678901234567890foo3'))
        self.assertEqual(
            '...7890foo3',
            string_diff('12345678901234567890foo4',
                        '12345678901234567890foo3'))
        self.assertEqual(
            '...7890foo3',
            string_diff('12345678901234567890foo45',
                        '12345678901234567890foo3'))
        self.assertEqual(
            '...4567890foo123456789123456789',
            string_diff('12345678901234567890',
                        '12345678901234567890foo123456789123456789'))

        self.assertEqual("['foo']", string_diff(['foo'], ['foo']))
        self.assertEqual("['bar']", string_diff(['foo'], ['bar']))
Exemple #3
0
def _get_element_diff(new_path_spec, config_old, extra_verbose=False):
    """
    :returns: a string telling what changed for element compared to old config
    """
    if new_path_spec is None or config_old is None:
        return ''
    output = [' %s' % new_path_spec.get_local_name()]
    if extra_verbose:
        old_element = None
        if config_old is not None:
            old_element = select_element(config_old.get_config_elements(),
                                         new_path_spec.get_local_name())

        if old_element is None:
            if new_path_spec.get_scmtype() is not None:
                output.append(
                    "   \t%s  %s   %s" % (new_path_spec.get_scmtype(),
                                          new_path_spec.get_uri(),
                                          new_path_spec.get_version() or ''))
        else:
            old_path_spec = old_element.get_path_spec()
            accessor_map = {PathSpec.get_scmtype: 'scmtype',
                            PathSpec.get_version: 'version',
                            PathSpec.get_revision: 'revision',
                            PathSpec.get_current_revision: 'current revision',
                            PathSpec.get_curr_uri: 'current_uri',
                            PathSpec.get_uri: 'specified uri'}
            for accessor, label in list(accessor_map.items()):
                old_val = accessor(old_path_spec)
                new_val = accessor(new_path_spec)
                if old_val is not None and\
                        old_val != new_val:
                    diff = string_diff(old_val, new_val)
                    output.append("  \t%s: %s -> %s;" % (label, old_val, diff))
                elif old_val is None and\
                        new_val is not None and\
                        new_val != "" and\
                        new_val != []:
                    output.append("  %s = %s" % (label,
                                                 new_val))
    return ''.join(output)