mockify.cardinality - Classes for setting expected call cardinality

class mockify.cardinality.ActualCallCount(initial_value)

Bases: object

Proxy class that is used to calculate actual mock calls.

Provides all needed arithmetic operators and a logic of rendering actual call message that is used in assertion messages.

Here’s an example:

>>> from mockify.cardinality import ActualCallCount
>>> str(ActualCallCount(0))
'never called'
>>> str(ActualCallCount(1))
'called once'

New in version 0.6.

__str__()

Return str(self).

class mockify.cardinality.ExpectedCallCount

Bases: abc.ABC

Abstract base class for classes used to set expected call count on mock objects.

New in version 0.6.

__str__()

Format message to be used in assertion reports.

This message must state how many times the mock was expected to be called and will only be evaluated if expectation is not satisfied.

match(actual_call_count)

Check if actual_call_count matches expected call count.

adjust_minimal(minimal)

Make a new cardinality object based on its current state and given minimal.

format_params(*args, **kwargs)

Format params to be used in repr().

This method must be overloaded without params, and call super().format_params(…) with args and kwargs you want to include in repr().

class mockify.cardinality.Exactly(expected)

Bases: mockify.cardinality.ExpectedCallCount

Used to set expected call count to fixed expected value.

Expectations marked with this cardinality object will have to be called exactly expected number of times to be satisfied.

You do not have to use this class explicitly as its instances are automatically created when you call mockify.Expectation.times() method with integer value as argument.

__str__()

Format message to be used in assertion reports.

This message must state how many times the mock was expected to be called and will only be evaluated if expectation is not satisfied.

match(actual_call_count)

Check if actual_call_count matches expected call count.

adjust_minimal(minimal)

Make a new cardinality object based on its current state and given minimal.

format_params()

Format params to be used in repr().

This method must be overloaded without params, and call super().format_params(…) with args and kwargs you want to include in repr().

class mockify.cardinality.AtLeast(minimal)

Bases: mockify.cardinality.ExpectedCallCount

Used to set expected call count to given minimal value.

Expectation will be satisfied if called not less times that given minimal.

__str__()

Format message to be used in assertion reports.

This message must state how many times the mock was expected to be called and will only be evaluated if expectation is not satisfied.

match(actual_call_count)

Check if actual_call_count matches expected call count.

adjust_minimal(minimal)

Make a new cardinality object based on its current state and given minimal.

format_params()

Format params to be used in repr().

This method must be overloaded without params, and call super().format_params(…) with args and kwargs you want to include in repr().

class mockify.cardinality.AtMost(maximal)

Bases: mockify.cardinality.ExpectedCallCount

Used to set expected call count to given maximal value.

If this is used, then expectation is said to be satisfied if actual call count is not greater than maximal.

__str__()

Format message to be used in assertion reports.

This message must state how many times the mock was expected to be called and will only be evaluated if expectation is not satisfied.

match(actual_call_count)

Check if actual_call_count matches expected call count.

adjust_minimal(minimal)

Make a new cardinality object based on its current state and given minimal.

format_params()

Format params to be used in repr().

This method must be overloaded without params, and call super().format_params(…) with args and kwargs you want to include in repr().

class mockify.cardinality.Between(minimal, maximal)

Bases: mockify.cardinality.ExpectedCallCount

Used to set a range of expected call counts between minimal and maximal, both included.

If this is used, then expectation is said to be satisfied if actual call count is not less than minimal and not greater than maximal.

__str__()

Format message to be used in assertion reports.

This message must state how many times the mock was expected to be called and will only be evaluated if expectation is not satisfied.

match(actual_call_count)

Check if actual_call_count matches expected call count.

adjust_minimal(minimal)

Make a new cardinality object based on its current state and given minimal.

format_params()

Format params to be used in repr().

This method must be overloaded without params, and call super().format_params(…) with args and kwargs you want to include in repr().