def test_all_fn(self): obj = CompareSet(['aaa', 'bbb', 'ddd']) key = lambda x: len(x) == 3 self.assertTrue(obj.all(key)) obj = CompareSet(['aaa1', 'aaa2', 'bbb1']) key = lambda x: str(x).startswith('aaa') self.assertFalse(obj.all(key))
def assertEqual(self, first, second, msg=None): """Fail if *first* does not satisfy *second* as determined by appropriate validation comparison. If *first* and *second* are comparable, a failure will raise a DataError containing the differences between the two. If the *second* argument is a helper-function (or other callable), it is used as a key which must return True for acceptable values. """ if not isinstance(first, BaseCompare): if isinstance(first, str) or not isinstance(first, Container): first = CompareSet([first]) elif isinstance(first, Set): first = CompareSet(first) elif isinstance(first, Mapping): first = CompareDict(first) if callable(second): equal = first.all(second) default_msg = 'first object contains invalid items' else: equal = first == second default_msg = 'first object does not match second object' if not equal: differences = first.compare(second) self.fail(msg or default_msg, differences)