def assertSameElements(self, expected_seq, actual_seq, msg=None): """An unordered sequence specific comparison. Raises with an error message listing which elements of expected_seq are missing from actual_seq and vice versa if any. """ try: expected = set(expected_seq) actual = set(actual_seq) missing = list(expected.difference(actual)) unexpected = list(actual.difference(expected)) missing.sort() unexpected.sort() except TypeError: # Fall back to slower list-compare if any of the objects are # not hashable. expected = list(expected_seq) actual = list(actual_seq) expected.sort() actual.sort() missing, unexpected = util.sorted_list_difference(expected, actual) errors = [] if missing: errors.append('Expected, but missing:\n %r' % missing) if unexpected: errors.append('Unexpected, but present:\n %r' % unexpected) if errors: standardMsg = '\n'.join(errors) self.fail(self._formatMessage(msg, standardMsg))
def assertExpectatations(actual, expected): def handle_card_card_or_name(seq): return [ c.name if isinstance(c, Card) else c for c in seq ] missing, unexpected = sorted_list_difference( handle_card_card_or_name(expected), handle_card_card_or_name(actual) ) errors = [] if missing: errors.append('Expected, but missing:\n %s' % safe_repr(missing)) if unexpected: errors.append('Unexpected, but present:\n %s' % safe_repr(unexpected)) if errors: message = '\n'.join(errors) raise AssertionError(message)