Skip to content

Towards v2 #96

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 24 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
8d855bc
Improve `_get_wanted_verification` implementation
kaste Jan 27, 2025
a8cc51b
Bump version to 2.0.0-dev0
kaste Feb 3, 2025
4d87db9
Update github workflow to run on Python 3.13
kaste Jan 31, 2025
f589235
Add all dev tools for now
kaste Jan 31, 2025
2e314fc
Rename `verifyNoUnwantedInteractions` -> `verifyExpectedInteractions`
kaste Jan 27, 2025
28462b1
Make a `deprecated` decorator compat to python 3.13
kaste Jan 27, 2025
54a1662
Rename `verifyNoMoreInteractions` -> `ensureNoUnverifiedInteractions`
kaste Jan 28, 2025
e18ea1a
Add docs to `verifyZeroInteractions`
kaste Jan 28, 2025
9e8e22f
Move deprecations to eof
kaste Jan 28, 2025
19d00b6
Add "v2" section to README
kaste Jan 28, 2025
3be442f
Check usage and expectations on `__exit__`
kaste Jan 29, 2025
267132f
Allow open ranges for `between`
kaste Jan 29, 2025
ea88c80
Add some docstrings
kaste Jan 31, 2025
acd65f5
Extract `error_message_for_unmatched_invocation`
kaste Jan 31, 2025
7755dee
Use `error_message_for_unmatched_invocation` in `AtLeast`
kaste Jan 31, 2025
090a0f2
Simplify `Times.verify`
kaste Jan 31, 2025
59d43ab
Let `match_signature*` functions never return anything
kaste Jan 31, 2025
b5ed5df
Remove py35 compatibility code
kaste Jan 31, 2025
79b549d
Let's invent the abstract superclass `VerificationMode`
kaste Jan 31, 2025
6740d27
Let's invent the abstract superclass `RealInvocation`
kaste Jan 31, 2025
c807b15
Fix docstring
kaste Jan 31, 2025
8fba2fc
Make `MatchingInvocation` abstract
kaste Jan 31, 2025
ff54160
Fix docstring
kaste Jan 31, 2025
cf5c72f
Add typing
kaste Jan 31, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 1.6.0-dev
current_version = 2.0.0-dev0
commit = True
message = Bump version to {new_version}
tag = True
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/test-lint-go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
- name: Setup python
uses: actions/setup-python@v5
with:
python-version: '3.10'
python-version: '3.13'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
Expand All @@ -54,7 +54,7 @@ jobs:
- name: Setup python
uses: actions/setup-python@v5
with:
python-version: '3.10'
python-version: '3.13'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
Expand All @@ -70,7 +70,7 @@ jobs:
- name: Setup python
uses: actions/setup-python@v5
with:
python-version: '3.10'
python-version: '3.13'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
Expand All @@ -88,7 +88,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.10'
python-version: '3.13'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
Expand Down
31 changes: 30 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Mockito is a spying framework originally based on `the Java library with the same name
<https://github.com/mockito/mockito>`_. (Actually *we* invented the strict stubbing mode
back in 2009.)
back in 2009.)

.. image:: https://github.com/kaste/mockito-python/actions/workflows/test-lint-go.yml/badge.svg
:target: https://github.com/kaste/mockito-python/actions/workflows/test-lint-go.yml
Expand Down Expand Up @@ -45,6 +45,35 @@ Read the docs
http://mockito-python.readthedocs.io/en/latest/


Breaking changes in v2
======================

Two functions have been renamed:

- `verifyNoMoreInteractions` is deprecated. Use `ensureNoUnverifiedInteractions` instead.

Although `verifyNoMoreInteractions` is the name used in mockito for Java, it is a misnomer over there
too (imo). Its docs say "Checks if any of given mocks has any unverified interaction.", and we
make that clear now in the name of the function, so you don't need the docs to tell you what it does.

