Beispiel #1
0
    def test_equality(self):
        """Collection elements should be matched regardless of its ordering"""
        class Obj:
            """Non comparable object"""
            # pylint: disable=R0903
            def __init__(self, attr):
                self.attr = attr

            def __repr__(self):
                return '<Obj: attr={}>'.format(repr(self.attr))

        UnOrderedCollectionMatcher.register_equalityfunc(
            Obj,
            lambda x, y: x.attr == y.attr
        )

        equals = (
            [[Obj(1)], [Obj(1)]],
            [[Obj(1), Obj(2), Obj(3)], [Obj(1), Obj(2), Obj(3)]],
            [[Obj(1), Obj(2), Obj(3)], [Obj(2), Obj(3), Obj(1)]]
        )
        not_equals = (
            [[Obj(1)], [Obj(2)]],
            [[Obj(1), Obj(2), Obj(3)], [Obj(3), Obj(2)]],
            [[Obj(1), Obj(2)], [Obj(2), Obj(1), Obj(3)]]
        )
        for expected, actual in equals:
            expected = UnOrderedCollectionMatcher(expected)
            self.assertEqual(expected, actual)
        for expected, actual in not_equals:
            expected = UnOrderedCollectionMatcher(expected)
            self.assertNotEqual(expected, actual)
Beispiel #2
0
    def test_equality(self):
        """Collection elements should be matched regardless of its ordering"""
        class Obj:
            """Non comparable object"""

            # pylint: disable=R0903
            def __init__(self, attr):
                self.attr = attr

            def __repr__(self):
                return '<Obj: attr={}>'.format(repr(self.attr))

        UnOrderedCollectionMatcher.register_equalityfunc(
            Obj, lambda x, y: x.attr == y.attr)

        equals = ([[Obj(1)], [Obj(1)]], [[Obj(1), Obj(2),
                                          Obj(3)],
                                         [Obj(1), Obj(2),
                                          Obj(3)]], [[Obj(1),
                                                      Obj(2),
                                                      Obj(3)],
                                                     [Obj(2),
                                                      Obj(3),
                                                      Obj(1)]])
        not_equals = ([[Obj(1)],
                       [Obj(2)]], [[Obj(1), Obj(2), Obj(3)],
                                   [Obj(3),
                                    Obj(2)]], [[Obj(1), Obj(2)],
                                               [Obj(2), Obj(1),
                                                Obj(3)]])
        for expected, actual in equals:
            expected = UnOrderedCollectionMatcher(expected)
            self.assertEqual(expected, actual)
        for expected, actual in not_equals:
            expected = UnOrderedCollectionMatcher(expected)
            self.assertNotEqual(expected, actual)
Beispiel #3
0
                             defaultconfig=None, command_options=None,
                             result_creator=None):
        # pylint: disable=too-many-arguments
        checker_spec = {}
        fields_map = {
            TASKNAME: taskname,
            COMMAND: command,
            DEFAULTCONFIG: defaultconfig,
            COMMAND_OPTIONS: command_options,
            RESULT_CREATOR: result_creator
        }
        for fieldname in fields_map:
            value = fields_map[fieldname]
            if value is None:
                continue
            checker_spec[fieldname] = value
        return checker_spec

def _is_tasks_equal(expected, actual):
    # pylint: disable=protected-access
    """Check is two Task objects are equal."""
    return isinstance(expected, Task) and \
        isinstance(actual, Task) and \
        expected.taskname == actual.taskname and \
        expected._build_command() == actual._build_command() and \
        expected.config == actual.config and \
        expected.result_creator == actual.result_creator


UnOrderedCollectionMatcher.register_equalityfunc(Task, _is_tasks_equal)