mockify.matchers - Classes for wildcarding expected arguments

class mockify.matchers.Matcher

Bases: abc.ABC

Abstract base class for matchers.

Changed in version 0.6: Now this inherits from abc.ABC

__eq__(other)

Check if other can be accepted by this matcher.

format_repr(*args, **kwargs)

Return matcher’s textual representation.

Pay attention to this, as it is later used to render string representation of expected call parameters.

__repr__()

Return repr(self).

class mockify.matchers.AnyOf(*values)

Bases: mockify.matchers.Matcher

Matches any value from given list of values.

You can also use matchers in values.

New in version 0.6.

__eq__(other)

Check if other can be accepted by this matcher.

format_repr()

Return matcher’s textual representation.

Pay attention to this, as it is later used to render string representation of expected call parameters.

class mockify.matchers.AllOf(*values)

Bases: mockify.matchers.Matcher

Matches if and only if received value is equal to all given values.

You can also use matchers in values.

New in version 0.6.

__eq__(other)

Check if other can be accepted by this matcher.

format_repr()

Return matcher’s textual representation.

Pay attention to this, as it is later used to render string representation of expected call parameters.

class mockify.matchers.Any

Bases: mockify.matchers.Matcher

Matches any value.

This can be used as a wildcard, when you care about number of arguments in your expectation, not their values or types. This can also be imported as underscore:

from mockify.matchers import _
__eq__(other)

Check if other can be accepted by this matcher.

format_repr()

Return matcher’s textual representation.

Pay attention to this, as it is later used to render string representation of expected call parameters.

class mockify.matchers.Type(*types)

Bases: mockify.matchers.Matcher

Matches any value that is instance of one of given types.

This is useful to record expectations where we do not care about expected value, but we do care about expected value type.

New in version 0.6.

__eq__(other)

Check if other can be accepted by this matcher.

format_repr()

Return matcher’s textual representation.

Pay attention to this, as it is later used to render string representation of expected call parameters.

class mockify.matchers.Regex(pattern, name=None)

Bases: mockify.matchers.Matcher

Matches value if it is a string that matches given regular expression pattern.

Parameters:
  • pattern – Regular expression pattern
  • name

    Optional name for given pattern.

    If given, then name will be used in text representation of this matcher. This can be very handy, especially when regular expression is complex and hard to read. Example:

    >>> r = Regex(r'^[a-z]+$', 'LOWER_ASCII')
    >>> repr(r)
    'Regex(LOWER_ASCII)'
    

New in version 0.6.

__eq__(other)

Check if other can be accepted by this matcher.

format_repr()

Return matcher’s textual representation.

Pay attention to this, as it is later used to render string representation of expected call parameters.

class mockify.matchers.List(matcher, min_length=None, max_length=None)

Bases: mockify.matchers.Matcher

Matches value if it is a list of values matching matcher.

Parameters:
  • matcher

    A matcher that every value in the list is expected to match.

    Use Any matcher if you want to match list containing any values.

  • min_length – Minimal accepted list length
  • max_length – Maximal accepted list length

New in version 0.6.

__eq__(other)

Check if other can be accepted by this matcher.

format_repr()

Return matcher’s textual representation.

Pay attention to this, as it is later used to render string representation of expected call parameters.

class mockify.matchers.Func(func, name=None)

Bases: mockify.matchers.Matcher

Matches value if func returns True for that value.

This is the most generic matcher as you can use your own match function if needed.

Parameters:
  • func – Function to be used to calculate match.
  • name

    Optional name for this matcher.

    This can be used to set a name used to format matcher’s text representation for assertion errors. Here’s a simple example:

    >>> f = Func(lambda x: x > 0, 'POSITIVE_ONLY')
    >>> repr(f)
    'Func(POSITIVE_ONLY)'
    

New in version 0.6.

__eq__(other)

Check if other can be accepted by this matcher.

format_repr()

Return matcher’s textual representation.

Pay attention to this, as it is later used to render string representation of expected call parameters.