diff options
| author | Georg Brandl <georg@python.org> | 2014-10-29 08:00:37 (GMT) |
|---|---|---|
| committer | Georg Brandl <georg@python.org> | 2014-10-29 08:00:37 (GMT) |
| commit | 9e67d801bdef7c43e6704200770fb9cf2040dc11 (patch) | |
| tree | 15d6fa6289d83cfc1091cf5b12a808274cf0727c /Doc/library/unittest.mock-examples.rst | |
| parent | b425891b6e803e5b9d6682ce4ac927c2853e1ca1 (diff) | |
| parent | 728e4debd84e3fa345a6516e7fc0390ffc023ea8 (diff) | |
| download | cpython-9e67d801bdef7c43e6704200770fb9cf2040dc11.zip cpython-9e67d801bdef7c43e6704200770fb9cf2040dc11.tar.gz cpython-9e67d801bdef7c43e6704200770fb9cf2040dc11.tar.bz2 | |
merge with 3.4
Diffstat (limited to 'Doc/library/unittest.mock-examples.rst')
| -rw-r--r-- | Doc/library/unittest.mock-examples.rst | 13 |
1 files changed, 5 insertions, 8 deletions
diff --git a/Doc/library/unittest.mock-examples.rst b/Doc/library/unittest.mock-examples.rst index b203598..7963237 100644 --- a/Doc/library/unittest.mock-examples.rst +++ b/Doc/library/unittest.mock-examples.rst @@ -512,9 +512,8 @@ this list of calls for us: Partial mocking ~~~~~~~~~~~~~~~ -In some tests I wanted to mock out a call to `datetime.date.today() -<https://docs.python.org/library/datetime.html#datetime.date.today>`_ to return -a known date, but I didn't want to prevent the code under test from +In some tests I wanted to mock out a call to :func:`datetime.date.today` +to return a known date, but I didn't want to prevent the code under test from creating new date objects. Unfortunately `datetime.date` is written in C, and so I couldn't just monkey-patch out the static `date.today` method. @@ -556,14 +555,12 @@ is discussed in `this blog entry Mocking a Generator Method ~~~~~~~~~~~~~~~~~~~~~~~~~~ -A Python generator is a function or method that uses the `yield statement -<https://docs.python.org/reference/simple_stmts.html#the-yield-statement>`_ to -return a series of values when iterated over [#]_. +A Python generator is a function or method that uses the :keyword:`yield` statement +to return a series of values when iterated over [#]_. A generator method / function is called to return the generator object. It is the generator object that is then iterated over. The protocol method for -iteration is `__iter__ -<https://docs.python.org/library/stdtypes.html#container.__iter__>`_, so we can +iteration is :meth:`~container.__iter__`, so we can mock this using a `MagicMock`. Here's an example class with an "iter" method implemented as a generator: |