- `verifyNoUnwantedInteractions` is deprecated. Use `verifyExpectedInteractions` instead.

The new name should make it clear that it corresponds to the usage of `expect` (as alternative to `when`).

Context managers now check the usage and any expectations (if you used `expect`) on exit. You can
disable this check by setting the environment variable `MOCKITO_CONTEXT_MANAGERS_CHECK_USAGE` to `"0"`.
Note that this does not disable the check for any explicit expectations you might have set with `expect`.

This roughly corresponds to the `verifyStubbedInvocationsAreUsed` contra the `verifyExpectedInteractions`
functions.


New in v2
=========

- `between` now supports open ranges, e.g. `between=(0, )` to check that at least 0 interactions
occurred.


Development
===========
Expand Down
13 changes: 9 additions & 4 deletions docs/the-functions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
The functions
=============

Stable entrypoints are: :func:`when`, :func:`mock`, :func:`unstub`, :func:`verify`, :func:`spy`. Experimental or new function introduces with v1.0.x are: :func:`when2`, :func:`expect`, :func:`verifyNoUnwantedInteractions`, :func:`verifyStubbedInvocationsAreUsed`, :func:`patch`
Stable entrypoints are: :func:`when`, :func:`mock`, :func:`unstub`, :func:`verify`, :func:`spy`. New function introduced in v1 are: :func:`when2`, :func:`expect`, :func:`verifyExpectedInteractions`, :func:`verifyStubbedInvocationsAreUsed`, :func:`patch`

.. autofunction:: when
.. autofunction:: when2
Expand All @@ -19,9 +19,14 @@ Stable entrypoints are: :func:`when`, :func:`mock`, :func:`unstub`, :func:`verif
This looks like a plethora of verification functions, and especially since you often don't need to `verify` at all.

.. autofunction:: verify
.. autofunction:: verifyNoMoreInteractions
.. autofunction:: verifyZeroInteractions
.. autofunction:: verifyNoUnwantedInteractions
.. autofunction:: verifyStubbedInvocationsAreUsed
.. autofunction:: verifyExpectedInteractions

Note that `verifyExpectedInteractions` was named `verifyNoUnwantedInteractions` in v1.
The usage of `verifyNoUnwantedInteractions` is deprecated.

.. autofunction:: verifyStubbedInvocationsAreUsed
.. autofunction:: ensureNoUnverifiedInteractions

Note that `ensureNoUnverifiedInteractions` was named `verifyNoMoreInteractions` in v1.
The usage of `verifyNoMoreInteractions` is deprecated.
16 changes: 11 additions & 5 deletions mockito/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@
expect,
unstub,
forget_invocations,
ensureNoUnverifiedInteractions,
verify,
verifyNoMoreInteractions,
verifyZeroInteractions,
verifyNoUnwantedInteractions,
verifyExpectedInteractions,
verifyStubbedInvocationsAreUsed,
verifyNoUnwantedInteractions, # deprecated
verifyNoMoreInteractions, # deprecated
ArgumentError,
)
from . import inorder
Expand All @@ -44,7 +46,7 @@
from .matchers import any, contains, times
from .verification import never

__version__ = '1.6.0-dev'
__version__ = '2.0.0-dev'

__all__ = [
'mock',
Expand All @@ -54,18 +56,22 @@
'when2',
'patch',
'expect',
'ensureNoUnverifiedInteractions',
'verify',
'verifyNoMoreInteractions',
'verifyZeroInteractions',
'verifyNoUnwantedInteractions',
'verifyExpectedInteractions',
'verifyStubbedInvocationsAreUsed',
'inorder',
'unstub',
'forget_invocations',
'VerificationError',
'ArgumentError',

'any', # compatibility
'contains', # compatibility
'never', # compatibility

'times', # deprecated
'verifyNoUnwantedInteractions', # deprecated
'verifyNoMoreInteractions', # deprecated
]
Loading
Loading