Skip to content

Commit

Permalink
Merge pull request #476 from cjw296/restart_for_4
Browse files Browse the repository at this point in the history
version 4.0.0b1 - gulp...
  • Loading branch information
cjw296 committed Jan 29, 2020
2 parents 8fcd7fb + ba8cbf9 commit 8c6dcdf
Show file tree
Hide file tree
Showing 28 changed files with 2,620 additions and 949 deletions.
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__

0 comments on commit 8c6dcdf

Please sign in to comment.