mockify.cardinality - Classes for setting expected call cardinality

Module containing types to be used to set expected number of mock calls.

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.

__repr__()

Return repr(self).

__str__()

Return str(self).

value

Number of actual mock calls.

class mockify.cardinality.ExpectedCallCount

Bases: mockify.abc.IExpectedCallCountMatcher, mockify._utils.DictEqualityMixin

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

New in version 0.6.

__repr__()

Return textual representation of expected call count object.

Since __str__() is used to render textual message of expected call count, this should render actual object representation, i.e. module, name, params it was created with etc.

Changed in version 0.11: Now this is made abstract and previous format_params() was removed.

__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.

adjust_minimal(minimal)

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

This produces a new ExpectedCallCount instance, but taking into account that some restrictions are already specified, f.e. with use of Session.will_once().

match(actual_call_count)

Check if actual_call_count matches expected call count.

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.core.Expectation.times() method with integer value as argument.

__repr__()

Return textual representation of expected call count object.

Since __str__() is used to render textual message of expected call count, this should render actual object representation, i.e. module, name, params it was created with etc.

Changed in version 0.11: Now this is made abstract and previous format_params() was removed.

__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.

adjust_minimal(minimal)

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

This produces a new ExpectedCallCount instance, but taking into account that some restrictions are already specified, f.e. with use of Session.will_once().

match(actual_call_count)

Check if actual_call_count matches expected call count.

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.

__repr__()

Return textual representation of expected call count object.

Since __str__() is used to render textual message of expected call count, this should render actual object representation, i.e. module, name, params it was created with etc.

Changed in version 0.11: Now this is made abstract and previous format_params() was removed.

__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.

adjust_minimal(minimal)

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

This produces a new ExpectedCallCount instance, but taking into account that some restrictions are already specified, f.e. with use of Session.will_once().

match(actual_call_count)

Check if actual_call_count matches expected call count.

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.

__repr__()

Return textual representation of expected call count object.

Since __str__() is used to render textual message of expected call count, this should render actual object representation, i.e. module, name, params it was created with etc.

Changed in version 0.11: Now this is made abstract and previous format_params() was removed.

__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.

adjust_minimal(minimal)

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

This produces a new ExpectedCallCount instance, but taking into account that some restrictions are already specified, f.e. with use of Session.will_once().

match(actual_call_count)

Check if actual_call_count matches expected call count.

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.

__repr__()

Return textual representation of expected call count object.

Since __str__() is used to render textual message of expected call count, this should render actual object representation, i.e. module, name, params it was created with etc.

Changed in version 0.11: Now this is made abstract and previous format_params() was removed.

__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.

adjust_minimal(minimal)

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

This produces a new ExpectedCallCount instance, but taking into account that some restrictions are already specified, f.e. with use of Session.will_once().

match(actual_call_count)

Check if actual_call_count matches expected call count.