Skip to content

AnyOf matcher and its tests#8

Closed
mShono wants to merge 2 commits intomasterfrom
any_of
Closed

AnyOf matcher and its tests#8
mShono wants to merge 2 commits intomasterfrom
any_of

Conversation

@mShono
Copy link
Collaborator

@mShono mShono commented Feb 12, 2025

No description provided.

assert {"a": 1, "b": 2} == DictContains({})


def test_anyof():
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, it should be vice versa =)

Actual value should be equal to one of "AnyOf". Not "AnyOf" is equal to one of the actual.

I.e. it should do:

assert 1 == AnyOf(1, 2, 3)

assert [8, "a", 3.5] == SimilarList(["a", 8, 3.5])
assert [8, "a", 3.5] == SimilarList([3.5, 8, "a"])
assert [8, "a", 3.5] != SimilarList([3.5, 9, "a"])
assert [8, "a", 3.5] != SimilarList([3.5, 8, "a", 10])
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add also test(s) with empty lists, as it's usually a special corner case

return repr(self.value)


class SimilarList:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather name it as "unorderd list" for this particular case.

def __init__(self, value):
self.value = value

def __eq__(self, other):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of implementing its own __eq__, we need to inherite from Matcher and implement _match(self, other). Check, how DictContains works.

@wsnk wsnk closed this Feb 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants