Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
6f2e9692
Commit
6f2e9692
authored
Oct 29, 2014
by
Georg Brandl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix external links to docs.python.org to use internal links instead.
parent
0828be7e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
8 additions
and
11 deletions
+8
-11
Doc/howto/pyporting.rst
Doc/howto/pyporting.rst
+3
-3
Doc/library/unittest.mock-examples.rst
Doc/library/unittest.mock-examples.rst
+5
-8
No files found.
Doc/howto/pyporting.rst
View file @
6f2e9692
...
...
@@ -39,7 +39,9 @@ The Short Version
With that done, your options are:
* If you are dropping Python 2 support, use 2to3_ to port to Python 3
* If you are dropping Python 2 support, use :ref:`2to3 <2to3-reference>` to port
to Python 3
* If you are keeping Python 2 support, then start writing Python 2/3-compatible
code starting **TODAY**
...
...
@@ -601,8 +603,6 @@ If you feel there is something missing from this document that should be added,
please email the python-porting_ mailing list.
.. _2to3: https://docs.python.org/2/library/2to3.html
.. _3to2: https://pypi.python.org/pypi/3to2
.. _Cheeseshop: PyPI_
.. _coverage: https://pypi.python.org/pypi/coverage
...
...
Doc/library/unittest.mock-examples.rst
View file @
6f2e9692
...
...
@@ -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:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment