Skip to content

Commit faa2066

Browse files
committed
Update docs
1 parent c1c6833 commit faa2066

9 files changed

Lines changed: 152 additions & 214 deletions

File tree

CHANGES.txt

Lines changed: 56 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -4,73 +4,79 @@ MOCKITO CHANGE LOG
44

55
Release 2.0.0 (March 10, 2026)
66
------------------------------
7-
- Packaging is now fully defined via ``pyproject.toml`` (``hatchling`` backend);
8-
the obsolete ``setup.py`` shim has been removed.
9-
10-
- Calling `thenAnswer()` without arguments is now allowed and is treated like
11-
`thenReturn()` without arguments: the stubbed method will return `None`.
12-
137
- Deprecate `verifyNoMoreInteractions` in favor of `ensureNoUnverifiedInteractions`.
148

159
- Deprecate `verifyNoUnwantedInteractions` in favor of `verifyExpectedInteractions`.
1610

1711
- Context managers now check usage and any expectations (set via `expect`) on exit. The usage
18-
check can be disabled with the environment variable `MOCKITO_CONTEXT_MANAGERS_CHECK_USAGE="0"`.
12+
check can be disabled with the environment variable ``MOCKITO_CONTEXT_MANAGERS_CHECK_USAGE="0"``.
1913

2014
- The `between` matcher now supports open ranges, e.g. `between=(0,)` to assert that at least
2115
0 interactions occurred.
2216

23-
- Added a first-class `InOrder` API via ``mockito.InOrder`` (also available as
24-
``mockito.inorder.InOrder``). The legacy in-order mode only supported one mock at a time;
17+
- Calling `thenAnswer()` without arguments is now allowed and is treated like
18+
`thenReturn()` without arguments: the stubbed method will return `None`.
19+
20+
- Added a first-class `InOrder` API via ``mockito.InOrder``.
21+
The legacy in-order mode only supported one mock at a time;
2522
the new API supports true cross-mock order verification.
2623

27-
Migration (old limited style -> new style)::
24+
Migration::
2825

29-
# Before (legacy, single-mock order only)
26+
# Before
3027
from mockito import inorder
3128
inorder.verify(cat).meow()
3229
inorder.verify(cat).purr()
3330

34-
# Now (preferred, explicit cross-mock order)
31+
# Now
3532
from mockito import InOrder
36-
in_order = InOrder(cat, dog)
33+
in_order = InOrder(cat) # <== pass multiple objects for cross-mock verification!
3734
in_order.verify(cat).meow()
38-
in_order.verify(dog).bark()
35+
inorder.verify(cat).purr()
3936

4037
- The legacy in-order verification mode (``inorder.verify(...)``)
4138
is deprecated in favor of ``InOrder(...)``.
4239

4340
- Added first-class async/await stubbing support: async callables now preserve
44-
awaitable behavior for `thenReturn`, `thenRaise`, and `thenAnswer` (including
45-
sync and async answer callables), with parity across `when`, `when2`,
46-
`patch`, and `expect`.
47-
Note that async introspection metadata (e.g. `inspect.iscoroutinefunction`)
48-
for stub wrappers is currently implemented only on Python 3.12+.
49-
50-
- Expanded `mock({...})` constructor shorthands:
51-
- `"async <name>"` marks methods as async and supports either `...` or a function value.
52-
- `{"__enter__": ...}` / `{"__aenter__": ...}` now install default matching
53-
`__exit__` / `__aexit__` handlers when not provided.
54-
- `{"__iter__": [..]}` and `{"__aiter__": [..]}` now normalize values into
55-
proper iterator / async-iterator behavior.
56-
- In constructor dict shorthands, zero-argument functions now widen to
57-
accept arbitrary call arguments (e.g. `lambda: "ok"` behaves like
58-
`lambda *a, **kw: "ok"`).
59-
60-
- Added first-class property/descriptor stubbing support, including class-level property
61-
stubbing via `when(F).p.thenReturn(...)` and `thenCallOriginalImplementation()` support for
62-
property stubs (including chained answers like
63-
`thenReturn(...).thenCallOriginalImplementation()`). Stubbing instance properties now fails
64-
fast with clear guidance to use class-level stubbing (`when(F).p...`).
65-
66-
- Added chained stubbing and expectations across call/property hops, e.g.
67-
`when(cat).meow().purr().thenReturn(...)`, `when(User).query.filter_by(...).first()`, and
68-
`expect(cat, times=1).meow().purr()`, including cleanup that preserves sibling chain branches.
69-
70-
- Allow `...` in fixed argument positions as an ad-hoc `any` matcher.
71-
Trailing positional `...` keeps its existing "rest" semantics.
72-
73-
- Extend `captor` to be used as a rest matcher
41+
awaitable behavior for `thenReturn`, `thenRaise`, and `thenAnswer`.
42+
43+
.. note::
44+
45+
Async introspection metadata (e.g. ``inspect.iscoroutinefunction``)
46+
for stub wrappers is currently implemented only on Python 3.12+.
47+
48+
- Expanded ``mock({...})`` constructor shorthands; see :doc:`mock-shorthands`.
49+
50+
- Added first-class property/descriptor stubbing support.
51+
52+
E.g.::
53+
54+
class F:
55+
@property
56+
def p(self):
57+
return "orig"
58+
59+
when(F).p.thenReturn("stub")
60+
assert F().p == "stub"
61+
62+
- Added chained stubbing and expectations across call/property hops, e.g.::
63+
64+
when(cat).meow().purr().thenReturn(...)
65+
when(User).query.filter_by(...).first()
66+
expect(cat, times=1).meow().purr()
67+
68+
- Allow ``...`` in fixed argument positions as an ad-hoc `any` matcher.
69+
Trailing positional ``...`` keeps its existing "rest" semantics.
70+
71+
E.g.::
72+
73+
when(api).call("users", active=...).thenReturn("ok")
74+
assert api.call("users", active=True) == "ok"
75+
api.call("users") # will raise InvocationError, kwarg "active" is missing
76+
77+
when(api).call("users", ...) # used as a rest matcher as before
78+
79+
- Extend ``captor`` to be used as a rest matcher
7480

