def pytest_assertrepr_compare(op: str, left, right) -> Optional[Sequence[str]]:
# set of entities
if op == '==' and isinstance(left, (set, frozenset)) and \
isinstance(right, (set, frozenset)) and \
all(isinstance(v, Entity) for v in left) and \
all(isinstance(v, Entity) for v in right):
def repr_ids(ids: AbstractSet[EntityId]) -> str:
sorted_ids = sorted(
ids,
key=lambda i: (
i[0],
# Since EntityIds usually consist of one letter followed
# by digits, order them numerically. If it's not in
# that format they should be sorted in the other bucket.
(0, int(i[1:])) if i[1:].isdigit() else (1, i[1:])
)
)
return '{' + ', '.join(sorted_ids) + '}'
left = cast(Union[Set[Entity], FrozenSet[Entity]], left)
right = cast(Union[Set[Entity], FrozenSet[Entity]], right)
left_ids = {e.id for e in left}
right_ids = {e.id for e in right}
return [
'{} == {}'.format(repr_ids(left_ids), repr_ids(right_ids)),
'Extra entities in the left set:',
repr_ids(left_ids - right_ids),
'Extra entities in the right set:',
repr_ids(right_ids - left_ids),
]
return None
评论列表
文章目录