Matchers that inspect objects.
Matches if object is equal to a given object.
| Parameters: | obj – The object to compare against as the expected value. |
|---|
This matcher compares the evaluated object to obj for equality.
Matches if len(item) satisfies a given matcher.
| Parameters: | match – The matcher to satisfy, or an expected value for equal_to matching. |
|---|
This matcher invokes the len function on the evaluated object to get its length, passing the result to a given matcher for evaluation.
If the match argument is not a matcher, it is implicitly wrapped in an equal_to matcher to check for :equality.
Examples:
has_length(greater_than(6))
has_length(5)
Matches if str(item) satisfies a given matcher.
| Parameters: | match – The matcher to satisfy, or an expected value for equal_to matching. |
|---|
This matcher invokes the str function on the evaluated object to get its length, passing the result to a given matcher for evaluation. If the match argument is not a matcher, it is implicitly wrapped in an equal_to matcher to check for equality.
Examples:
has_string(starts_with('foo'))
has_string('bar')
Matches if object has a property with a given name whose value satisfies a given matcher.
| Parameters: |
|
|---|
This matcher determines if the evaluated object has a property with a given name. If no such property is found, has_property is not satisfied.
If the property is found, its value is passed to a given matcher for evaluation. If the match argument is not a matcher, it is implicitly wrapped in an equal_to matcher to check for equality.
If the match argument is not provided, the anything matcher is used so that has_property is satisfied if a matching property is found.
Examples:
has_property('name', starts_with('J'))
has_property('name', 'Jon')
has_property('name')
Matches if object is an instance of, or inherits from, a given type.
| Parameters: | atype – The type to compare against as the expected type. |
|---|
This matcher checks whether the evaluated object is an instance of atype or an instance of any class that inherits from atype.
Example:
instance_of(str)
Matches if object is None.
Matches if object is not None.
Matches if evaluated object is the same instance as a given object.
| Parameters: | obj – The object to compare against as the expected value. |
|---|
This matcher invokes the is identity operator to determine if the evaluated object is the the same object as obj.