Hello community, here is the log from the commit of package python-mockito for openSUSE:Factory checked in at 2019-04-08 20:53:42 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/python-mockito (Old) and /work/SRC/openSUSE:Factory/.python-mockito.new.3908 (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "python-mockito" Mon Apr 8 20:53:42 2019 rev:7 rq:692235 version:1.1.1 Changes: -------- --- /work/SRC/openSUSE:Factory/python-mockito/python-mockito.changes 2018-12-24 11:39:44.845539664 +0100 +++ /work/SRC/openSUSE:Factory/.python-mockito.new.3908/python-mockito.changes 2019-04-08 20:53:43.894576965 +0200 @@ -1,0 +2,17 @@ +Mon Apr 8 08:58:08 UTC 2019 - Tomáš Chvátal <[email protected]> + +- Disable python3 building as the mockito is py2 only (git master + is py3 compatible so hopefully next release should be supported) + +------------------------------------------------------------------- +Fri Apr 5 12:38:51 UTC 2019 - Tomáš Chvátal <[email protected]> + +- Update to 1.1.1: + * Added forget_invocations function. Thanks to @maximkulkin + * Fix: The context manager (with) has now a proper implementation + * Fix: Calling patch with two arguments can now be used with with + * Fix: Do not treat the placeholder arguments (Ellipsis, args, kwargs) as special on call time anymore. (T.i. they only have a meaning when stubbing or verifying.) + * Enhancement: Changed some truthy or equality tests to identity (is) tests. This reduces edge-cases where some user object defines __eq__ or __bool__. (Hello _numpy_!) +- Run tests + +------------------------------------------------------------------- Old: ---- mockito-1.0.12.tar.gz New: ---- mockito-1.1.1.tar.gz ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ python-mockito.spec ++++++ --- /var/tmp/diff_new_pack.1aLjwM/_old 2019-04-08 20:53:44.734577582 +0200 +++ /var/tmp/diff_new_pack.1aLjwM/_new 2019-04-08 20:53:44.734577582 +0200 @@ -1,7 +1,7 @@ # # spec file for package python-mockito # -# Copyright (c) 2018 SUSE LINUX GmbH, Nuernberg, Germany. +# Copyright (c) 2019 SUSE LINUX GmbH, Nuernberg, Germany. # # All modifications and additions to the file contributed by third parties # remain the property of their copyright owners, unless otherwise agreed @@ -17,14 +17,17 @@ %{?!python_module:%define python_module() python-%{**} python3-%{**}} +%define skip_python3 1 Name: python-mockito -Version: 1.0.12 +Version: 1.1.1 Release: 0 Summary: Spying framework License: MIT Group: Development/Languages/Python -Url: http://mockito-python.readthedocs.io/en/latest/ +URL: https://github.com/kaste/mockito-python Source: https://files.pythonhosted.org/packages/source/m/mockito/mockito-%{version}.tar.gz +BuildRequires: %{python_module numpy} +BuildRequires: %{python_module pytest} BuildRequires: %{python_module setuptools} BuildRequires: fdupes BuildRequires: python-rpm-macros @@ -47,6 +50,9 @@ %python_install %python_expand %fdupes %{buildroot}%{$python_sitelib} +%check +%pytest + %files %{python_files} %doc AUTHORS CHANGES.txt README.rst %license LICENSE ++++++ mockito-1.0.12.tar.gz -> mockito-1.1.1.tar.gz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/mockito-1.0.12/CHANGES.txt new/mockito-1.1.1/CHANGES.txt --- old/mockito-1.0.12/CHANGES.txt 2017-06-03 14:40:32.000000000 +0200 +++ new/mockito-1.1.1/CHANGES.txt 2018-08-28 21:22:02.000000000 +0200 @@ -1,6 +1,25 @@ MOCKITO CHANGE LOG ================== +Release 1.1.1 (August 28, 2018) +------------------------------- + +- Fix: The context manager (``with``) has now a proper implementation +- Fix: Calling ``patch`` with two arguments can now be used with ``with`` +- Fix: Do not treat the placeholder arguments (Ellipsis, args, kwargs) as special on call time anymore. (T.i. they only have a meaning when stubbing or verifying.) +- Enhancement: Changed some truthy or equality tests to identity (``is``) tests. This reduces edge-cases where some user object defines ``__eq__`` or ``__bool__``. (Hello _numpy_!) + + +Release 1.1.0 (May 2, 2018) +--------------------------- + +- Added ``forget_invocations`` function. Thanks to @maximkulkin + +This is generally useful if you already call mocks during your setup routine. +Now you could call ``forget_invocations`` at the end of your setup, and +have a clean 'recording' for your actual test code. T.i. you don't have +to count the invocations from your setup code anymore. + Release 1.0.12 (June 3, 2017) ----------------------------- diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/mockito-1.0.12/PKG-INFO new/mockito-1.1.1/PKG-INFO --- old/mockito-1.0.12/PKG-INFO 2017-06-03 14:40:54.000000000 +0200 +++ new/mockito-1.1.1/PKG-INFO 2018-08-28 21:22:38.000000000 +0200 @@ -1,12 +1,13 @@ -Metadata-Version: 1.1 +Metadata-Version: 1.2 Name: mockito -Version: 1.0.12 +Version: 1.1.1 Summary: Spying framework Home-page: https://github.com/kaste/mockito-python -Author: herr.kaste -Author-email: [email protected] +Maintainer: herr.kaste +Maintainer-email: [email protected] License: MIT -Description: Mockito is a spying framework originally based on the Java library with the same name. +Description: Mockito is a spying framework originally based on `the Java library with the same name + <https://github.com/mockito/mockito>`_. .. image:: https://travis-ci.org/kaste/mockito-python.svg?branch=master :target: https://travis-ci.org/kaste/mockito-python diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/mockito-1.0.12/README.rst new/mockito-1.1.1/README.rst --- old/mockito-1.0.12/README.rst 2017-06-03 14:40:32.000000000 +0200 +++ new/mockito-1.1.1/README.rst 2018-08-28 21:22:02.000000000 +0200 @@ -1,4 +1,5 @@ -Mockito is a spying framework originally based on the Java library with the same name. +Mockito is a spying framework originally based on `the Java library with the same name +<https://github.com/mockito/mockito>`_. .. image:: https://travis-ci.org/kaste/mockito-python.svg?branch=master :target: https://travis-ci.org/kaste/mockito-python diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/mockito-1.0.12/mockito/__init__.py new/mockito-1.1.1/mockito/__init__.py --- old/mockito-1.0.12/mockito/__init__.py 2017-06-03 14:40:32.000000000 +0200 +++ new/mockito-1.1.1/mockito/__init__.py 2018-08-28 21:22:02.000000000 +0200 @@ -22,9 +22,9 @@ from .mockito import ( - when, when2, patch, expect, unstub, verify, verifyNoMoreInteractions, - verifyZeroInteractions, verifyNoUnwantedInteractions, - verifyStubbedInvocationsAreUsed, + when, when2, patch, expect, unstub, forget_invocations, + verify, verifyNoMoreInteractions, verifyZeroInteractions, + verifyNoUnwantedInteractions, verifyStubbedInvocationsAreUsed, ArgumentError) from . import inorder from .spying import spy, spy2 @@ -34,12 +34,12 @@ from .matchers import * # noqa: F403 from .verification import never -__version__ = '1.0.12' +__version__ = '1.1.1' __all__ = ['mock', 'spy', 'spy2', 'when', 'when2', 'patch', 'expect', 'verify', 'verifyNoMoreInteractions', 'verifyZeroInteractions', 'verifyNoUnwantedInteractions', 'verifyStubbedInvocationsAreUsed', - 'inorder', 'unstub', + 'inorder', 'unstub', 'forget_invocations', 'VerificationError', 'ArgumentError', 'any', # compatibility 'contains', # compatibility diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/mockito-1.0.12/mockito/invocation.py new/mockito-1.1.1/mockito/invocation.py --- old/mockito-1.0.12/mockito/invocation.py 2017-06-03 14:40:32.000000000 +0200 +++ new/mockito-1.1.1/mockito/invocation.py 2018-08-28 21:22:02.000000000 +0200 @@ -21,7 +21,7 @@ from . import matchers from . import signature from . import verification as verificationModule -from .mock_registry import mock_registry +from .utils import contains_strict from collections import deque import functools @@ -53,6 +53,19 @@ params = ", ".join(args + kwargs) return "%s(%s)" % (self.method_name, params) + +class RememberedInvocation(Invocation): + def __init__(self, mock, method_name): + super(RememberedInvocation, self).__init__(mock, method_name) + self.verified = False + self.verified_inorder = False + + def ensure_mocked_object_has_method(self, method_name): + if not self.mock.has_method(method_name): + raise InvocationError( + "You tried to call a method '%s' the object (%s) doesn't " + "have." % (method_name, self.mock.mocked_obj)) + def ensure_signature_matches(self, method_name, args, kwargs): sig = self.mock.get_signature(method_name) if not sig: @@ -60,6 +73,60 @@ signature.match_signature(sig, args, kwargs) + def __call__(self, *params, **named_params): + if self.strict: + self.ensure_mocked_object_has_method(self.method_name) + self.ensure_signature_matches( + self.method_name, params, named_params) + + self._remember_params(params, named_params) + self.mock.remember(self) + + for matching_invocation in self.mock.stubbed_invocations: + if matching_invocation.matches(self): + matching_invocation.should_answer(self) + return matching_invocation.answer_first( + *params, **named_params) + + if self.strict: + stubbed_invocations = self.mock.stubbed_invocations or [None] + raise InvocationError(""" +You called + + %s, + +which is not expected. Stubbed invocations are: + + %s + +(Set strict to False to bypass this check.) +""" % (self, "\n ".join(str(invoc) for invoc in stubbed_invocations))) + + return None + + +class RememberedProxyInvocation(Invocation): + '''Remeber params and proxy to method of original object. + + Calls method on original object and returns it's return value. + ''' + def __init__(self, mock, method_name): + super(RememberedProxyInvocation, self).__init__(mock, method_name) + self.verified = False + self.verified_inorder = False + + def __call__(self, *params, **named_params): + self._remember_params(params, named_params) + self.mock.remember(self) + obj = self.mock.spec + try: + method = getattr(obj, self.method_name) + except AttributeError: + raise AttributeError( + "You tried to call method '%s' which '%s' instance does not " + "have." % (self.method_name, obj)) + return method(*params, **named_params) + class MatchingInvocation(Invocation): @staticmethod @@ -72,17 +139,23 @@ return True def _remember_params(self, params, named_params): - if Ellipsis in params and (params[-1] is not Ellipsis or named_params): + if ( + contains_strict(params, Ellipsis) + and (params[-1] is not Ellipsis or named_params) + ): raise TypeError('Ellipsis must be the last argument you specify.') - if matchers.args in params: + if contains_strict(params, matchers.args): raise TypeError('args must be used as *args') - if matchers.kwargs in params or matchers.KWARGS_SENTINEL in params: + if ( + contains_strict(params, matchers.kwargs) + or contains_strict(params, matchers.KWARGS_SENTINEL) + ): raise TypeError('kwargs must be used as **kwargs') def wrap(p): - if p in (any, matchers.any_): + if p is any or p is matchers.any_: return matchers.any_() return p @@ -117,8 +190,9 @@ return False for key, p1 in sorted( - self.named_params.iteritems(), - key=lambda (k, v): 1 if k is matchers.KWARGS_SENTINEL else 0): + self.named_params.iteritems(), + key=lambda k_v: 1 if k_v[0] is matchers.KWARGS_SENTINEL else 0 + ): if key is matchers.KWARGS_SENTINEL: break @@ -136,73 +210,6 @@ return True -class RememberedInvocation(Invocation): - def __init__(self, mock, method_name): - super(RememberedInvocation, self).__init__(mock, method_name) - self.verified = False - self.verified_inorder = False - - def ensure_mocked_object_has_method(self, method_name): - if not self.mock.has_method(method_name): - raise InvocationError( - "You tried to call a method '%s' the object (%s) doesn't " - "have." % (method_name, self.mock.mocked_obj)) - - def __call__(self, *params, **named_params): - if self.strict: - self.ensure_mocked_object_has_method(self.method_name) - self.ensure_signature_matches( - self.method_name, params, named_params) - - self._remember_params(params, named_params) - self.mock.remember(self) - - for matching_invocation in self.mock.stubbed_invocations: - if matching_invocation.matches(self): - matching_invocation.should_answer(self) - return matching_invocation.answer_first( - *params, **named_params) - - if self.strict: - stubbed_invocations = self.mock.stubbed_invocations or [None] - raise InvocationError(""" -You called - - %s, - -which is not expected. Stubbed invocations are: - - %s - -(Set strict to False to bypass this check.) -""" % (self, "\n ".join(str(invoc) for invoc in stubbed_invocations))) - - return None - - -class RememberedProxyInvocation(Invocation): - '''Remeber params and proxy to method of original object. - - Calls method on original object and returns it's return value. - ''' - def __init__(self, mock, method_name): - super(RememberedProxyInvocation, self).__init__(mock, method_name) - self.verified = False - self.verified_inorder = False - - def __call__(self, *params, **named_params): - self._remember_params(params, named_params) - self.mock.remember(self) - obj = self.mock.spec - try: - method = getattr(obj, self.method_name) - except AttributeError: - raise AttributeError( - "You tried to call method '%s' which '%s' instance does not " - "have." % (self.method_name, obj)) - return method(*params, **named_params) - - class VerifiableInvocation(MatchingInvocation): def __init__(self, mock, method_name, verification): super(VerifiableInvocation, self).__init__(mock, method_name) @@ -274,6 +281,13 @@ "You tried to stub a method '%s' the object (%s) doesn't " "have." % (method_name, self.mock.mocked_obj)) + def ensure_signature_matches(self, method_name, args, kwargs): + sig = self.mock.get_signature(method_name) + if not sig: + return + + signature.match_signature_allowing_placeholders(sig, args, kwargs) + def __call__(self, *params, **named_params): if self.strict: self.ensure_mocked_object_has_method(self.method_name) @@ -285,6 +299,9 @@ self.mock.finish_stubbing(self) return AnswerSelector(self) + def forget_self(self): + self.mock.forget_stubbed_invocation(self) + def add_answer(self, answer): self.answers.add(answer) @@ -371,7 +388,7 @@ pass def __exit__(self, *exc_info): - mock_registry.unstub(self.invocation.mock.mocked_obj) + self.invocation.forget_self() class CompositeAnswer(object): diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/mockito-1.0.12/mockito/mock_registry.py new/mockito-1.1.1/mockito/mock_registry.py --- old/mockito-1.0.12/mockito/mock_registry.py 2017-06-03 14:40:32.000000000 +0200 +++ new/mockito-1.1.1/mockito/mock_registry.py 2018-08-28 21:22:02.000000000 +0200 @@ -64,7 +64,7 @@ self._store.append((key, value)) def remove(self, key): - self._store = filter(lambda (k, v): k != key, self._store) + self._store = filter(lambda k_v: k_v[0] != key, self._store) def pop(self, key): rv = self.get(key) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/mockito-1.0.12/mockito/mocking.py new/mockito-1.1.1/mockito/mocking.py --- old/mockito-1.0.12/mockito/mocking.py 2017-06-03 14:40:32.000000000 +0200 +++ new/mockito-1.1.1/mockito/mocking.py 2018-08-28 21:22:02.000000000 +0200 @@ -62,12 +62,15 @@ def finish_stubbing(self, stubbed_invocation): self.stubbed_invocations.appendleft(stubbed_invocation) + def clear_invocations(self): + self.invocations = deque() # STUBBING def get_original_method(self, method_name): - if not self.spec: + if self.spec is None: return None + return self.spec.__dict__.get(method_name) def set_method(self, method_name, new_method): @@ -116,27 +119,46 @@ self.replace_method(method_name, original_method) + def forget_stubbed_invocation(self, invocation): + assert invocation in self.stubbed_invocations + + if len(self.stubbed_invocations) == 1: + mock_registry.unstub(self.mocked_obj) + return + + self.stubbed_invocations.remove(invocation) + + if not any( + inv.method_name == invocation.method_name + for inv in self.stubbed_invocations + ): + original_method = self.original_methods.pop(invocation.method_name) + self.restore_method(invocation.method_name, original_method) + + def restore_method(self, method_name, original_method): + # If original_method is None, we *added* it to mocked_obj, so we + # must delete it here. + # If we mocked an instance, our mocked function will actually hide + # the one on its class, so we delete as well. + if (not original_method or not inspect.isclass(self.mocked_obj) and + inspect.ismethod(original_method)): + delattr(self.mocked_obj, method_name) + else: + self.set_method(method_name, original_method) + def unstub(self): while self.original_methods: method_name, original_method = self.original_methods.popitem() - # If original_method is None, we *added* it to mocked_obj, so we - # must delete it here. - # If we mocked an instance, our mocked function will actually hide - # the one on its class, so we delete as well. - if (not original_method or not inspect.isclass(self.mocked_obj) and - inspect.ismethod(original_method)): - delattr(self.mocked_obj, method_name) - else: - self.set_method(method_name, original_method) + self.restore_method(method_name, original_method) # SPECCING def has_method(self, method_name): - if self.spec: - return hasattr(self.spec, method_name) - else: + if self.spec is None: return True + return hasattr(self.spec, method_name) + def get_signature(self, method_name): if self.spec is None: return None diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/mockito-1.0.12/mockito/mockito.py new/mockito-1.1.1/mockito/mockito.py --- old/mockito-1.0.12/mockito/mockito.py 2017-06-03 14:40:32.000000000 +0200 +++ new/mockito-1.1.1/mockito/mockito.py 2018-08-28 21:22:02.000000000 +0200 @@ -267,7 +267,7 @@ """ if replacement is None: replacement = attr_or_replacement - when2(fn, Ellipsis).thenAnswer(replacement) + return when2(fn, Ellipsis).thenAnswer(replacement) else: obj, name = fn, attr_or_replacement theMock = _get_mock(obj, strict=True) @@ -331,6 +331,20 @@ mock_registry.unstub_all() +def forget_invocations(*objs): + """Forget all invocations of given objs. + + If you already *call* mocks during your setup routine, you can now call + ``forget_invocations`` at the end of your setup, and have a clean + 'recording' for your actual test code. T.i. you don't have + to count the invocations from your setup code anymore when using + :func:`verify` afterwards. + """ + for obj in objs: + theMock = _get_mock_or_raise(obj) + theMock.clear_invocations() + + def verifyNoMoreInteractions(*objs): verifyNoUnwantedInteractions(*objs) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/mockito-1.0.12/mockito/signature.py new/mockito-1.1.1/mockito/signature.py --- old/mockito-1.0.12/mockito/signature.py 2017-06-03 14:40:32.000000000 +0200 +++ new/mockito-1.1.1/mockito/signature.py 2018-08-28 21:22:02.000000000 +0200 @@ -1,5 +1,6 @@ from . import matchers +from .utils import contains_strict import functools import inspect @@ -33,16 +34,21 @@ try: return signature(method) - except: + except Exception: return None -def match_signature(sig, args, kwargs): # noqa: C901 (too complex) +def match_signature(sig, args, kwargs): + sig.bind(*args, **kwargs) + return sig + + +def match_signature_allowing_placeholders(sig, args, kwargs): # noqa: C901 # Let's face it. If this doesn't work out, we have to do it the hard # way and reimplement something like `sig.bind` with our specific # need for `...`, `*args`, and `**kwargs` support. - if Ellipsis in args: + if contains_strict(args, Ellipsis): # Invariant: Ellipsis as the sole argument should just pass, regardless # if it actually can consume an arg or the function does not take any # arguments at all @@ -64,7 +70,7 @@ else: # `*args` should at least match one arg (t.i. not `*[]`), so we # keep it here. The value and its type is irrelevant in python. - args_provided = matchers.ARGS_SENTINEL in args + args_provided = contains_strict(args, matchers.ARGS_SENTINEL) # If we find the `**kwargs` sentinel we must remove it, bc its # name cannot be matched against the sig. diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/mockito-1.0.12/mockito/tests/ellipsis_test.py new/mockito-1.1.1/mockito/tests/ellipsis_test.py --- old/mockito-1.0.12/mockito/tests/ellipsis_test.py 2017-06-03 14:40:32.000000000 +0200 +++ new/mockito-1.1.1/mockito/tests/ellipsis_test.py 2018-08-28 21:22:02.000000000 +0200 @@ -10,6 +10,8 @@ def bark(self, sound): return "%s!" % sound + def waggle(self): + return 'waggle' class CallSignature(namedtuple('CallSignature', 'args kwargs')): def raises(self, reason): @@ -19,6 +21,131 @@ return CallSignature(args, kwargs) +class TestCallMethodWithSignature: + def testNoArg(self): + rex = Dog() + when(rex).waggle().thenReturn('wuff') + + assert rex.waggle() == 'wuff' + + with pytest.raises(TypeError): + rex.waggle(1) + with pytest.raises(TypeError): + rex.waggle(Ellipsis) + with pytest.raises(TypeError): + rex.waggle(args) + with pytest.raises(TypeError): + rex.waggle(kwargs) + with pytest.raises(TypeError): + rex.waggle(*args) + with pytest.raises(TypeError): + rex.waggle(**kwargs) + + def testExpectingSpecificInputAsPositionalArgument(self): + rex = Dog() + when(rex).bark(1).thenReturn('wuff') + + assert rex.bark(1) == 'wuff' + + with pytest.raises(invocation.InvocationError): + rex.bark(sound=1) + with pytest.raises(invocation.InvocationError): + rex.bark(Ellipsis) + with pytest.raises(invocation.InvocationError): + rex.bark(args) + with pytest.raises(invocation.InvocationError): + rex.bark(*args) + with pytest.raises(invocation.InvocationError): + rex.bark(kwargs) + + with pytest.raises(TypeError): + rex.bark(1, 2) + with pytest.raises(TypeError): + rex.bark(wuff=1) + with pytest.raises(TypeError): + rex.bark(**kwargs) + + def testExpectingSpecificInputAsKeyword(self): + rex = Dog() + when(rex).bark(sound=1).thenReturn('wuff') + + assert rex.bark(sound=1) == 'wuff' + + with pytest.raises(invocation.InvocationError): + rex.bark(1) + with pytest.raises(invocation.InvocationError): + rex.bark(Ellipsis) + with pytest.raises(invocation.InvocationError): + rex.bark(args) + with pytest.raises(invocation.InvocationError): + rex.bark(*args) + with pytest.raises(invocation.InvocationError): + rex.bark(kwargs) + + with pytest.raises(TypeError): + rex.bark(1, 2) + with pytest.raises(TypeError): + rex.bark(wuff=1) + with pytest.raises(TypeError): + rex.bark(**kwargs) + + def testExpectingStarKwargs(self): + rex = Dog() + when(rex).bark(**kwargs).thenReturn('wuff') + + assert rex.bark(sound='miau') == 'wuff' + + with pytest.raises(invocation.InvocationError): + rex.bark('miau') + with pytest.raises(invocation.InvocationError): + rex.bark(Ellipsis) + with pytest.raises(invocation.InvocationError): + rex.bark(kwargs) + with pytest.raises(invocation.InvocationError): + rex.bark(args) + + with pytest.raises(TypeError): + rex.bark(wuff='miau') + with pytest.raises(TypeError): + rex.bark(**kwargs) + + def testExpectingEllipsis(self): + rex = Dog() + when(rex).bark(Ellipsis).thenReturn('wuff') + + assert rex.bark('miau') == 'wuff' + with pytest.raises(TypeError): + rex.bark('miau', 'miau') + + assert rex.bark(sound='miau') == 'wuff' + with pytest.raises(TypeError): + rex.bark(wuff='miau') + + assert rex.bark(Ellipsis) == 'wuff' + assert rex.bark(args) == 'wuff' + assert rex.bark(*args) == 'wuff' + assert rex.bark(kwargs) == 'wuff' + + with pytest.raises(TypeError): + rex.bark(**kwargs) == 'wuff' + + def testExpectingStarArgs(self): + rex = Dog() + when(rex).bark(*args).thenReturn('wuff') + + assert rex.bark('miau') == 'wuff' + + with pytest.raises(invocation.InvocationError): + rex.bark(sound='miau') + with pytest.raises(TypeError): + rex.bark(wuff='miau') + + assert rex.bark(*args) == 'wuff' + assert rex.bark(Ellipsis) == 'wuff' + + with pytest.raises(TypeError): + rex.bark(**kwargs) + class TestEllipsises: diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/mockito-1.0.12/mockito/tests/module.py new/mockito-1.1.1/mockito/tests/module.py --- old/mockito-1.0.12/mockito/tests/module.py 2017-06-03 14:40:32.000000000 +0200 +++ new/mockito-1.1.1/mockito/tests/module.py 2018-08-28 21:22:02.000000000 +0200 @@ -2,3 +2,7 @@ class Foo(object): def no_arg(self): pass + + +def one_arg(arg): + return arg diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/mockito-1.0.12/mockito/tests/numpy_test.py new/mockito-1.1.1/mockito/tests/numpy_test.py --- old/mockito-1.0.12/mockito/tests/numpy_test.py 1970-01-01 01:00:00.000000000 +0100 +++ new/mockito-1.1.1/mockito/tests/numpy_test.py 2018-08-28 21:22:02.000000000 +0200 @@ -0,0 +1,31 @@ +import mockito +from mockito import when, patch +import pytest + +import numpy as np +from . import module + + +pytestmark = pytest.mark.usefixtures("unstub") + + +def xcompare(a, b): + if isinstance(a, mockito.matchers.Matcher): + return a.matches(b) + + return np.array_equal(a, b) + + +class TestEnsureNumpyWorks: + def testEnsureNumpyArrayAllowedWhenStubbing(self): + array = np.array([1, 2, 3]) + when(module).one_arg(array).thenReturn('yep') + + with patch(mockito.invocation.MatchingInvocation.compare, xcompare): + assert module.one_arg(array) == 'yep' + + def testEnsureNumpyArrayAllowedWhenCalling(self): + array = np.array([1, 2, 3]) + when(module).one_arg(Ellipsis).thenReturn('yep') + assert module.one_arg(array) == 'yep' + diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/mockito-1.0.12/mockito/tests/signatures_test.py new/mockito-1.1.1/mockito/tests/signatures_test.py --- old/mockito-1.0.12/mockito/tests/signatures_test.py 2017-06-03 14:40:32.000000000 +0200 +++ new/mockito-1.1.1/mockito/tests/signatures_test.py 2018-08-28 21:22:02.000000000 +0200 @@ -143,10 +143,8 @@ class TestSignatures: - class TestNoneArg: - @pytest.mark.parametrize('call', [ sig(), sig(Ellipsis), @@ -154,10 +152,6 @@ def test_passing(self, sut, call): when(sut).none_args(*call.args, **call.kwargs).thenReturn('stub') - if sut == SUT: - sut = sut() - assert sut.none_args(*call.args, **call.kwargs) == 'stub' - @pytest.mark.parametrize('call', [ sig(12), @@ -165,18 +159,9 @@ sig(**kwargs), sig(*args, **kwargs) ]) - class TestFailing: - def test_stubbing(self, sut, call): - with pytest.raises(TypeError): - when(sut).none_args(*call.args, **call.kwargs) - - - def test_calling(self, sut, call): - when(sut).none_args() - if sut == SUT: - sut = sut() - with pytest.raises(TypeError): - sut.none_args(*call.args, **call.kwargs) + def test_failing(self, sut, call): + with pytest.raises(TypeError): + when(sut).none_args(*call.args, **call.kwargs) class TestOneArg: @@ -193,9 +178,6 @@ ]) def test_passing(self, sut, call): when(sut).one_arg(*call.args, **call.kwargs).thenReturn('stub') - if sut == SUT: - sut = sut() - assert sut.one_arg(*call.args, **call.kwargs) == 'stub' @pytest.mark.parametrize('call', [ sig(12, 13), @@ -212,17 +194,10 @@ sig(*args, b=1), sig(1, **kwargs), ]) - class TestFailing: - def test_stubbing(self, sut, call): - with pytest.raises(TypeError): - when(sut).one_arg(*call.args, **call.kwargs) - - def test_calling(self, sut, call): - when(sut).one_arg(Ellipsis) - if sut == SUT: - sut = sut() - with pytest.raises(TypeError): - sut.one_arg(*call.args, **call.kwargs) + def test_failing(self, sut, call): + with pytest.raises(TypeError): + when(sut).one_arg(*call.args, **call.kwargs) + class TestTwoArgs: diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/mockito-1.0.12/mockito/tests/unstub_test.py new/mockito-1.1.1/mockito/tests/unstub_test.py --- old/mockito-1.0.12/mockito/tests/unstub_test.py 2017-06-03 14:40:32.000000000 +0200 +++ new/mockito-1.1.1/mockito/tests/unstub_test.py 2018-08-28 21:22:02.000000000 +0200 @@ -1,12 +1,16 @@ import pytest -from mockito import when, unstub, verify +from mockito import when, unstub, verify, ArgumentError class Dog(object): def waggle(self): return 'Unsure' + def bark(self, sound='Wuff'): + return sound + + class TestUntub: def testIndependentUnstubbing(self): rex = Dog() @@ -72,10 +76,44 @@ with when(rex).waggle().thenReturn('Yup'), \ when(mox).waggle().thenReturn('Nope'): # noqa: E127 assert rex.waggle() == 'Yup' + assert mox.waggle() == 'Nope' assert rex.waggle() == 'Unsure' assert mox.waggle() == 'Unsure' + def testOnlyUnstubTheExactStub(self): + rex = Dog() + + when(rex).bark('Shhh').thenReturn('Nope') + with when(rex).bark('Miau').thenReturn('Grrr'): + assert rex.bark('Miau') == 'Grrr' + + assert rex.bark('Shhh') == 'Nope' + verify(rex, times=2).bark(Ellipsis) + + def testOnlyUnstubTheExcatMethod(self): + rex = Dog() + + when(rex).bark('Shhh').thenReturn('Nope') + with when(rex).waggle().thenReturn('Yup'): + assert rex.waggle() == 'Yup' + + assert rex.bark('Shhh') == 'Nope' + verify(rex, times=1).bark(Ellipsis) + verify(rex, times=1).waggle() + + def testCleanupRegistryAfterLastStub(self): + rex = Dog() + + with when(rex).bark('Shhh').thenReturn('Nope'): + with when(rex).bark('Miau').thenReturn('Grrr'): + assert rex.bark('Miau') == 'Grrr' + assert rex.bark('Shhh') == 'Nope' + + with pytest.raises(ArgumentError): + verify(rex).bark(Ellipsis) + + class TestEnsureCleanUnstubIfMockingAGlobal: def testA(self): with when(Dog).waggle().thenReturn('Sure'): diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/mockito-1.0.12/mockito/tests/verifications_test.py new/mockito-1.1.1/mockito/tests/verifications_test.py --- old/mockito-1.0.12/mockito/tests/verifications_test.py 2017-06-03 14:40:32.000000000 +0200 +++ new/mockito-1.1.1/mockito/tests/verifications_test.py 2018-08-28 21:22:02.000000000 +0200 @@ -22,8 +22,8 @@ from .test_base import TestBase from mockito import ( - mock, verify, inorder, VerificationError, ArgumentError, - verifyNoMoreInteractions, verifyZeroInteractions, + mock, when, verify, forget_invocations, inorder, VerificationError, + ArgumentError, verifyNoMoreInteractions, verifyZeroInteractions, verifyNoUnwantedInteractions, verifyStubbedInvocationsAreUsed, any) from mockito.verification import never @@ -320,6 +320,31 @@ VerificationError, verifyNoMoreInteractions, theMock) +class ClearInvocationsTest(TestBase): + def testClearsInvocations(self): + theMock1 = mock() + theMock2 = mock() + theMock1.do_foo() + theMock2.do_bar() + + self.assertRaises(VerificationError, verifyZeroInteractions, theMock1) + self.assertRaises(VerificationError, verifyZeroInteractions, theMock2) + + forget_invocations(theMock1, theMock2) + + verifyZeroInteractions(theMock1) + verifyZeroInteractions(theMock2) + + def testPreservesStubs(self): + theMock = mock() + when(theMock).do_foo().thenReturn('hello') + self.assertEqual('hello', theMock.do_foo()) + + forget_invocations(theMock) + + self.assertEqual('hello', theMock.do_foo()) + + class TestRaiseOnUnknownObjects: @pytest.mark.parametrize('verification_fn', [ verify, diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/mockito-1.0.12/mockito/tests/when2_test.py new/mockito-1.1.1/mockito/tests/when2_test.py --- old/mockito-1.0.12/mockito/tests/when2_test.py 2017-06-03 14:40:32.000000000 +0200 +++ new/mockito-1.1.1/mockito/tests/when2_test.py 2018-08-28 21:22:02.000000000 +0200 @@ -73,8 +73,10 @@ assert time.time() == 'None' def testWhenSplitOnNextLine(self): + # fmt: off when2( os.path.commonprefix, '/Foo').thenReturn(True) + # fmt: on assert os.path.commonprefix('/Foo') def testEnsureWithWhen2SameLine(self): @@ -82,9 +84,11 @@ pass def testEnsureWithWhen2SplitLine(self): + # fmt: off with when2( os.path.commonprefix, '/Foo'): pass + # fmt: on def testEnsureToResolveMethodOnClass(self): class A(object): @@ -109,6 +113,18 @@ assert os.path.commonprefix(Ellipsis) == 'yep' + def testWithPatchGivenTwoArgs(self): + with patch(os.path.exists, lambda m: 'yup'): + assert os.path.exists('foo') == 'yup' + + assert not os.path.exists('foo') + + def testWithPatchGivenThreeArgs(self): + with patch(os.path, 'exists', lambda m: 'yup'): + assert os.path.exists('foo') == 'yup' + + assert not os.path.exists('foo') + def testSpy2(self): spy2(os.path.exists) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/mockito-1.0.12/mockito/utils.py new/mockito-1.1.1/mockito/utils.py --- old/mockito-1.0.12/mockito/utils.py 2017-06-03 14:40:32.000000000 +0200 +++ new/mockito-1.1.1/mockito/utils.py 2018-08-28 21:22:02.000000000 +0200 @@ -9,6 +9,10 @@ PY3 = sys.version_info >= (3,) +def contains_strict(seq, element): + return any(item is element for item in seq) + + def newmethod(fn, obj): if PY3: return types.MethodType(fn, obj) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/mockito-1.0.12/mockito.egg-info/PKG-INFO new/mockito-1.1.1/mockito.egg-info/PKG-INFO --- old/mockito-1.0.12/mockito.egg-info/PKG-INFO 2017-06-03 14:40:54.000000000 +0200 +++ new/mockito-1.1.1/mockito.egg-info/PKG-INFO 2018-08-28 21:22:38.000000000 +0200 @@ -1,12 +1,13 @@ -Metadata-Version: 1.1 +Metadata-Version: 1.2 Name: mockito -Version: 1.0.12 +Version: 1.1.1 Summary: Spying framework Home-page: https://github.com/kaste/mockito-python -Author: herr.kaste -Author-email: [email protected] +Maintainer: herr.kaste +Maintainer-email: [email protected] License: MIT -Description: Mockito is a spying framework originally based on the Java library with the same name. +Description: Mockito is a spying framework originally based on `the Java library with the same name + <https://github.com/mockito/mockito>`_. .. image:: https://travis-ci.org/kaste/mockito-python.svg?branch=master :target: https://travis-ci.org/kaste/mockito-python diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/mockito-1.0.12/mockito.egg-info/SOURCES.txt new/mockito-1.1.1/mockito.egg-info/SOURCES.txt --- old/mockito-1.0.12/mockito.egg-info/SOURCES.txt 2017-06-03 14:40:54.000000000 +0200 +++ new/mockito-1.1.1/mockito.egg-info/SOURCES.txt 2018-08-28 21:22:38.000000000 +0200 @@ -29,6 +29,7 @@ mockito/tests/module.py mockito/tests/modulefunctions_test.py mockito/tests/my_dict_test.py +mockito/tests/numpy_test.py mockito/tests/signatures_test.py mockito/tests/speccing_test.py mockito/tests/spying_test.py
