Logical matchers
Logical matchers can be used to logically combine other matchers.
Not
Match the negative of the given matcher
For example:
# Matches anything that isn't a string
assert 1 == Not(Any(str))
# Matches anything that is not "nice"
assert 68 == Not("nice")
Parameters:
Name | Type | Description | Default |
---|---|---|---|
matcher |
object
|
matcher to negate |
required |
And
Match all of the given matchers
For example:
# Matches any string that doesn't match with the
# regex "hello*"
And(Any(str), Not(StringMatchingRegex("hello*")))
Parameters:
Name | Type | Description | Default |
---|---|---|---|
matchers |
object
|
matchers to use |
()
|
Or
Match at least one of the given matchers
For example:
# Matches any object that is a str or int
Or(Any(str), Any(int))
Parameters:
Name | Type | Description | Default |
---|---|---|---|
matchers |
object
|
matchers to use |
()
|
Xor
Match exactly one of the given matchers
For example:
# Matches any object that is a str or int, but not both
# Yes I know this a bit of a bad example, but I can't come up with
# anything right now ok
Xor(Any(str), Any(int))
Parameters:
Name | Type | Description | Default |
---|---|---|---|
matchers |
object
|
matchers to use |
()
|