Skip to content
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

version 4.0 #476

Merged
merged 70 commits into from Jan 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
d1118fb
update list of supported versions.
cjw296 Jan 13, 2020
4680a96
move __version__ to __init__.py so we don't have to modify the mock.p…
cjw296 Jan 13, 2020
f8d22bc
fix release script to blank out lower version segments.
cjw296 Jan 13, 2020
4195207
support pre-releases in version_info
cjw296 Jan 13, 2020
ce5b696
new cut from cpython as at 4a686504eb2bbf69adf78077458508a7ba131667
cjw296 Jan 13, 2020
b81f7b6
not needed in backport
cjw296 Jan 13, 2020
389e48e
fix imports
cjw296 Jan 13, 2020
b3d20d4
vendor uncache helper in to our package.
cjw296 Jan 13, 2020
cdf2d79
py3.6 needs the inner mock module to be deleted too
cjw296 Jan 13, 2020
45c1e65
run() implementation for py3.6, where it's missing
cjw296 Jan 13, 2020
12bd6d5
PyPy's object class has no __sizeof__.
cjw296 Jan 15, 2020
3d44cb8
re-introduce skips for https://bitbucket.org/pypy/pypy/issues/3010
cjw296 Jan 15, 2020
9b35e34
Skip cpython's 2085bd0877e17ad4d98a4586d5eabb6faecbb190 as PEP 570 sy…
cjw296 Jan 15, 2020
20abe16
bpo-21478: Record calls to parent when autospecced objects are used a…
tirkarthi Jul 22, 2019
ae02b30
Fix typos in comments, docs and test names (#15018)
minho42 Jul 30, 2019
cd18e01
bpo-37685: Fixed __eq__, __lt__ etc implementations in some classes. …
serhiy-storchaka Aug 8, 2019
9f43738
bpo-36871: Ensure method signature is used when asserting mock calls …
tirkarthi Aug 29, 2019
202ff78
bpo-35946: Improve assert_called_with documentation (GH-11796)
Aug 29, 2019
20fce5d
bpo-36743: __get__ is sometimes called without the owner argument (#1…
rhettinger Aug 29, 2019
97bf5a4
Fix typos mostly in comments, docs and test names (GH-15209)
minho42 Aug 30, 2019
39b5272
Fix assertions regarding magic methods function body that was not exe…
tirkarthi Sep 9, 2019
93f85f9
bpo-37212: Preserve keyword argument order in unittest.mock.call and …
tirkarthi Sep 9, 2019
42ae9eb
docs: Add references to AsyncMock in unittest.mock.patch (#13681)
mariocj89 Sep 9, 2019
d8170ff
bpo-37251: Removes __code__ check from _is_async_obj. (GH-15830)
lisroach Sep 10, 2019
08a2de7
backport fixed iscoroutinefunction from Python 3.8
cjw296 Jan 21, 2020
702d35b
bpo-37555: Update _CallList.__contains__ to respect ANY (#14700)
ElizabethU Sep 13, 2019
21ea393
bpo-38122: minor fixes to AsyncMock spec handling (GH-16099)
voidspace Sep 13, 2019
14aaccb
bpo-38100: Fix spelling error in unittest.mock code (GH-16168)
marcoramirezmx Sep 16, 2019
3b149c9
bpo-37828: Fix default mock_name in unittest.mock.assert_called error…
categulario Sep 17, 2019
136175a
bpo-38093: Correctly returns AsyncMock for async subclasses. (GH-15947)
lisroach Sep 20, 2019
d66e9d7
bpo-38136: Updates await_count and call_count to be different things …
lisroach Sep 24, 2019
e702e61
turn warnings for async stuff into errors.
cjw296 Jan 22, 2020
a0e820d
bpo-36871: Handle spec errors in assert_has_calls (GH-16005)
sfreilich Sep 24, 2019
3bdebf2
bpo-36871: Avoid duplicated 'Actual:' in assertion message (GH-16361)
sfreilich Sep 24, 2019
ee8bbd4
support for py3.6
cjw296 Jan 22, 2020
be7df81
bpo-38108: Makes mock objects inherit from Base (GH-16060)
lisroach Sep 29, 2019
189dffb
bpo-38161: Removes _AwaitEvent from AsyncMock. (GH-16443)
lisroach Sep 30, 2019
ec2bfa7
bpo-38163: Child mocks detect their type as sync or async (GH-16471)
lisroach Sep 30, 2019
0fda551
bpo-38839: Fix some unused functions in tests (GH-17189)
adamchainz Nov 19, 2019
30cc188
bpo-38857: AsyncMock fix for awaitable values and StopIteration fix […
fried Nov 21, 2019
a6768e6
minimal backport of IsolatedAsyncioTestCase to get tests passing on P…
cjw296 Jan 24, 2020
c000fff
bpo-38669: patch.object now raises a helpful error (GH17034)
elenaoat Dec 8, 2019
695580a
remove unused __version__ from mock.py (#17977)
cjw296 Jan 13, 2020
7a35f3a
Improve test coverage for AsyncMock. (GH-17906)
tirkarthi Jan 15, 2020
aa5f6e9
bpo-24928: Add test case for patch.dict using OrderedDict (GH -11437)
eamanu Jan 24, 2020
11df596
Fix `mock.patch.dict` to be stopped with `mock.patch.stopall` (#17606)
mariocj89 Jan 24, 2020
5de813c
bpo-38473: Handle autospecced functions and methods used with attach_…
tirkarthi Jan 24, 2020
610e9e3
flip more to iscoroutinefunction backport
cjw296 Jan 24, 2020
5a12423
this one no longer fails on pypy
cjw296 Jan 25, 2020
7a5fc54
pypy actually gets this right, so make it clear in the test
cjw296 Jan 25, 2020
8d3d8f2
move testasync to backports.iscoroutinefunction to keep inline with u…
cjw296 Jan 27, 2020
ad2b38d
bpo-39082: Allow AsyncMock to correctly patch static/class methods (G…
mkokotovich Jan 25, 2020
1d85e1a
bpo-37955: correct mock.patch docs with respect to the returned type …
phsilva Jan 25, 2020
0dc01d6
bpo-38932: Mock fully resets child objects on reset_mock(). (GH-17409)
vegarsti Jan 25, 2020
7409327
bpo-25597: Ensure wraps' return value is used for magic methods in Ma…
tirkarthi Jan 27, 2020
04ebc28
Backports: c7dd3c7d87d6961756d99b57aa13db7c7a03e1f8, skipped: already…
cjw296 Jan 27, 2020
a4d8fae
Clarify and fix assertions that mocks have not been awaited (GH-18196)
cjw296 Jan 27, 2020
af0e3ed
fixup: simplify IsolatedAsyncioTestCase backport
cjw296 Jan 27, 2020
d6deb20
fixup: uncache backport
cjw296 Jan 27, 2020
608b1bd
ignore empty yield methods too
cjw296 Jan 28, 2020
0c6893a
instructions for running coverage on cpython's mock package
cjw296 Jan 28, 2020
5db45d4
bpo-39485: fix corner-case in method-detection of mock (GH-18252)
cfbolz Jan 29, 2020
9b05bea
Get mock coverage back to 100% (GH-18228)
cjw296 Jan 29, 2020
a294948
bpo-37972: unittest.mock._Call now passes on __getitem__ to the __get…
blhsing Sep 11, 2019
3610394
latest sync point
cjw296 Jan 24, 2020
37f664b
fixup: point sphinx conf at new version location
cjw296 Jan 29, 2020
7fd1749
bug fix on committing changed version file
cjw296 Jan 29, 2020
fe43b42
another code coverage pattern
cjw296 Jan 29, 2020
9004d44
ReST bugfix
cjw296 Jan 29, 2020
ba8cbf9
Preparing for 4.1.0 release.
cjw296 Jan 29, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 9 additions & 23 deletions .circleci/config.yml
Expand Up @@ -24,37 +24,25 @@ jobs:

common: &common
jobs:
- python/pip-run-tests:
name: python27
image: circleci/python:2.7
- python/pip-run-tests:
name: python34
image: circleci/python:3.4
- python/pip-run-tests:
name: python35
image: circleci/python:3.5
- python/pip-run-tests:
name: python36
image: circleci/python:3.6
- python/pip-run-tests:
name: python37
image: circleci/python:3.7
- python/pip-run-tests:
name: pypy27
image: pypy:2.7
name: python38
image: circleci/python:3.8
- python/pip-run-tests:
name: pypy36
image: pypy:3.6

- python/coverage:
name: coverage
requires:
- python27
- python34
- python35
- python36
- python37
- pypy27
- python38
- pypy36

- python/pip-docs:
Expand All @@ -72,7 +60,7 @@ common: &common

- check-package:
name: check-package-python27
image: circleci/python:2.7
image: circleci/python:3.7
requires:
- package

Expand All @@ -83,26 +71,24 @@ common: &common
- package

- check-package:
name: check-package-pypy27
image: pypy:2.7
python: pypy
name: check-package-python38
image: circleci/python:3.8
requires:
- package

- check-package:
name: check-package-pypy36
image: pypy:3.6
python: pypy3
image: pypy:2.7
python: pypy
requires:
- package

- python/release:
name: release
config: .carthorse.yml
requires:
- check-package-python27
- check-package-python37
- check-package-pypy27
- check-package-python38
- check-package-pypy36

workflows:
Expand Down
2 changes: 1 addition & 1 deletion .coveragerc
@@ -1,12 +1,12 @@
[run]
source = mock
omit = mock/tests/__main__.py

[report]
exclude_lines =
pragma: no cover
if __name__ == .__main__.:
: pass
: yield

[paths]
source =
Expand Down
105 changes: 105 additions & 0 deletions CHANGELOG.rst
@@ -1,3 +1,108 @@
4.0.0b1
-------

- The release is a fresh cut of cpython's `4a686504`__. All changes to :mod:`mock`
from that commit and before are included in this release along with the
subsequent changes listed below.

__ https://github.com/python/cpython/commit/4a686504eb2bbf69adf78077458508a7ba131667

- Issue #37972: Subscripts to the `unittest.mock.call` objects now receive
the same chaining mechanism as any other custom attributes, so that the
following usage no longer raises a `TypeError`:

call().foo().__getitem__('bar')

Patch by blhsing

- Issue #38839: Fix some unused functions in tests. Patch by Adam Johnson.

- Issue #39485: Fix a bug in :func:`unittest.mock.create_autospec` that
would complain about the wrong number of arguments for custom descriptors
defined in an extension module returning functions.

- Issue #39082: Allow AsyncMock to correctly patch static/class methods

- Issue #38093: Fixes AsyncMock so it doesn't crash when used with
AsyncContextManagers or AsyncIterators.

- Issue #38859: AsyncMock now returns StopAsyncIteration on the exaustion of
a side_effects iterable. Since PEP-479 its Impossible to raise a
StopIteration exception from a coroutine.

- Issue #38163: Child mocks will now detect their type as either synchronous
or asynchronous, asynchronous child mocks will be AsyncMocks and
synchronous child mocks will be either MagicMock or Mock (depending on
their parent type).

- Issue #38473: Use signature from inner mock for autospecced methods
attached with :func:`unittest.mock.attach_mock`. Patch by Karthikeyan
Singaravelan.

- Issue #38136: Changes AsyncMock call count and await count to be two
different counters. Now await count only counts when a coroutine has been
awaited, not when it has been called, and vice-versa. Update the
documentation around this.

- Issue #37555: Fix `NonCallableMock._call_matcher` returning tuple instead
of `_Call` object when `self._spec_signature` exists. Patch by Elizabeth
Uselton

- Issue #37251: Remove `__code__` check in AsyncMock that incorrectly
evaluated function specs as async objects but failed to evaluate classes
with `__await__` but no `__code__` attribute defined as async objects.

- Issue #38669: Raise :exc:`TypeError` when passing target as a string with
:meth:`unittest.mock.patch.object`.

- Issue #25597: Ensure, if ``wraps`` is supplied to
:class:`unittest.mock.MagicMock`, it is used to calculate return values
for the magic methods instead of using the default return values. Patch by
Karthikeyan Singaravelan.

- Issue #38108: Any synchronous magic methods on an AsyncMock now return a
MagicMock. Any asynchronous magic methods on a MagicMock now return an
AsyncMock.

- Issue #21478: Record calls to parent when autospecced object is attached
to a mock using :func:`unittest.mock.attach_mock`. Patch by Karthikeyan
Singaravelan.

- Issue #38857: AsyncMock fix for return values that are awaitable types.
This also covers side_effect iterable values that happend to be awaitable,
and wraps callables that return an awaitable type. Before these awaitables
were being awaited instead of being returned as is.

- Issue #38932: Mock fully resets child objects on reset_mock(). Patch by
Vegard Stikbakke

- Issue #37685: Fixed ``__eq__``, ``__lt__`` etc implementations in some
classes. They now return :data:`NotImplemented` for unsupported type of
the other operand. This allows the other operand to play role (for example
the equality comparison with :data:`~unittest.mock.ANY` will return
``True``).

- Issue #37212: :func:`unittest.mock.call` now preserves the order of
keyword arguments in repr output. Patch by Karthikeyan Singaravelan.

- Issue #37828: Fix default mock name in
:meth:`unittest.mock.Mock.assert_called` exceptions. Patch by Abraham
Toriz Cruz.

- Issue #36871: Improve error handling for the assert_has_calls and
assert_has_awaits methods of mocks. Fixed a bug where any errors
encountered while binding the expected calls to the mock's spec were
silently swallowed, leading to misleading error output.

- Issue #21600: Fix :func:`mock.patch.stopall` to stop active patches that
were created with :func:`mock.patch.dict`.

- Issue #38161: Removes _AwaitEvent from AsyncMock.

- Issue #36871: Ensure method signature is used instead of constructor
signature of a class while asserting mock object against method calls.
Patch by Karthikeyan Singaravelan.

3.0.5
-----

Expand Down
2 changes: 1 addition & 1 deletion README.rst
Expand Up @@ -7,7 +7,7 @@ mock is now part of the Python standard library, available as `unittest.mock
onwards.

This package contains a rolling backport of the standard library mock code
compatible with Python 2.7 and 3.4 and up.
compatible with Python 3.6 and up.

Please see the standard library documentation for more details.

Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Expand Up @@ -71,7 +71,7 @@ def __init__(self):
# The default replacements for |version| and |release|, also used in various
# other places throughout the built documents. Supplied by pbr.
#
version = release = mock.mock.__version__
version = release = mock.__version__

# There are two options for replacing |today|: either, you set today to some
# non-false value, then it is used: (Set from pbr)
Expand Down
50 changes: 36 additions & 14 deletions docs/index.txt
Expand Up @@ -25,6 +25,8 @@ Python Version Compatibility

* Version 2.0.0 is the last version offering official Jython support.

* version 3.0.5 is the last version supporting Python 3.5 and lower.

.. index:: installing
.. _installing:

Expand Down Expand Up @@ -77,9 +79,6 @@ Checkout from git (see :ref:`installing`) and submit pull requests.
Committers can just push as desired: since all semantic development takes
place in cPython, the backport process is as lightweight as we can make it.

mock is CI tested using Travis-CI on Python versions 2.7, 3.4,
3.5, 3.6, pypy, pypy3.

If you end up fixing anything backport-specific, please add an entry
to the top of ``CHANGELOG.rst`` so it shows up in the next release
notes.
Expand All @@ -104,30 +103,33 @@ non-bugfix changes, patch on bugfix only changes.
Backporting rules
-----------------

- ``isinstance`` checks in cPython to ``type`` need to check ``ClassTypes``.
Code calling ``obj.isidentifier`` needs to change to ``_isidentifier(obj)``.
- If code such as this causes coverage checking to drop below 100%:

.. code-block:: python

- f-strings need to be rewritten using some other string substitution.
def will_never_be_called():
pass

- ``assertRaisesRegex`` needs to be ``assertRaisesRegexp`` for Python 2.
It should be adjusted to the following pattern, preferably upstream,
so that the ``.coveragerc`` in this repo knows to ignore it:

- If test code won't compile on a particular version of Python, move it to
a matching ``_py{version}.py`` file. If ``{version}`` isn't 3, adjust
``conftest.py``.
.. code-block:: python

def will_never_be_called(): pass

- If code such as this causes coverage checking to drop below 100%:

.. code-block:: python

def will_never_be_called():
pass
yield

It should be adjusted to the following pattern, preferably upstream,
so that the ``.coveragerc`` in this repo knows to ignore it:

.. code-block:: python

def will_never_be_called(): pass
def will_never_be_called(): yield

Backporting process
-------------------
Expand Down Expand Up @@ -177,5 +179,25 @@ Backporting process

5. Rinse and repeat until ``backport.py`` reports no more patches need applying.

6. If ``backport.py`` has updated ``lastsync.txt``, now would be a good time
to commit that change.
6. If ``backport.py`` has updated ``lastsync.txt`` but not committed it,
now would be a good time to commit that change.

Checking coverage in upstream
-----------------------------

Assuming you have the checkout structure as above, and you have compiled your cpython
master branch, then roughly as follows:

.. code-block:: bash

~/vcs/cpython/python.exe -m venv ~/virtualenvs/cpython-master
source ~/virtualenvs/cpython-master/bin/activate
pip install -U setuptools pip
pip install pytest pytest-cov
cd vcs/cpython/Lib/unittest
pytest --cov unittest.mock --cov unittest.test.testmock \
--cov-config ~/vcs/git/mock/.coveragerc \
--cov-report term-missing:skip-covered \
test/testmock/test*

Ignore ``test/testmock/__*__.py`` as these aren't present in the backport.
2 changes: 1 addition & 1 deletion lastsync.txt
@@ -1 +1 @@
11a8832c98b3db78727312154dd1d3ba76d639ec
db5e86adbce12350c26e7ffc2c6673369971a2dc
13 changes: 12 additions & 1 deletion mock/__init__.py
@@ -1,4 +1,15 @@
from __future__ import absolute_import

import re, sys

IS_PYPY = 'PyPy' in sys.version

import mock.mock as _mock
from mock.mock import *
__all__ = _mock.__all__

__version__ = '4.0.0b1'
version_info = tuple(int(p) for p in
re.match(r'(\d+).(\d+).(\d+)', __version__).groups())


__all__ = ('__version__', 'version_info') + _mock.__all__