Skip to content

Commit c5ce34f

Browse files
[3.12] gh-101100: Fix sphinx warnings in unittest.mock-examples.rst (GH-108810) (#108813)
* [3.12] gh-101100: Fix sphinx warnings in `unittest.mock-examples.rst` (GH-108810). (cherry picked from commit 5141b1e) Co-authored-by: Nikita Sobolev <[email protected]> * Make the requested changes --------- Co-authored-by: AlexWaygood <[email protected]>
1 parent 54e8dd7 commit c5ce34f

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

Doc/library/unittest.mock-examples.rst

+7-6
Original file line numberDiff line numberDiff line change
@@ -579,14 +579,14 @@ Partial mocking
579579
In some tests I wanted to mock out a call to :meth:`datetime.date.today`
580580
to return a known date, but I didn't want to prevent the code under test from
581581
creating new date objects. Unfortunately :class:`datetime.date` is written in C, and
582-
so I couldn't just monkey-patch out the static :meth:`date.today` method.
582+
so I couldn't just monkey-patch out the static :meth:`datetime.date.today` method.
583583

584584
I found a simple way of doing this that involved effectively wrapping the date
585585
class with a mock, but passing through calls to the constructor to the real
586586
class (and returning real instances).
587587

588588
The :func:`patch decorator <patch>` is used here to
589-
mock out the ``date`` class in the module under test. The :attr:`side_effect`
589+
mock out the ``date`` class in the module under test. The :attr:`~Mock.side_effect`
590590
attribute on the mock date class is then set to a lambda function that returns
591591
a real date. When the mock date class is called a real date will be
592592
constructed and returned by ``side_effect``. ::
@@ -766,8 +766,8 @@ mock has a nice API for making assertions about how your mock objects are used.
766766
>>> mock.foo_bar.assert_called_with('baz', spam='eggs')
767767

768768
If your mock is only being called once you can use the
769-
:meth:`assert_called_once_with` method that also asserts that the
770-
:attr:`call_count` is one.
769+
:meth:`~Mock.assert_called_once_with` method that also asserts that the
770+
:attr:`~Mock.call_count` is one.
771771

772772
>>> mock.foo_bar.assert_called_once_with('baz', spam='eggs')
773773
>>> mock.foo_bar()
@@ -835,7 +835,7 @@ One possibility would be for mock to copy the arguments you pass in. This
835835
could then cause problems if you do assertions that rely on object identity
836836
for equality.
837837

838-
Here's one solution that uses the :attr:`side_effect`
838+
Here's one solution that uses the :attr:`~Mock.side_effect`
839839
functionality. If you provide a ``side_effect`` function for a mock then
840840
``side_effect`` will be called with the same args as the mock. This gives us an
841841
opportunity to copy the arguments and store them for later assertions. In this
@@ -971,7 +971,8 @@ We can do this with :class:`MagicMock`, which will behave like a dictionary,
971971
and using :data:`~Mock.side_effect` to delegate dictionary access to a real
972972
underlying dictionary that is under our control.
973973

974-
When the :meth:`__getitem__` and :meth:`__setitem__` methods of our ``MagicMock`` are called
974+
When the :meth:`~object.__getitem__` and :meth:`~object.__setitem__` methods
975+
of our ``MagicMock`` are called
975976
(normal dictionary access) then ``side_effect`` is called with the key (and in
976977
the case of ``__setitem__`` the value too). We can also control what is returned.
977978

Doc/tools/.nitignore

-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,6 @@ Doc/library/tkinter.ttk.rst
145145
Doc/library/traceback.rst
146146
Doc/library/tty.rst
147147
Doc/library/turtle.rst
148-
Doc/library/unittest.mock-examples.rst
149148
Doc/library/unittest.mock.rst
150149
Doc/library/unittest.rst
151150
Doc/library/urllib.parse.rst

0 commit comments

Comments
 (0)