mocksafe.WhenStubber
- class mocksafe.WhenStubber(method_mock: MethodMock[T])
Set up conditions for when a stub is to be used.
- Example:
>>> when(mock_random.random).any_call().then_return(0.31)
See:
mocksafe.MatchCallStubber- Example:
>>> when( ... mock_random.randint ... ).called_with( ... mock_random.randint(1, 10) ... ).then_return(7)
>>> mock_random.randint(1, 10) 7
- Example:
>>> when( ... mock_random.randint ... ).call_matching( ... lambda a, b: a <= 3 and b > 3 ... ).then_return(3)
>>> mock_random.randint(2, 6) 3
See:
mocksafe.MatchCallStubber- __init__(method_mock: MethodMock[T])
Methods
__setattr__(name, value, /)Implement setattr(self, name, value).
any_call()Matches any calls made to the mocked method.
call_matching(call_lambda)Use a lambda to determine whether to match a call.
called_with(_)Matches specific calls made to the mocked method.