Sequence Matchers¶
Matchers of sequences.
See also, Sequence matcher internals.
contains_exactly¶
- hamcrest.library.collection.issequence_containinginorder.contains_exactly(*items)¶
Matches if sequence’s elements satisfy a given list of matchers, in order.
- Parameters
match1,... – A comma-separated list of matchers.
items (Union[hamcrest.core.matcher.Matcher[hamcrest.library.collection.issequence_containinginorder.T], hamcrest.library.collection.issequence_containinginorder.T]) –
- Return type
hamcrest.core.matcher.Matcher[Sequence[hamcrest.library.collection.issequence_containinginorder.T]]
This matcher iterates the evaluated sequence and a given list of matchers, seeing if each element satisfies its corresponding matcher.
Any argument that is not a matcher is implicitly wrapped in an
equal_to
matcher to check for equality.
contains_inanyorder¶
- hamcrest.library.collection.issequence_containinginanyorder.contains_inanyorder(*items)¶
Matches if sequences’s elements, in any order, satisfy a given list of matchers.
- Parameters
match1,... – A comma-separated list of matchers.
items (Union[hamcrest.core.matcher.Matcher[hamcrest.library.collection.issequence_containinginanyorder.T], hamcrest.library.collection.issequence_containinginanyorder.T]) –
- Return type
hamcrest.core.matcher.Matcher[Sequence[hamcrest.library.collection.issequence_containinginanyorder.T]]
This matcher iterates the evaluated sequence, seeing if each element satisfies any of the given matchers. The matchers are tried from left to right, and when a satisfied matcher is found, it is no longer a candidate for the remaining elements. If a one-to-one correspondence is established between elements and matchers,
contains_inanyorder
is satisfied.Any argument that is not a matcher is implicitly wrapped in an
equal_to
matcher to check for equality.
has_item, has_items¶
- hamcrest.library.collection.issequence_containing.has_items(*items)¶
Matches if all of the given matchers are satisfied by any elements of the sequence.
- Parameters
match1,... – A comma-separated list of matchers.
items (Union[hamcrest.core.matcher.Matcher[hamcrest.library.collection.issequence_containing.T], hamcrest.library.collection.issequence_containing.T]) –
- Return type
hamcrest.core.matcher.Matcher[Sequence[hamcrest.library.collection.issequence_containing.T]]
This matcher iterates the given matchers, searching for any elements in the evaluated sequence that satisfy them. If each matcher is satisfied, then
has_items
is satisfied.Any argument that is not a matcher is implicitly wrapped in an
equal_to
matcher to check for equality.
is_in¶
- hamcrest.library.collection.isin.is_in(sequence)¶
Matches if evaluated object is present in a given sequence.
- Parameters
sequence (Sequence[hamcrest.library.collection.isin.T]) – The sequence to search.
- Return type
hamcrest.core.matcher.Matcher[hamcrest.library.collection.isin.T]
This matcher invokes the
in
membership operator to determine if the evaluated object is a member of the sequence.
only_contains¶
- hamcrest.library.collection.issequence_onlycontaining.only_contains(*items)¶
Matches if each element of sequence satisfies any of the given matchers.
- Parameters
match1,... – A comma-separated list of matchers.
items (Union[hamcrest.core.matcher.Matcher[hamcrest.library.collection.issequence_onlycontaining.T], hamcrest.library.collection.issequence_onlycontaining.T]) –
- Return type
hamcrest.core.matcher.Matcher[Sequence[hamcrest.library.collection.issequence_onlycontaining.T]]
This matcher iterates the evaluated sequence, confirming whether each element satisfies any of the given matchers.
Example:
only_contains(less_than(4))
will match
[3,1,2]
.Any argument that is not a matcher is implicitly wrapped in an
equal_to
matcher to check for equality.
empty¶
- hamcrest.library.collection.is_empty.empty()¶
This matcher matches any collection-like object that responds to the __len__ method, and has a length of 0.
- Return type