Skip to content

Commit 8c6dcdf

Browse files
authored
Merge pull request #476 from cjw296/restart_for_4
version 4.0.0b1 - gulp...
2 parents 8fcd7fb + ba8cbf9 commit 8c6dcdf

28 files changed

+2620
-949
lines changed

.circleci/config.yml

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -24,37 +24,25 @@ jobs:
2424

2525
common: &common
2626
jobs:
27-
- python/pip-run-tests:
28-
name: python27
29-
image: circleci/python:2.7
30-
- python/pip-run-tests:
31-
name: python34
32-
image: circleci/python:3.4
33-
- python/pip-run-tests:
34-
name: python35
35-
image: circleci/python:3.5
3627
- python/pip-run-tests:
3728
name: python36
3829
image: circleci/python:3.6
3930
- python/pip-run-tests:
4031
name: python37
4132
image: circleci/python:3.7
4233
- python/pip-run-tests:
43-
name: pypy27
44-
image: pypy:2.7
34+
name: python38
35+
image: circleci/python:3.8
4536
- python/pip-run-tests:
4637
name: pypy36
4738
image: pypy:3.6
4839

4940
- python/coverage:
5041
name: coverage
5142
requires:
52-
- python27
53-
- python34
54-
- python35
5543
- python36
5644
- python37
57-
- pypy27
45+
- python38
5846
- pypy36
5947

6048
- python/pip-docs:
@@ -72,7 +60,7 @@ common: &common
7260

7361
- check-package:
7462
name: check-package-python27
75-
image: circleci/python:2.7
63+
image: circleci/python:3.7
7664
requires:
7765
- package
7866

@@ -83,26 +71,24 @@ common: &common
8371
- package
8472

8573
- check-package:
86-
name: check-package-pypy27
87-
image: pypy:2.7
88-
python: pypy
74+
name: check-package-python38
75+
image: circleci/python:3.8
8976
requires:
9077
- package
9178

9279
- check-package:
9380
name: check-package-pypy36
94-
image: pypy:3.6
95-
python: pypy3
81+
image: pypy:2.7
82+
python: pypy
9683
requires:
9784
- package
9885

9986
- python/release:
10087
name: release
10188
config: .carthorse.yml
10289
requires:
103-
- check-package-python27
10490
- check-package-python37
105-
- check-package-pypy27
91+
- check-package-python38
10692
- check-package-pypy36
10793

10894
workflows:

.coveragerc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
[run]
22
source = mock
3-
omit = mock/tests/__main__.py
43

54
[report]
65
exclude_lines =
76
pragma: no cover
87
if __name__ == .__main__.:
98
: pass
9+
: yield
1010

1111
[paths]
1212
source =

