mockify.cardinality - Classes for setting expected call cardinality¶
Module containing set of classes to be used with
You can also create your own classes to be used with that method. The only thing required from such class is to implement following interface:
actualcall count is satisfied by
actualis absolute call count expectation received so far. It is completely implementation-specific of which values of
actualare said to be satisfied and which are not. For example,
actualwith fixed value (given via constructor) and return
Trueonly if those two are equal.
minimalexpected call count and return new instance of
In some complex expectation there could be a situation in which expectation must be computed again. This is not visible for library user, but must be done behind the scenes to properly process expectations. Such situation can be presented in this example:>>> from mockify.actions import Return >>> from mockify.mock import Function >>> foo = Function('foo') >>> foo.expect_call(1, 2).will_once(Return(1)).will_repeatedly(Return(2)).times(2) <mockify.Expectation: foo(1, 2)> >>> foo(1, 2) 1 >>> foo(1, 2) 2 >>> foo(1, 2) 2 >>> foo.assert_satisfied()
In example above we’ve used
times(2)to tell that last repeated action is expected to be called twice, but real expected call count is 3 times, as
will_onceis used. Behind the scenes, this is recalculated using this metho.
Return textual representation of expected call count.
This is used by
mockify.exc.Unsatisfiedexception when error message is being rendered.
Property containing minimal call count that is considered valid for given instance.
Used to set minimal expected call count.
If this is used, then expectation is said to be satisfied if actual call count is not less that
Parameters: minimal – Integer value representing minimal expected call count
Used to set maximal expected call count.
If this is used, then expectation is said to be satisfied if actual call count is not greater than
Parameters: maximal – Integer value representing maximal expected call count
Used to set a range of valid call counts.
If this is used, then expectation is said to be satisfied if actual call count is not less than
minimaland not greater than
- minimal – Integer value representing minimal expected call count
- maximal – Integer value representing maximal expected call count
Used to expect fixed call count to be made.
You do not have to use this class explicitly as its instances are automatically created when you call
timesmethod with integer value as argument.
Parameters: expected – Integer value representing expected call count