/usr/lib/python3/dist-packages/mockito/verification.py is in python3-mockito 0.5.2-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 | # Copyright (c) 2008-2013 Szczepan Faber, Serhiy Oplakanets, Herr Kaste
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
__all__ = ['never', 'VerificationError']
class VerificationError(AssertionError):
'''Indicates error during verification of invocations.
Raised if verification fails. Error message contains the cause.
'''
pass
class AtLeast(object):
def __init__(self, wanted_count):
self.wanted_count = wanted_count
def verify(self, invocation, actual_count):
if actual_count < self.wanted_count:
raise VerificationError("\nWanted at least: %i, actual times: %i" % (self.wanted_count, actual_count))
class AtMost(object):
def __init__(self, wanted_count):
self.wanted_count = wanted_count
def verify(self, invocation, actual_count):
if actual_count > self.wanted_count:
raise VerificationError("\nWanted at most: %i, actual times: %i" % (self.wanted_count, actual_count))
class Between(object):
def __init__(self, wanted_from, wanted_to):
self.wanted_from = wanted_from
self.wanted_to = wanted_to
def verify(self, invocation, actual_count):
if actual_count < self.wanted_from or actual_count > self.wanted_to:
raise VerificationError("\nWanted between: [%i, %i], actual times: %i" % (self.wanted_from, self.wanted_to, actual_count))
class Times(object):
def __init__(self, wanted_count):
self.wanted_count = wanted_count
def verify(self, invocation, actual_count):
if actual_count == self.wanted_count:
return
if actual_count == 0:
raise VerificationError("\nWanted but not invoked: %s" % (invocation))
else:
if self.wanted_count == 0:
raise VerificationError("\nUnwanted invocation of %s, times: %i" % (invocation, actual_count))
else:
raise VerificationError("\nWanted times: %i, actual times: %i" % (self.wanted_count, actual_count))
class InOrder(object):
'''
Verifies invocations in order.
Verifies if invocation was in expected order, and if yes -- degrades to original Verifier (AtLeast, Times, Between, ...).
'''
def __init__(self, original_verification):
'''
@param original_verification: Original verifiaction to degrade to if order of invocation was ok.
'''
self.original_verification = original_verification
def verify(self, wanted_invocation, count):
for invocation in reversed(wanted_invocation.mock.invocations):
if not invocation.verified_inorder:
if not wanted_invocation.matches(invocation):
raise VerificationError("\nWanted %s to be invoked, got %s instead" % (wanted_invocation, invocation))
invocation.verified_inorder = True
break
# proceed with original verification
self.original_verification.verify(wanted_invocation, count)
never = 0
|