Sequence Matchers¶
Matchers of sequences.
- class hamcrest.library.collection.issequence_containinginorder.IsSequenceContainingInOrder(matchers)¶
Bases:
BaseMatcher
[Sequence
[T
]]- describe_mismatch(item, mismatch_description)¶
Generates a description of why the matcher has not accepted the item.
The description will be part of a larger description of why a matching failed, so it should be concise.
This method assumes that
matches(item)
isFalse
, but will not check this.- Parameters:
item (Sequence[T]) – The item that the
Matcher
has rejected.mismatch_description (Description) – The description to be built or appended to.
- Return type:
None
- describe_to(description)¶
Generates a description of the object.
The description may be part of a description of a larger object of which this is just a component, so it should be worded appropriately.
- Parameters:
description (Description) – The description to be built or appended to.
- Return type:
None
- matches(item, mismatch_description=None)¶
Evaluates the matcher for argument item.
If a mismatch is detected and argument
mismatch_description
is provided, it will generate a description of why the matcher has not accepted the item.- Parameters:
item (Sequence[T]) – The object against which the matcher is evaluated.
mismatch_description (Optional[Description]) –
- Returns:
True
ifitem
matches, otherwiseFalse
.- Return type:
- hamcrest.library.collection.issequence_containinginorder.contains(*items)¶
Deprecated - use contains_exactly(*items)
- hamcrest.library.collection.issequence_containinginorder.contains_exactly(*items)¶
Matches if sequence’s elements satisfy a given list of matchers, in order.
- Parameters:
- Return type:
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.
- class hamcrest.library.collection.issequence_containinginanyorder.IsSequenceContainingInAnyOrder(matchers)¶
Bases:
BaseMatcher
[Sequence
[T
]]- describe_mismatch(item, mismatch_description)¶
Generates a description of why the matcher has not accepted the item.
The description will be part of a larger description of why a matching failed, so it should be concise.
This method assumes that
matches(item)
isFalse
, but will not check this.- Parameters:
item (Sequence[T]) – The item that the
Matcher
has rejected.mismatch_description (Description) – The description to be built or appended to.
- Return type:
None
- describe_to(description)¶
Generates a description of the object.
The description may be part of a description of a larger object of which this is just a component, so it should be worded appropriately.
- Parameters:
description (Description) – The description to be built or appended to.
- Return type:
None
- matches(item, mismatch_description=None)¶
Evaluates the matcher for argument item.
If a mismatch is detected and argument
mismatch_description
is provided, it will generate a description of why the matcher has not accepted the item.- Parameters:
item (Sequence[T]) – The object against which the matcher is evaluated.
mismatch_description (Optional[Description]) –
- Returns:
True
ifitem
matches, otherwiseFalse
.- Return type:
- hamcrest.library.collection.issequence_containinginanyorder.contains_inanyorder(*items)¶
Matches if sequences’s elements, in any order, satisfy a given list of matchers.
- Parameters:
- Return type:
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.
- class hamcrest.library.collection.issequence_containing.IsSequenceContaining(element_matcher)¶
Bases:
BaseMatcher
[Sequence
[T
]]- Parameters:
element_matcher (Matcher[T]) –
- describe_to(description)¶
Generates a description of the object.
The description may be part of a description of a larger object of which this is just a component, so it should be worded appropriately.
- Parameters:
description (Description) – The description to be built or appended to.
- Return type:
None
- class hamcrest.library.collection.issequence_containing.IsSequenceContainingEvery(*element_matchers)¶
Bases:
BaseMatcher
[Sequence
[T
]]- Parameters:
element_matchers (Matcher[T]) –
- describe_mismatch(item, mismatch_description)¶
Generates a description of why the matcher has not accepted the item.
The description will be part of a larger description of why a matching failed, so it should be concise.
This method assumes that
matches(item)
isFalse
, but will not check this.- Parameters:
item (Sequence[T]) – The item that the
Matcher
has rejected.mismatch_description (Description) – The description to be built or appended to.
- Return type:
None
- describe_to(description)¶
Generates a description of the object.
The description may be part of a description of a larger object of which this is just a component, so it should be worded appropriately.
- Parameters:
description (Description) – The description to be built or appended to.
- Return type:
None
- hamcrest.library.collection.issequence_containing.has_item(match)¶
Matches if any element of sequence satisfies a given matcher.
- Parameters:
match (Union[Matcher[T], T]) – The matcher to satisfy, or an expected value for
equal_to
matching.- Return type:
This matcher iterates the evaluated sequence, searching for any element that satisfies a given matcher. If a matching element is found,
has_item
is satisfied.If the
match
argument is not a matcher, it is implicitly wrapped in anequal_to
matcher to check for equality.
- hamcrest.library.collection.issequence_containing.has_items(*items)¶
Matches if all of the given matchers are satisfied by any elements of the sequence.
- Parameters:
- Return type:
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.
- class hamcrest.library.collection.isin.IsIn(sequence)¶
Bases:
BaseMatcher
[T
]- Parameters:
sequence (Sequence[T]) –
- describe_to(description)¶
Generates a description of the object.
The description may be part of a description of a larger object of which this is just a component, so it should be worded appropriately.
- Parameters:
description (Description) – The description to be built or appended to.
- Return type:
None
- hamcrest.library.collection.isin.is_in(sequence)¶
Matches if evaluated object is present in a given sequence.
This matcher invokes the
in
membership operator to determine if the evaluated object is a member of the sequence.
- class hamcrest.library.collection.issequence_onlycontaining.IsSequenceOnlyContaining(matcher)¶
Bases:
BaseMatcher
[Sequence
[T
]]- Parameters:
matcher (Matcher[T]) –
- describe_to(description)¶
Generates a description of the object.
The description may be part of a description of a larger object of which this is just a component, so it should be worded appropriately.
- Parameters:
description (Description) – The description to be built or appended to.
- Return type:
None
- hamcrest.library.collection.issequence_onlycontaining.only_contains(*items)¶
Matches if each element of sequence satisfies any of the given matchers.
- Parameters:
- Return type:
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.
- class hamcrest.library.collection.is_empty.IsEmpty¶
Bases:
BaseMatcher
[Sized
]- describe_to(description)¶
Generates a description of the object.
The description may be part of a description of a larger object of which this is just a component, so it should be worded appropriately.
- Parameters:
description (Description) – The description to be built or appended to.
- Return type:
None
- matches(item, mismatch_description=None)¶
Evaluates the matcher for argument item.
If a mismatch is detected and argument
mismatch_description
is provided, it will generate a description of why the matcher has not accepted the item.- Parameters:
item (Sized) – The object against which the matcher is evaluated.
mismatch_description (Optional[Description]) –
- Returns:
True
ifitem
matches, otherwiseFalse
.- Return type: