mockify.exc - Library exceptions¶
Module containing Mockify’s warnings and exceptions.
-
exception
mockify.exc.
MockifyWarning
¶ Bases:
Warning
Common base class for Mockify warnings.
New in version 0.6.
-
exception
mockify.exc.
UninterestedCallWarning
¶ Bases:
mockify.exc.MockifyWarning
This warning is used to inform about uninterested call being made.
It is only used when uninterested call strategy is changed in mocking session. See
mockify.core.Session
for more details.New in version 0.6.
-
exception
mockify.exc.
MockifyError
¶ Bases:
Exception
Common base class for all Mockify exceptions.
New in version 0.6.
-
exception
mockify.exc.
MockifyAssertion
¶ Bases:
mockify.exc.MockifyError
,AssertionError
Common base class for all Mockify assertion errors.
With this exception it will be easy to re-raise Mockify-specific assertion exceptions for example during debugging.
New in version 0.6.
-
exception
mockify.exc.
UnexpectedCall
(actual_call, expected_calls)¶ Bases:
mockify.exc.MockifyAssertion
Raised when mock was called with parameters that couldn’t been matched to any of existing expectations.
This exception was added for easier debugging of failing tests; unlike
UninterestedCall
exception, this one signals that there are expectations set for mock that was called.For example, we have expectation defined like this:
from mockify.mock import Mock mock = Mock('mock') mock.expect_call(1, 2)
And if the mock is now called f.e. without params, this exception will be raised:
>>> mock() Traceback (most recent call last): ... mockify.exc.UnexpectedCall: No matching expectations found for call: at <doctest default[0]>:1 ------------------------- Called: mock() Expected (any of): mock(1, 2)
New in version 0.6.
Parameters: - actual_call – Instance of
mockify.core.Call
representing parameters of call that was made - expected_calls – List of
mockify.core.Call
instances, each representing expected parameters of single expectation
-
actual_call
¶ Instance of
mockify.core.Call
with actual call.
-
expected_calls
¶ Sequence of
mockify.core.Call
instances with expected calls.
- actual_call – Instance of
-
exception
mockify.exc.
UnexpectedCallOrder
(actual_call, expected_call)¶ Bases:
mockify.exc.MockifyAssertion
Raised when mock was called but another one is expected to be called before.
This can only be raised if you use ordered expectations with
mockify.core.ordered()
context manager.See Recording ordered expectations for more details.
New in version 0.6.
Parameters: - actual_call – The call that was made
- expected_call – The call that is expected to be made
-
actual_call
¶ Instance of
mockify.core.Call
with actual call.
-
expected_call
¶ Instance of
mockify.core.Call
with expected call.
-
exception
mockify.exc.
UninterestedCall
(actual_call)¶ Bases:
mockify.exc.MockifyAssertion
Raised when call is made to a mock that has no expectations set.
This exception can be disabled by changing unexpected call strategy using
mockify.Session.config
attribute (however, you will have to manually create and share session object to change that).Parameters: actual_call – The call that was made -
actual_call
¶ Instance of
mockify.core.Call
with actual call.
-
-
exception
mockify.exc.
OversaturatedCall
(actual_call, oversaturated_expectation)¶ Bases:
mockify.exc.MockifyAssertion
Raised when mock with actions recorded using
mockify.core.Expectation.will_once()
was called more times than expected and has all recorded actions already consumed.This exception can be avoided if you record repeated action to the end of expected action chain (using
mockify.core.Expectation.will_repeatedly()
). However, it was added for a reason. For example, if your mock returns value of incorrect type (the default one), you’ll result in production code errors instead of mock errors. And that can possibly be harder to debug.Parameters: - actual_call – The call that was made
- oversaturated_expectation – The expectation that was oversaturated
-
actual_call
¶ Instance of
mockify.core.Call
with actual call.
-
oversaturated_expectation
¶ Instance of
mockify.core.Expectation
class representing expectation that was oversaturated.
-
exception
mockify.exc.
Unsatisfied
(unsatisfied_expectations)¶ Bases:
mockify.exc.MockifyAssertion
Raised when unsatisfied expectations are present.
This can only be raised by either
mockify.core.satisfied()
mockify.core.assert_satisfied()
ormockify.core.Session.done()
. You’ll not get this exception when mock is called.Parameters: unsatisfied_expectations – List of all unsatisfied expectations found -
unsatisfied_expectations
¶ List of unsatisfied expectations.
New in version 0.6: Previously it was called
expectations
.
-