Dictionary Matchers¶
Matchers of dictionaries.
has_entries¶
-
class
hamcrest.library.collection.isdict_containingentries.IsDictContainingEntries(value_matchers)¶ Bases:
hamcrest.core.base_matcher.BaseMatcher[Mapping[hamcrest.library.collection.isdict_containingentries.K,hamcrest.library.collection.isdict_containingentries.V]]-
describe_keyvalue(index: int, value: V, description: hamcrest.core.description.Description) → None¶ Describes key-value pair at given index.
-
describe_mismatch(item: Mapping[K, V], mismatch_description: hamcrest.core.description.Description) → None¶ 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 – The item that the
Matcherhas rejected.mismatch_description – The description to be built or appended to.
-
describe_to(description: hamcrest.core.description.Description) → None¶ 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 – The description to be built or appended to.
-
matches(item: Mapping[K, V], mismatch_description: Optional[hamcrest.core.description.Description] = None) → bool¶ Evaluates the matcher for argument item.
If a mismatch is detected and argument
mismatch_descriptionis provided, it will generate a description of why the matcher has not accepted the item.- Parameters
item – The object against which the matcher is evaluated.
mismatch_description –
- Returns
Trueifitemmatches, otherwiseFalse.
-
-
hamcrest.library.collection.isdict_containingentries.has_entries(**keys_valuematchers: Union[hamcrest.core.matcher.Matcher[V], V]) → hamcrest.core.matcher.Matcher[Mapping[str, V]]¶ -
hamcrest.library.collection.isdict_containingentries.has_entries(keys_valuematchers: Mapping[K, Union[hamcrest.core.matcher.Matcher[V], V]]) → hamcrest.core.matcher.Matcher[Mapping[K, V]] -
hamcrest.library.collection.isdict_containingentries.has_entries(*keys_valuematchers: Any) → hamcrest.core.matcher.Matcher[Mapping[Any, Any]] Matches if dictionary contains entries satisfying a dictionary of keys and corresponding value matchers.
- Parameters
matcher_dict – A dictionary mapping keys to associated value matchers, or to expected values for
equal_tomatching.
Note that the keys must be actual keys, not matchers. Any value argument that is not a matcher is implicitly wrapped in an
equal_tomatcher to check for equality.Examples:
has_entries({'foo':equal_to(1), 'bar':equal_to(2)}) has_entries({'foo':1, 'bar':2})
has_entriesalso accepts a list of keyword arguments:-
hamcrest.library.collection.isdict_containingentries.has_entries(keyword1=value_matcher1[, keyword2=value_matcher2[, ...]])¶
- Parameters
keyword1 – A keyword to look up.
valueMatcher1 – The matcher to satisfy for the value, or an expected value for
equal_tomatching.
Examples:
has_entries(foo=equal_to(1), bar=equal_to(2)) has_entries(foo=1, bar=2)
Finally,
has_entriesalso accepts a list of alternating keys and their value matchers:-
hamcrest.library.collection.isdict_containingentries.has_entries(key1, value_matcher1[, ...])¶
- Parameters
key1 – A key (not a matcher) to look up.
valueMatcher1 – The matcher to satisfy for the value, or an expected value for
equal_tomatching.
Examples:
has_entries('foo', equal_to(1), 'bar', equal_to(2)) has_entries('foo', 1, 'bar', 2)
has_entry¶
-
class
hamcrest.library.collection.isdict_containing.IsDictContaining(key_matcher: hamcrest.core.matcher.Matcher[K], value_matcher: hamcrest.core.matcher.Matcher[V])¶ Bases:
hamcrest.core.base_matcher.BaseMatcher[Mapping[hamcrest.library.collection.isdict_containing.K,hamcrest.library.collection.isdict_containing.V]]-
describe_to(description: hamcrest.core.description.Description) → None¶ 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 – The description to be built or appended to.
-
-
hamcrest.library.collection.isdict_containing.has_entry(key_match: Union[K, hamcrest.core.matcher.Matcher[K]], value_match: Union[V, hamcrest.core.matcher.Matcher[V]]) → hamcrest.core.matcher.Matcher[Mapping[K, V]]¶ Matches if dictionary contains key-value entry satisfying a given pair of matchers.
- Parameters
This matcher iterates the evaluated dictionary, searching for any key-value entry that satisfies
key_matchandvalue_match. If a matching entry is found,has_entryis satisfied.Any argument that is not a matcher is implicitly wrapped in an
equal_tomatcher to check for equality.Examples:
has_entry(equal_to('foo'), equal_to(1)) has_entry('foo', 1)
has_key¶
-
class
hamcrest.library.collection.isdict_containingkey.IsDictContainingKey(key_matcher: hamcrest.core.matcher.Matcher[K])¶ Bases:
hamcrest.core.base_matcher.BaseMatcher[Mapping[hamcrest.library.collection.isdict_containingkey.K,Any]]-
describe_to(description: hamcrest.core.description.Description) → None¶ 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 – The description to be built or appended to.
-
-
hamcrest.library.collection.isdict_containingkey.has_key(key_match: Union[K, hamcrest.core.matcher.Matcher[K]]) → hamcrest.core.matcher.Matcher[Mapping[K, Any]]¶ Matches if dictionary contains an entry whose key satisfies a given matcher.
- Parameters
key_match – The matcher to satisfy for the key, or an expected value for
equal_tomatching.
This matcher iterates the evaluated dictionary, searching for any key-value entry whose key satisfies the given matcher. If a matching entry is found,
has_keyis satisfied.Any argument that is not a matcher is implicitly wrapped in an
equal_tomatcher to check for equality.Examples:
has_key(equal_to('foo')) has_key('foo')
has_value¶
-
class
hamcrest.library.collection.isdict_containingvalue.IsDictContainingValue(value_matcher: hamcrest.core.matcher.Matcher[V])¶ Bases:
hamcrest.core.base_matcher.BaseMatcher[Mapping[Any,hamcrest.library.collection.isdict_containingvalue.V]]-
describe_to(description: hamcrest.core.description.Description) → None¶ 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 – The description to be built or appended to.
-
-
hamcrest.library.collection.isdict_containingvalue.has_value(value: Union[V, hamcrest.core.matcher.Matcher[V]]) → hamcrest.core.matcher.Matcher[Mapping[Any, V]]¶ Matches if dictionary contains an entry whose value satisfies a given matcher.
- Parameters
value_match – The matcher to satisfy for the value, or an expected value for
equal_tomatching.
This matcher iterates the evaluated dictionary, searching for any key-value entry whose value satisfies the given matcher. If a matching entry is found,
has_valueis satisfied.Any argument that is not a matcher is implicitly wrapped in an
equal_tomatcher to check for equality.Examples:
has_value(equal_to('bar')) has_value('bar')