7581
E.g., support::
7682

@@ -89,7 +95,7 @@ Release 2.0.0 (March 10, 2026)
8995
mock.do(1, 2, x=3)
9096
assert call.value == ((1, 2), {"x": 3})
9197

92-
- Added `patch_attr` and `patch_dict` for non-callable monkeypatch-style use cases
98+
- Added ``patch_attr`` and ``patch_dict`` for non-callable monkeypatch-style use cases
9399
(e.g. `sys.stdout`, `sys.argv`, and environment/config dictionaries) with
94100
context-manager support and restoration through `unstub`.
95101

@@ -100,7 +106,7 @@ Release 2.0.0 (March 10, 2026)
100106
with patch_dict(os.environ, {"user": "bob"}): ...
101107

102108
- Added explicit partial-`unstub` targeting by host + attribute name.
103-
This complements method-reference partial unstub (e.g. `unstub(cat.meow)`)
109+
This complements method-reference partial unstub (e.g. ``unstub(cat.meow)``)
104110
and supports tuple form and shorthand form, including multiple attributes
105111
in one call.
106112

@@ -111,7 +117,10 @@ Release 2.0.0 (March 10, 2026)
111117
unstub(cat, "meow")
112118
unstub((cat, "meow"), (os.path, "exists"))
113119

114-
- Also implemented `unstub("os.path")`
120+
- Also implemented `unstub("os.path")` - the string variant.
121+
122+
- Packaging is now fully defined via ``pyproject.toml`` (``hatchling`` backend);
123+
the obsolete ``setup.py`` shim has been removed.
115124

116125

117126

README.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,10 @@ to your computer, then run ``uv sync`` in the root directory. Example usage::
9090
Note: development and docs tooling target Python >=3.12, while the library itself
9191
supports older Python versions at runtime.
9292

93-
For docs (Python >=3.12), install only the docs dependencies with::
93+
To install everything (all dependency groups, Python >=3.12), run::
9494

95-
uv sync --no-dev --group docs
95+
uv sync --all-groups
9696

97-
Or to install everything (all dependency groups, Python >=3.12), run::
97+
Start the sphinx server::
9898

99-
uv sync --all-groups
99+
uv run sphinx-autobuild docs docs/_build/html

docs/_static/custom.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.highlight {
2+
background: #f5f5f5;
3+
}

docs/conf.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080
#
8181
# This is also used if you do content translation via gettext catalogs.
8282
# Usually you set "language" from the command line for these cases.
83-
language = None
83+
language = "en"
8484

8585
# There are two options for replacing |today|: either, you set today to some
8686
# non-false value, then it is used:
@@ -123,21 +123,22 @@
123123

124124
# -- Options for HTML output ----------------------------------------------
125125

126-
# The theme to use for HTML and HTML Help pages. See the documentation for
127-
# a list of builtin themes.
128-
html_theme = 'alabaster'
126+
# The theme to use for HTML and HTML Help pages.
127+
html_theme = 'furo'
129128