CHANGELOG.rst

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,108 @@
1+
4.0.0b1
2+
-------
3+
4+
- The release is a fresh cut of cpython's `4a686504`__. All changes to :mod:`mock`
5+
from that commit and before are included in this release along with the
6+
subsequent changes listed below.
7+
8+
__ https://github.com/python/cpython/commit/4a686504eb2bbf69adf78077458508a7ba131667
9+
10+
- Issue #37972: Subscripts to the `unittest.mock.call` objects now receive
11+
the same chaining mechanism as any other custom attributes, so that the
12+
following usage no longer raises a `TypeError`:
13+
14+
call().foo().__getitem__('bar')
15+
16+
Patch by blhsing
17+
18+
- Issue #38839: Fix some unused functions in tests. Patch by Adam Johnson.
19+
20+
- Issue #39485: Fix a bug in :func:`unittest.mock.create_autospec` that
21+
would complain about the wrong number of arguments for custom descriptors
22+
defined in an extension module returning functions.
23+
24+
- Issue #39082: Allow AsyncMock to correctly patch static/class methods
25+
26+
- Issue #38093: Fixes AsyncMock so it doesn't crash when used with
27+
AsyncContextManagers or AsyncIterators.
28+
29+
- Issue #38859: AsyncMock now returns StopAsyncIteration on the exaustion of
30+
a side_effects iterable. Since PEP-479 its Impossible to raise a
31+
StopIteration exception from a coroutine.
32+
33+
- Issue #38163: Child mocks will now detect their type as either synchronous
34+
or asynchronous, asynchronous child mocks will be AsyncMocks and
35+
synchronous child mocks will be either MagicMock or Mock (depending on
36+
their parent type).
37+
38+
- Issue #38473: Use signature from inner mock for autospecced methods
39+
attached with :func:`unittest.mock.attach_mock`. Patch by Karthikeyan
40+
Singaravelan.
41+
42+
- Issue #38136: Changes AsyncMock call count and await count to be two
43+
different counters. Now await count only counts when a coroutine has been
44+
awaited, not when it has been called, and vice-versa. Update the
45+
documentation around this.
46+
47+
- Issue #37555: Fix `NonCallableMock._call_matcher` returning tuple instead
48+
of `_Call` object when `self._spec_signature` exists. Patch by Elizabeth
49+
Uselton
50+
51+
- Issue #37251: Remove `__code__` check in AsyncMock that incorrectly
52+
evaluated function specs as async objects but failed to evaluate classes
53+
with `__await__` but no `__code__` attribute defined as async objects.
54+
55+
- Issue #38669: Raise :exc:`TypeError` when passing target as a string with
56+
:meth:`unittest.mock.patch.object`.
57+
58+
- Issue #25597: Ensure, if ``wraps`` is supplied to
59+
:class:`unittest.mock.MagicMock`, it is used to calculate return values
60+
for the magic methods instead of using the default return values. Patch by
61+
Karthikeyan Singaravelan.
62+
63+
- Issue #38108: Any synchronous magic methods on an AsyncMock now return a
64+
MagicMock. Any asynchronous magic methods on a MagicMock now return an
65+
AsyncMock.
66+
67+
- Issue #21478: Record calls to parent when autospecced object is attached
68+
to a mock using :func:`unittest.mock.attach_mock`. Patch by Karthikeyan
69+
Singaravelan.
70+
71+
- Issue #38857: AsyncMock fix for return values that are awaitable types.
72+
This also covers side_effect iterable values that happend to be awaitable,
73+
and wraps callables that return an awaitable type. Before these awaitables
74+
were being awaited instead of being returned as is.
75+
76+
- Issue #38932: Mock fully resets child objects on reset_mock(). Patch by
77+
Vegard Stikbakke
78+
79+
- Issue #37685: Fixed ``__eq__``, ``__lt__`` etc implementations in some
80+
classes. They now return :data:`NotImplemented` for unsupported type of
81+
the other operand. This allows the other operand to play role (for example
82+
the equality comparison with :data:`~unittest.mock.ANY` will return
83+
``True``).
84+
85+
- Issue #37212: :func:`unittest.mock.call` now preserves the order of
86+
keyword arguments in repr output. Patch by Karthikeyan Singaravelan.
87+
88+
- Issue #37828: Fix default mock name in
89+
:meth:`unittest.mock.Mock.assert_called` exceptions. Patch by Abraham
90+
Toriz Cruz.
91+
92+
- Issue #36871: Improve error handling for the assert_has_calls and
93+
assert_has_awaits methods of mocks. Fixed a bug where any errors
94+
encountered while binding the expected calls to the mock's spec were
95+
silently swallowed, leading to misleading error output.
96+
97+
- Issue #21600: Fix :func:`mock.patch.stopall` to stop active patches that
98+
were created with :func:`mock.patch.dict`.
99+
100+
- Issue #38161: Removes _AwaitEvent from AsyncMock.
101+
102+
- Issue #36871: Ensure method signature is used instead of constructor
103+
signature of a class while asserting mock object against method calls.
104+
Patch by Karthikeyan Singaravelan.
105+
1106
3.0.5
2107
-----
3108

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ mock is now part of the Python standard library, available as `unittest.mock
77
onwards.
88

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

1212
Please see the standard library documentation for more details.
1313

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def __init__(self):
7171
# The default replacements for |version| and |release|, also used in various
7272
# other places throughout the built documents. Supplied by pbr.
7373
#
74-
version = release = mock.mock.__version__
74+
version = release = mock.__version__
7575

7676
# There are two options for replacing |today|: either, you set today to some
7777
# non-false value, then it is used: (Set from pbr)

docs/index.txt

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ Python Version Compatibility
2525

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

28+
* version 3.0.5 is the last version supporting Python 3.5 and lower.
29+
2830
.. index:: installing
2931
.. _installing:
3032

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

80-
mock is CI tested using Travis-CI on Python versions 2.7, 3.4,
81-
3.5, 3.6, pypy, pypy3.
82-
8382
If you end up fixing anything backport-specific, please add an entry
8483
to the top of ``CHANGELOG.rst`` so it shows up in the next release
8584
notes.
@@ -104,30 +103,33 @@ non-bugfix changes, patch on bugfix only changes.
104103
Backporting rules
105104
-----------------
106105

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

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

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

114-
- If test code won't compile on a particular version of Python, move it to
115-
a matching ``_py{version}.py`` file. If ``{version}`` isn't 3, adjust
116-
``conftest.py``.
116+
.. code-block:: python
117+
118+
def will_never_be_called(): pass
117119

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

120122
.. code-block:: python
121123

122124
def will_never_be_called():
123-
pass
125+
yield
124126

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

128130
.. code-block:: python
129131

130-
def will_never_be_called(): pass
132+
def will_never_be_called(): yield
131133

132134
Backporting process
133135
-------------------
@@ -177,5 +179,25 @@ Backporting process
177179

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

180-
6. If ``backport.py`` has updated ``lastsync.txt``, now would be a good time
181-
to commit that change.
182+
6. If ``backport.py`` has updated ``lastsync.txt`` but not committed it,
183+
now would be a good time to commit that change.
184+
185+
Checking coverage in upstream
186+
-----------------------------
187+
188+
Assuming you have the checkout structure as above, and you have compiled your cpython
189+
master branch, then roughly as follows:
190+
191+
.. code-block:: bash
192+
193+
~/vcs/cpython/python.exe -m venv ~/virtualenvs/cpython-master
194+
source ~/virtualenvs/cpython-master/bin/activate
195+
pip install -U setuptools pip
196+
pip install pytest pytest-cov
197+
cd vcs/cpython/Lib/unittest
198+
pytest --cov unittest.mock --cov unittest.test.testmock \
199+
--cov-config ~/vcs/git/mock/.coveragerc \
200+
--cov-report term-missing:skip-covered \
201+
test/testmock/test*
202+
203+
Ignore ``test/testmock/__*__.py`` as these aren't present in the backport.

lastsync.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
11a8832c98b3db78727312154dd1d3ba76d639ec
1+
db5e86adbce12350c26e7ffc2c6673369971a2dc

mock/__init__.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,15 @@
11
from __future__ import absolute_import
2+
3+
import re, sys
4+
5+
IS_PYPY = 'PyPy' in sys.version
6+
27
import mock.mock as _mock
38
from mock.mock import *
4-
__all__ = _mock.__all__
9+
10+
__version__ = '4.0.0b1'
11+
version_info = tuple(int(p) for p in
12+
re.match(r'(\d+).(\d+).(\d+)', __version__).groups())
13+
14+
15+
__all__ = ('__version__', 'version_info') + _mock.__all__

0 commit comments

Comments
 (0)