130-
# Theme options are theme-specific and customize the look and feel of a theme
131-
# further. For a list of options available for each theme, see the
132-
# documentation.
133-
#html_theme_options = {}
129+
# Theme options are theme-specific and customize the look and feel of a theme.
130+
html_theme_options = {
131+
'source_repository': 'https://github.com/kaste/mockito-python/',
132+
'source_branch': 'master',
133+
'source_directory': 'docs/',
134+
}
134135

135136
# Add any paths that contain custom themes here, relative to this directory.
136137
#html_theme_path = []
137138

138139
# The name for this set of Sphinx documents.
139-
# "<project> v<release> documentation" by default.
140-
#html_title = u'mockito-python v0.6.1'
140+
# By default Sphinx appends "documentation", but we keep it shorter.
141+
html_title = f"{project} {release}"
141142

142143
# A shorter title for the navigation bar. Default is the same as html_title.
143144
#html_short_title = None
@@ -155,6 +156,7 @@
155156
# relative to this directory. They are copied after the builtin static files,
156157
# so a file named "default.css" will overwrite the builtin "default.css".
157158
html_static_path = ['_static']
159+
html_css_files = ['custom.css']
158160

159161
# Add any extra paths that contain custom files (such as robots.txt or
160162
# .htaccess) here, relative to this directory. These files are copied
@@ -170,9 +172,7 @@
170172
# typographically correct entities.
171173
#html_use_smartypants = True
172174

173-
# Custom sidebar templates, maps document names to template names.
174-
#html_sidebars = {}
175-
html_sidebars = { '**': ['localtoc.html', 'relations.html', 'searchbox.html'], }
175+
# Use theme-provided sidebars.
176176

177177
# Additional templates that should be rendered to pages, maps page names to
178178
# template names.

docs/index.rst

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@
33
You can adapt this file completely to your liking, but it should at least
44
contain the root `toctree` directive.
55
6-
.. module:: mockito
7-
8-
Mockito is a spying framework originally based on the Java library with the same name.
6+
Mockito
7+
=======
98

10-
.. image:: https://github.com/kaste/mockito-python/actions/workflows/test-lint-go.yml/badge.svg
11-
:target: https://github.com/kaste/mockito-python/actions/workflows/test-lint-go.yml
9+
.. module:: mockito
1210

11+
Mockito is a spying framework focusing on ergonomics.
1312

1413

1514
Install
@@ -19,7 +18,7 @@ Install
1918
2019
pip install mockito
2120
22-
If you already use `pytest`, consider using the plugin `pytest-mockito <https://github.com/kaste/pytest-mockito>`_.
21+
If you already use `pytest`, consider using the plugin `pytest-mockito <https://github.com/kaste/pytest-mockito>`_ too.
2322

2423

2524
Use

docs/mock-shorthands.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
mock() configuration and shorthands
22
===================================
33

4-
If you really dig mock driven development, you use dumb ``mock()``s and don't patch
4+
If you really dig mock driven development, you use dumb `mocks` and don't patch
55
real objects and modules all the time.
66

77
The standard setup works as expected::
@@ -69,8 +69,8 @@ you also need to define the context/with handlers::
6969
.. note::
7070

7171
``__aenter__``, ``__aexit__``, ``__anext__`` are async by definition,
72-
use either ``mock({"__aenter__": ...})`` or
73-
``mock({"async __aenter__": ...})``.
72+
both ``mock({"__aenter__": ...})`` and
73+
``mock({"async __aenter__": ...})`` are equivalent.
7474

7575
For ``__aiter__``, we have a special shortcode::
7676

@@ -107,9 +107,9 @@ We have the same shortcuts available for `__enter__` and `__iter__`::
107107

108108
mock({"__iter__": [4, 5, 6]}) # install handler and wrap in an iterator
109109

110-
Remember or note that when you rather use specced ``mock()``s you're more or less limited by what the spec
111-
implements. If you for example use ``aiohttp.ClientSession`` as the blueprint for your mock,
112-
we already know that ``get`` is async and you don't need to tell mockito so::
110+
Remember or note that when you rather use specced ``mock()``\ s you're more or less limited by
111+
what the spec implements. If you for example use ``aiohttp.ClientSession`` as the blueprint
112+
for your mock, we already know that ``get`` is async and hence you don't need to tell mockito::
113113

114114
mock({
115115
"get": lambda: response # Look up if ClientSession defines "async def get"

0 commit comments

Comments
 (0)