Wed, 31 Dec 2014 07:22:50 +0100
Correct previous dual key logic pending first delivery installment.
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
3 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
6 <html xmlns="http://www.w3.org/1999/xhtml">
7 <head>
8 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
10 <title>CHANGELOG — Mock 1.0.0 documentation</title>
12 <link rel="stylesheet" href="_static/nature.css" type="text/css" />
13 <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
15 <script type="text/javascript">
16 var DOCUMENTATION_OPTIONS = {
17 URL_ROOT: '',
18 VERSION: '1.0.0',
19 COLLAPSE_INDEX: false,
20 FILE_SUFFIX: '.html',
21 HAS_SOURCE: true
22 };
23 </script>
24 <script type="text/javascript" src="_static/jquery.js"></script>
25 <script type="text/javascript" src="_static/underscore.js"></script>
26 <script type="text/javascript" src="_static/doctools.js"></script>
27 <link rel="top" title="Mock 1.0.0 documentation" href="index.html" />
28 <link rel="prev" title="Mock Library Comparison" href="compare.html" />
29 </head>
30 <body>
31 <div class="related">
32 <h3>Navigation</h3>
33 <ul>
34 <li class="right" style="margin-right: 10px">
35 <a href="genindex.html" title="General Index"
36 accesskey="I">index</a></li>
37 <li class="right" >
38 <a href="compare.html" title="Mock Library Comparison"
39 accesskey="P">previous</a> |</li>
40 <li><a href="index.html">Mock 1.0.0 documentation</a> »</li>
41 </ul>
42 </div>
44 <div class="document">
45 <div class="documentwrapper">
46 <div class="bodywrapper">
47 <div class="body">
49 <div class="section" id="changelog">
50 <h1>CHANGELOG<a class="headerlink" href="#changelog" title="Permalink to this headline">¶</a></h1>
51 <div class="section" id="version-1-0-0">
52 <h2>2012/10/07 Version 1.0.0<a class="headerlink" href="#version-1-0-0" title="Permalink to this headline">¶</a></h2>
53 <p>No changes since 1.0.0 beta 1. This version has feature parity with
54 <a class="reference external" href="http://docs.python.org/py3k/library/unittest.mock.html#module-unittest.mock">unittest.mock</a>
55 in Python 3.3.</p>
56 <p>Full list of changes since 0.8:</p>
57 <ul class="simple">
58 <li><cite>mocksignature</cite>, along with the <cite>mocksignature</cite> argument to <cite>patch</cite>, removed</li>
59 <li>Support for deleting attributes (accessing deleted attributes will raise an
60 <cite>AttributeError</cite>)</li>
61 <li>Added the <cite>mock_open</cite> helper function for mocking the builtin <cite>open</cite></li>
62 <li><cite>__class__</cite> is assignable, so a mock can pass an <cite>isinstance</cite> check without
63 requiring a spec</li>
64 <li>Addition of <cite>PropertyMock</cite>, for mocking properties</li>
65 <li><cite>MagicMocks</cite> made unorderable by default (in Python 3). The comparison
66 methods (other than equality and inequality) now return <cite>NotImplemented</cite></li>
67 <li>Propagate traceback info to support subclassing of <cite>_patch</cite> by other
68 libraries</li>
69 <li><cite>create_autospec</cite> works with attributes present in results of <cite>dir</cite> that
70 can’t be fetched from the object’s class. Contributed by Konstantine Rybnikov</li>
71 <li>Any exceptions in an iterable <cite>side_effect</cite> will be raised instead of
72 returned</li>
73 <li>In Python 3, <cite>create_autospec</cite> now supports keyword only arguments</li>
74 <li>Added <cite>patch.stopall</cite> method to stop all active patches created by <cite>start</cite></li>
75 <li>BUGFIX: calling <cite>MagicMock.reset_mock</cite> wouldn’t reset magic method mocks</li>
76 <li>BUGFIX: calling <cite>reset_mock</cite> on a <cite>MagicMock</cite> created with autospec could
77 raise an exception</li>
78 <li>BUGFIX: passing multiple spec arguments to patchers (<cite>spec</cite> , <cite>spec_set</cite> and
79 <cite>autospec</cite>) had unpredictable results, now it is an error</li>
80 <li>BUGFIX: using <cite>spec=True</cite> <em>and</em> <cite>create=True</cite> as arguments to patchers could
81 result in using <cite>DEFAULT</cite> as the spec. Now it is an error instead</li>
82 <li>BUGFIX: using <cite>spec</cite> or <cite>autospec</cite> arguments to patchers, along with
83 <cite>spec_set=True</cite> did not work correctly</li>
84 <li>BUGFIX: using an object that evaluates to False as a spec could be ignored</li>
85 <li>BUGFIX: a list as the <cite>spec</cite> argument to a patcher would always result in a
86 non-callable mock. Now if <cite>__call__</cite> is in the spec the mock is callable</li>
87 </ul>
88 </div>
89 <div class="section" id="version-1-0-0-beta-1">
90 <h2>2012/07/13 Version 1.0.0 beta 1<a class="headerlink" href="#version-1-0-0-beta-1" title="Permalink to this headline">¶</a></h2>
91 <ul class="simple">
92 <li>Added <cite>patch.stopall</cite> method to stop all active patches created by <cite>start</cite></li>
93 <li>BUGFIX: calling <cite>MagicMock.reset_mock</cite> wouldn’t reset magic method mocks</li>
94 <li>BUGFIX: calling <cite>reset_mock</cite> on a <cite>MagicMock</cite> created with autospec could
95 raise an exception</li>
96 </ul>
97 </div>
98 <div class="section" id="version-1-0-0-alpha-2">
99 <h2>2012/05/04 Version 1.0.0 alpha 2<a class="headerlink" href="#version-1-0-0-alpha-2" title="Permalink to this headline">¶</a></h2>
100 <ul class="simple">
101 <li><cite>PropertyMock</cite> attributes are now standard <cite>MagicMocks</cite></li>
102 <li><cite>create_autospec</cite> works with attributes present in results of <cite>dir</cite> that
103 can’t be fetched from the object’s class. Contributed by Konstantine Rybnikov</li>
104 <li>Any exceptions in an iterable <cite>side_effect</cite> will be raised instead of
105 returned</li>
106 <li>In Python 3, <cite>create_autospec</cite> now supports keyword only arguments</li>
107 </ul>
108 </div>
109 <div class="section" id="version-1-0-0-alpha-1">
110 <h2>2012/03/25 Version 1.0.0 alpha 1<a class="headerlink" href="#version-1-0-0-alpha-1" title="Permalink to this headline">¶</a></h2>
111 <p>The standard library version!</p>
112 <ul class="simple">
113 <li><cite>mocksignature</cite>, along with the <cite>mocksignature</cite> argument to <cite>patch</cite>, removed</li>
114 <li>Support for deleting attributes (accessing deleted attributes will raise an
115 <cite>AttributeError</cite>)</li>
116 <li>Added the <cite>mock_open</cite> helper function for mocking the builtin <cite>open</cite></li>
117 <li><cite>__class__</cite> is assignable, so a mock can pass an <cite>isinstance</cite> check without
118 requiring a spec</li>
119 <li>Addition of <cite>PropertyMock</cite>, for mocking properties</li>
120 <li><cite>MagicMocks</cite> made unorderable by default (in Python 3). The comparison
121 methods (other than equality and inequality) now return <cite>NotImplemented</cite></li>
122 <li>Propagate traceback info to support subclassing of <cite>_patch</cite> by other
123 libraries</li>
124 <li>BUGFIX: passing multiple spec arguments to patchers (<cite>spec</cite> , <cite>spec_set</cite> and
125 <cite>autospec</cite>) had unpredictable results, now it is an error</li>
126 <li>BUGFIX: using <cite>spec=True</cite> <em>and</em> <cite>create=True</cite> as arguments to patchers could
127 result in using <cite>DEFAULT</cite> as the spec. Now it is an error instead</li>
128 <li>BUGFIX: using <cite>spec</cite> or <cite>autospec</cite> arguments to patchers, along with
129 <cite>spec_set=True</cite> did not work correctly</li>
130 <li>BUGFIX: using an object that evaluates to False as a spec could be ignored</li>
131 <li>BUGFIX: a list as the <cite>spec</cite> argument to a patcher would always result in a
132 non-callable mock. Now if <cite>__call__</cite> is in the spec the mock is callable</li>
133 </ul>
134 </div>
135 <div class="section" id="version-0-8-0">
136 <h2>2012/02/13 Version 0.8.0<a class="headerlink" href="#version-0-8-0" title="Permalink to this headline">¶</a></h2>
137 <p>The only changes since 0.8rc2 are:</p>
138 <ul class="simple">
139 <li>Improved repr of <a class="reference internal" href="sentinel.html#mock.sentinel" title="mock.sentinel"><tt class="xref py py-data docutils literal"><span class="pre">sentinel</span></tt></a> objects</li>
140 <li><a class="reference internal" href="helpers.html#mock.ANY" title="mock.ANY"><tt class="xref py py-data docutils literal"><span class="pre">ANY</span></tt></a> can be used for comparisons against <a class="reference internal" href="helpers.html#mock.call" title="mock.call"><tt class="xref py py-data docutils literal"><span class="pre">call</span></tt></a> objects</li>
141 <li>The return value of <cite>MagicMock.__iter__</cite> method can be set to
142 any iterable and isn’t required to be an iterator</li>
143 </ul>
144 <p>Full List of changes since 0.7:</p>
145 <p>mock 0.8.0 is the last version that will support Python 2.4.</p>
146 <ul class="simple">
147 <li>Addition of <a class="reference internal" href="mock.html#mock.Mock.mock_calls" title="mock.Mock.mock_calls"><tt class="xref py py-attr docutils literal"><span class="pre">mock_calls</span></tt></a> list for <em>all</em> calls (including magic
148 methods and chained calls)</li>
149 <li><a class="reference internal" href="patch.html#mock.patch" title="mock.patch"><tt class="xref py py-func docutils literal"><span class="pre">patch()</span></tt></a> and <a class="reference internal" href="patch.html#mock.patch.object" title="mock.patch.object"><tt class="xref py py-func docutils literal"><span class="pre">patch.object()</span></tt></a> now create a <a class="reference internal" href="magicmock.html#mock.MagicMock" title="mock.MagicMock"><tt class="xref py py-class docutils literal"><span class="pre">MagicMock</span></tt></a>
150 instead of a <a class="reference internal" href="mock.html#mock.Mock" title="mock.Mock"><tt class="xref py py-class docutils literal"><span class="pre">Mock</span></tt></a> by default</li>
151 <li>The patchers (<cite>patch</cite>, <cite>patch.object</cite> and <cite>patch.dict</cite>), plus <cite>Mock</cite> and
152 <cite>MagicMock</cite>, take arbitrary keyword arguments for configuration</li>
153 <li>New mock method <a class="reference internal" href="mock.html#mock.Mock.configure_mock" title="mock.Mock.configure_mock"><tt class="xref py py-meth docutils literal"><span class="pre">configure_mock()</span></tt></a> for setting attributes and
154 return values / side effects on the mock and its attributes</li>
155 <li>New mock assert methods <a class="reference internal" href="mock.html#mock.Mock.assert_any_call" title="mock.Mock.assert_any_call"><tt class="xref py py-meth docutils literal"><span class="pre">assert_any_call()</span></tt></a> and
156 <a class="reference internal" href="mock.html#mock.Mock.assert_has_calls" title="mock.Mock.assert_has_calls"><tt class="xref py py-meth docutils literal"><span class="pre">assert_has_calls()</span></tt></a></li>
157 <li>Implemented <a class="reference internal" href="helpers.html#auto-speccing"><em>Autospeccing</em></a> (recursive, lazy speccing of mocks with
158 mocked signatures for functions/methods), as the <cite>autospec</cite> argument to
159 <cite>patch</cite></li>
160 <li>Added the <a class="reference internal" href="helpers.html#mock.create_autospec" title="mock.create_autospec"><tt class="xref py py-func docutils literal"><span class="pre">create_autospec()</span></tt></a> function for manually creating
161 ‘auto-specced’ mocks</li>
162 <li><a class="reference internal" href="patch.html#mock.patch.multiple" title="mock.patch.multiple"><tt class="xref py py-func docutils literal"><span class="pre">patch.multiple()</span></tt></a> for doing multiple patches in a single call, using
163 keyword arguments</li>
164 <li>Setting <a class="reference internal" href="mock.html#mock.Mock.side_effect" title="mock.Mock.side_effect"><tt class="xref py py-attr docutils literal"><span class="pre">side_effect</span></tt></a> to an iterable will cause calls to the mock
165 to return the next value from the iterable</li>
166 <li>New <cite>new_callable</cite> argument to <cite>patch</cite> and <cite>patch.object</cite> allowing you to
167 pass in a class or callable object (instead of <cite>MagicMock</cite>) that will be
168 called to replace the object being patched</li>
169 <li>Addition of <a class="reference internal" href="mock.html#mock.NonCallableMock" title="mock.NonCallableMock"><tt class="xref py py-class docutils literal"><span class="pre">NonCallableMock</span></tt></a> and <a class="reference internal" href="magicmock.html#mock.NonCallableMagicMock" title="mock.NonCallableMagicMock"><tt class="xref py py-class docutils literal"><span class="pre">NonCallableMagicMock</span></tt></a>, mocks
170 without a <cite>__call__</cite> method</li>
171 <li>Addition of <a class="reference internal" href="mock.html#mock.Mock.mock_add_spec" title="mock.Mock.mock_add_spec"><tt class="xref py py-meth docutils literal"><span class="pre">mock_add_spec()</span></tt></a> method for adding (or changing) a
172 spec on an existing mock</li>
173 <li>Protocol methods on <a class="reference internal" href="magicmock.html#mock.MagicMock" title="mock.MagicMock"><tt class="xref py py-class docutils literal"><span class="pre">MagicMock</span></tt></a> are magic mocks, and are created
174 lazily on first lookup. This means the result of calling a protocol method is
175 a <cite>MagicMock</cite> instead of a <cite>Mock</cite> as it was previously</li>
176 <li>Addition of <a class="reference internal" href="mock.html#mock.Mock.attach_mock" title="mock.Mock.attach_mock"><tt class="xref py py-meth docutils literal"><span class="pre">attach_mock()</span></tt></a> method</li>
177 <li>Added <a class="reference internal" href="helpers.html#mock.ANY" title="mock.ANY"><tt class="xref py py-data docutils literal"><span class="pre">ANY</span></tt></a> for ignoring arguments in <a class="reference internal" href="mock.html#mock.Mock.assert_called_with" title="mock.Mock.assert_called_with"><tt class="xref py py-meth docutils literal"><span class="pre">assert_called_with()</span></tt></a>
178 calls</li>
179 <li>Addition of <a class="reference internal" href="helpers.html#mock.call" title="mock.call"><tt class="xref py py-data docutils literal"><span class="pre">call</span></tt></a> helper object</li>
180 <li>Improved repr for mocks</li>
181 <li>Improved repr for <a class="reference internal" href="mock.html#mock.Mock.call_args" title="mock.Mock.call_args"><tt class="xref py py-attr docutils literal"><span class="pre">Mock.call_args</span></tt></a> and entries in
182 <a class="reference internal" href="mock.html#mock.Mock.call_args_list" title="mock.Mock.call_args_list"><tt class="xref py py-attr docutils literal"><span class="pre">Mock.call_args_list</span></tt></a>, <a class="reference internal" href="mock.html#mock.Mock.method_calls" title="mock.Mock.method_calls"><tt class="xref py py-attr docutils literal"><span class="pre">Mock.method_calls</span></tt></a> and
183 <a class="reference internal" href="mock.html#mock.Mock.mock_calls" title="mock.Mock.mock_calls"><tt class="xref py py-attr docutils literal"><span class="pre">Mock.mock_calls</span></tt></a></li>
184 <li>Improved repr for <a class="reference internal" href="sentinel.html#mock.sentinel" title="mock.sentinel"><tt class="xref py py-data docutils literal"><span class="pre">sentinel</span></tt></a> objects</li>
185 <li><cite>patch</cite> lookup is done at use time not at decoration time</li>
186 <li>In Python 2.6 or more recent, <cite>dir</cite> on a mock will report all the dynamically
187 created attributes (or the full list of attributes if there is a spec) as
188 well as all the mock methods and attributes.</li>
189 <li>Module level <a class="reference internal" href="helpers.html#mock.FILTER_DIR" title="mock.FILTER_DIR"><tt class="xref py py-data docutils literal"><span class="pre">FILTER_DIR</span></tt></a> added to control whether <cite>dir(mock)</cite> filters
190 private attributes. <cite>True</cite> by default.</li>
191 <li><cite>patch.TEST_PREFIX</cite> for controlling how patchers recognise test methods when
192 used to decorate a class</li>
193 <li>Support for using Java exceptions as a <a class="reference internal" href="mock.html#mock.Mock.side_effect" title="mock.Mock.side_effect"><tt class="xref py py-attr docutils literal"><span class="pre">side_effect</span></tt></a> on Jython</li>
194 <li><cite>Mock</cite> call lists (<cite>call_args_list</cite>, <cite>method_calls</cite> & <cite>mock_calls</cite>) are now
195 custom list objects that allow membership tests for “sub lists” and have
196 a nicer representation if you <cite>str</cite> or <cite>print</cite> them</li>
197 <li>Mocks attached as attributes or return values to other mocks have calls
198 recorded in <cite>method_calls</cite> and <cite>mock_calls</cite> of the parent (unless a name is
199 already set on the child)</li>
200 <li>Improved failure messages for <cite>assert_called_with</cite> and
201 <cite>assert_called_once_with</cite></li>
202 <li>The return value of the <a class="reference internal" href="magicmock.html#mock.MagicMock" title="mock.MagicMock"><tt class="xref py py-class docutils literal"><span class="pre">MagicMock</span></tt></a> <cite>__iter__</cite> method can be set to
203 any iterable and isn’t required to be an iterator</li>
204 <li>Added the Mock API (<cite>assert_called_with</cite> etc) to functions created by
205 <tt class="xref py py-func docutils literal"><span class="pre">mocksignature()</span></tt></li>
206 <li>Tuples as well as lists can be used to specify allowed methods for <cite>spec</cite> &
207 <cite>spec_set</cite> arguments</li>
208 <li>Calling <cite>stop</cite> on an unstarted patcher fails with a more meaningful error
209 message</li>
210 <li>Renamed the internal classes <cite>Sentinel</cite> and <cite>SentinelObject</cite> to prevent abuse</li>
211 <li>BUGFIX: an error creating a patch, with nested patch decorators, won’t leave
212 patches in place</li>
213 <li>BUGFIX: <cite>__truediv__</cite> and <cite>__rtruediv__</cite> not available as magic methods on
214 mocks in Python 3</li>
215 <li>BUGFIX: <cite>assert_called_with</cite> / <cite>assert_called_once_with</cite> can be used with
216 <cite>self</cite> as a keyword argument</li>
217 <li>BUGFIX: when patching a class with an explicit spec / spec_set (not a
218 boolean) it applies “spec inheritance” to the return value of the created
219 mock (the “instance”)</li>
220 <li>BUGFIX: remove the <cite>__unittest</cite> marker causing traceback truncation</li>
221 <li>Removal of deprecated <cite>patch_object</cite></li>
222 <li>Private attributes <cite>_name</cite>, <cite>_methods</cite>, ‘_children’, <cite>_wraps</cite> and <cite>_parent</cite>
223 (etc) renamed to reduce likelihood of clash with user attributes.</li>
224 <li>Added license file to the distribution</li>
225 </ul>
226 </div>
227 <div class="section" id="version-0-8-0-release-candidate-2">
228 <h2>2012/01/10 Version 0.8.0 release candidate 2<a class="headerlink" href="#version-0-8-0-release-candidate-2" title="Permalink to this headline">¶</a></h2>
229 <ul class="simple">
230 <li>Removed the <cite>configure</cite> keyword argument to <cite>create_autospec</cite> and allow
231 arbitrary keyword arguments (for the <cite>Mock</cite> constructor) instead</li>
232 <li>Fixed <cite>ANY</cite> equality with some types in <cite>assert_called_with</cite> calls</li>
233 <li>Switched to a standard Sphinx theme (compatible with
234 <a class="reference external" href="http://mock.readthedocs.org">readthedocs.org</a>)</li>
235 </ul>
236 </div>
237 <div class="section" id="version-0-8-0-release-candidate-1">
238 <h2>2011/12/29 Version 0.8.0 release candidate 1<a class="headerlink" href="#version-0-8-0-release-candidate-1" title="Permalink to this headline">¶</a></h2>
239 <ul class="simple">
240 <li><cite>create_autospec</cite> on the return value of a mocked class will use <cite>__call__</cite>
241 for the signature rather than <cite>__init__</cite></li>
242 <li>Performance improvement instantiating <cite>Mock</cite> and <cite>MagicMock</cite></li>
243 <li>Mocks used as magic methods have the same type as their parent instead of
244 being hardcoded to <cite>MagicMock</cite></li>
245 </ul>
246 <p>Special thanks to Julian Berman for his help with diagnosing and improving
247 performance in this release.</p>
248 </div>
249 <div class="section" id="version-0-8-0-beta-4">
250 <h2>2011/10/09 Version 0.8.0 beta 4<a class="headerlink" href="#version-0-8-0-beta-4" title="Permalink to this headline">¶</a></h2>
251 <ul class="simple">
252 <li><cite>patch</cite> lookup is done at use time not at decoration time</li>
253 <li>When attaching a Mock to another Mock as a magic method, calls are recorded
254 in mock_calls</li>
255 <li>Addition of <cite>attach_mock</cite> method</li>
256 <li>Renamed the internal classes <cite>Sentinel</cite> and <cite>SentinelObject</cite> to prevent abuse</li>
257 <li>BUGFIX: various issues around circular references with mocks (setting a mock
258 return value to be itself etc)</li>
259 </ul>
260 </div>
261 <div class="section" id="version-0-8-0-beta-3">
262 <h2>2011/08/15 Version 0.8.0 beta 3<a class="headerlink" href="#version-0-8-0-beta-3" title="Permalink to this headline">¶</a></h2>
263 <ul class="simple">
264 <li>Mocks attached as attributes or return values to other mocks have calls
265 recorded in <cite>method_calls</cite> and <cite>mock_calls</cite> of the parent (unless a name is
266 already set on the child)</li>
267 <li>Addition of <cite>mock_add_spec</cite> method for adding (or changing) a spec on an
268 existing mock</li>
269 <li>Improved repr for <cite>Mock.call_args</cite> and entries in <cite>Mock.call_args_list</cite>,
270 <cite>Mock.method_calls</cite> and <cite>Mock.mock_calls</cite></li>
271 <li>Improved repr for mocks</li>
272 <li>BUGFIX: minor fixes in the way <cite>mock_calls</cite> is worked out,
273 especially for “intermediate” mocks in a call chain</li>
274 </ul>
275 </div>
276 <div class="section" id="version-0-8-0-beta-2">
277 <h2>2011/08/05 Version 0.8.0 beta 2<a class="headerlink" href="#version-0-8-0-beta-2" title="Permalink to this headline">¶</a></h2>
278 <ul class="simple">
279 <li>Setting <cite>side_effect</cite> to an iterable will cause calls to the mock to return
280 the next value from the iterable</li>
281 <li>Added <cite>assert_any_call</cite> method</li>
282 <li>Moved <cite>assert_has_calls</cite> from call lists onto mocks</li>
283 <li>BUGFIX: <cite>call_args</cite> and all members of <cite>call_args_list</cite> are two tuples of
284 <cite>(args, kwargs)</cite> again instead of three tuples of <cite>(name, args, kwargs)</cite></li>
285 </ul>
286 </div>
287 <div class="section" id="version-0-8-0-beta-1">
288 <h2>2011/07/25 Version 0.8.0 beta 1<a class="headerlink" href="#version-0-8-0-beta-1" title="Permalink to this headline">¶</a></h2>
289 <ul class="simple">
290 <li><cite>patch.TEST_PREFIX</cite> for controlling how patchers recognise test methods when
291 used to decorate a class</li>
292 <li><cite>Mock</cite> call lists (<cite>call_args_list</cite>, <cite>method_calls</cite> & <cite>mock_calls</cite>) are now
293 custom list objects that allow membership tests for “sub lists” and have
294 an <cite>assert_has_calls</cite> method for unordered call checks</li>
295 <li><cite>callargs</cite> changed to <em>always</em> be a three-tuple of <cite>(name, args, kwargs)</cite></li>
296 <li>Addition of <cite>mock_calls</cite> list for <em>all</em> calls (including magic methods and
297 chained calls)</li>
298 <li>Extension of <cite>call</cite> object to support chained calls and <cite>callargs</cite> for better
299 comparisons with or without names. <cite>call</cite> object has a <cite>call_list</cite> method for
300 chained calls</li>
301 <li>Added the public <cite>instance</cite> argument to <cite>create_autospec</cite></li>
302 <li>Support for using Java exceptions as a <cite>side_effect</cite> on Jython</li>
303 <li>Improved failure messages for <cite>assert_called_with</cite> and
304 <cite>assert_called_once_with</cite></li>
305 <li>Tuples as well as lists can be used to specify allowed methods for <cite>spec</cite> &
306 <cite>spec_set</cite> arguments</li>
307 <li>BUGFIX: Fixed bug in <cite>patch.multiple</cite> for argument passing when creating
308 mocks</li>
309 <li>Added license file to the distribution</li>
310 </ul>
311 </div>
312 <div class="section" id="version-0-8-0-alpha-2">
313 <h2>2011/07/16 Version 0.8.0 alpha 2<a class="headerlink" href="#version-0-8-0-alpha-2" title="Permalink to this headline">¶</a></h2>
314 <ul class="simple">
315 <li><cite>patch.multiple</cite> for doing multiple patches in a single call, using keyword
316 arguments</li>
317 <li>New <cite>new_callable</cite> argument to <cite>patch</cite> and <cite>patch.object</cite> allowing you to
318 pass in a class or callable object (instead of <cite>MagicMock</cite>) that will be
319 called to replace the object being patched</li>
320 <li>Addition of <cite>NonCallableMock</cite> and <cite>NonCallableMagicMock</cite>, mocks without a
321 <cite>__call__</cite> method</li>
322 <li>Mocks created by <cite>patch</cite> have a <cite>MagicMock</cite> as the <cite>return_value</cite> where a
323 class is being patched</li>
324 <li><cite>create_autospec</cite> can create non-callable mocks for non-callable objects.
325 <cite>return_value</cite> mocks of classes will be non-callable unless the class has
326 a <cite>__call__</cite> method</li>
327 <li><cite>autospec</cite> creates a <cite>MagicMock</cite> without a spec for properties and slot
328 descriptors, because we don’t know the type of object they return</li>
329 <li>Removed the “inherit” argument from <cite>create_autospec</cite></li>
330 <li>Calling <cite>stop</cite> on an unstarted patcher fails with a more meaningful error
331 message</li>
332 <li>BUGFIX: an error creating a patch, with nested patch decorators, won’t leave
333 patches in place</li>
334 <li>BUGFIX: <cite>__truediv__</cite> and <cite>__rtruediv__</cite> not available as magic methods on
335 mocks in Python 3</li>
336 <li>BUGFIX: <cite>assert_called_with</cite> / <cite>assert_called_once_with</cite> can be used with
337 <cite>self</cite> as a keyword argument</li>
338 <li>BUGFIX: autospec for functions / methods with an argument named self that
339 isn’t the first argument no longer broken</li>
340 <li>BUGFIX: when patching a class with an explicit spec / spec_set (not a
341 boolean) it applies “spec inheritance” to the return value of the created
342 mock (the “instance”)</li>
343 <li>BUGFIX: remove the <cite>__unittest</cite> marker causing traceback truncation</li>
344 </ul>
345 </div>
346 <div class="section" id="version-0-8-0-alpha-1">
347 <h2>2011/06/14 Version 0.8.0 alpha 1<a class="headerlink" href="#version-0-8-0-alpha-1" title="Permalink to this headline">¶</a></h2>
348 <p>mock 0.8.0 is the last version that will support Python 2.4.</p>
349 <ul>
350 <li><p class="first">The patchers (<cite>patch</cite>, <cite>patch.object</cite> and <cite>patch.dict</cite>), plus <cite>Mock</cite> and
351 <cite>MagicMock</cite>, take arbitrary keyword arguments for configuration</p>
352 </li>
353 <li><p class="first">New mock method <cite>configure_mock</cite> for setting attributes and return values /
354 side effects on the mock and its attributes</p>
355 </li>
356 <li><p class="first">In Python 2.6 or more recent, <cite>dir</cite> on a mock will report all the dynamically
357 created attributes (or the full list of attributes if there is a spec) as
358 well as all the mock methods and attributes.</p>
359 </li>
360 <li><p class="first">Module level <cite>FILTER_DIR</cite> added to control whether <cite>dir(mock)</cite> filters
361 private attributes. <cite>True</cite> by default. Note that <cite>vars(Mock())</cite> can still be
362 used to get all instance attributes and <cite>dir(type(Mock())</cite> will still return
363 all the other attributes (irrespective of <cite>FILTER_DIR</cite>)</p>
364 </li>
365 <li><p class="first"><cite>patch</cite> and <cite>patch.object</cite> now create a <cite>MagicMock</cite> instead of a <cite>Mock</cite> by
366 default</p>
367 </li>
368 <li><p class="first">Added <cite>ANY</cite> for ignoring arguments in <cite>assert_called_with</cite> calls</p>
369 </li>
370 <li><p class="first">Addition of <cite>call</cite> helper object</p>
371 </li>
372 <li><p class="first">Protocol methods on <cite>MagicMock</cite> are magic mocks, and are created lazily on
373 first lookup. This means the result of calling a protocol method is a
374 MagicMock instead of a Mock as it was previously</p>
375 </li>
376 <li><p class="first">Added the Mock API (<cite>assert_called_with</cite> etc) to functions created by
377 <cite>mocksignature</cite></p>
378 </li>
379 <li><p class="first">Private attributes <cite>_name</cite>, <cite>_methods</cite>, ‘_children’, <cite>_wraps</cite> and <cite>_parent</cite>
380 (etc) renamed to reduce likelihood of clash with user attributes.</p>
381 </li>
382 <li><p class="first">Implemented auto-speccing (recursive, lazy speccing of mocks with mocked
383 signatures for functions/methods)</p>
384 <p>Limitations:</p>
385 <ul class="simple">
386 <li>Doesn’t mock magic methods or attributes (it creates MagicMocks, so the
387 magic methods are <em>there</em>, they just don’t have the signature mocked nor
388 are attributes followed)</li>
389 <li>Doesn’t mock function / method attributes</li>
390 <li>Uses object traversal on the objects being mocked to determine types - so
391 properties etc may be triggered</li>
392 <li>The return value of mocked classes (the ‘instance’) has the same call
393 signature as the class __init__ (as they share the same spec)</li>
394 </ul>
395 <p>You create auto-specced mocks by passing <cite>autospec=True</cite> to <cite>patch</cite>.</p>
396 <p>Note that attributes that are None are special cased and mocked without a
397 spec (so any attribute / method can be used). This is because None is
398 typically used as a default value for attributes that may be of some other
399 type, and as we don’t know what type that may be we allow all access.</p>
400 <p>Note that the <cite>autospec</cite> option to <cite>patch</cite> obsoletes the <cite>mocksignature</cite>
401 option.</p>
402 </li>
403 <li><p class="first">Added the <cite>create_autospec</cite> function for manually creating ‘auto-specced’
404 mocks</p>
405 </li>
406 <li><p class="first">Removal of deprecated <cite>patch_object</cite></p>
407 </li>
408 </ul>
409 </div>
410 <div class="section" id="version-0-7-2">
411 <h2>2011/05/30 Version 0.7.2<a class="headerlink" href="#version-0-7-2" title="Permalink to this headline">¶</a></h2>
412 <ul class="simple">
413 <li>BUGFIX: instances of list subclasses can now be used as mock specs</li>
414 <li>BUGFIX: MagicMock equality / inequality protocol methods changed to use the
415 default equality / inequality. This is done through a <cite>side_effect</cite> on
416 the mocks used for <cite>__eq__</cite> / <cite>__ne__</cite></li>
417 </ul>
418 </div>
419 <div class="section" id="version-0-7-1">
420 <h2>2011/05/06 Version 0.7.1<a class="headerlink" href="#version-0-7-1" title="Permalink to this headline">¶</a></h2>
421 <p>Package fixes contributed by Michael Fladischer. No code changes.</p>
422 <ul class="simple">
423 <li>Include template in package</li>
424 <li>Use isolated binaries for the tox tests</li>
425 <li>Unset executable bit on docs</li>
426 <li>Fix DOS line endings in getting-started.txt</li>
427 </ul>
428 </div>
429 <div class="section" id="version-0-7-0">
430 <h2>2011/03/05 Version 0.7.0<a class="headerlink" href="#version-0-7-0" title="Permalink to this headline">¶</a></h2>
431 <p>No API changes since 0.7.0 rc1. Many documentation changes including a stylish
432 new <a class="reference external" href="https://github.com/coordt/ADCtheme/">Sphinx theme</a>.</p>
433 <p>The full set of changes since 0.6.0 are:</p>
434 <ul class="simple">
435 <li>Python 3 compatibility</li>
436 <li>Ability to mock magic methods with <cite>Mock</cite> and addition of <cite>MagicMock</cite>
437 with pre-created magic methods</li>
438 <li>Addition of <cite>mocksignature</cite> and <cite>mocksignature</cite> argument to <cite>patch</cite> and
439 <cite>patch.object</cite></li>
440 <li>Addition of <cite>patch.dict</cite> for changing dictionaries during a test</li>
441 <li>Ability to use <cite>patch</cite>, <cite>patch.object</cite> and <cite>patch.dict</cite> as class decorators</li>
442 <li>Renamed <tt class="docutils literal"><span class="pre">patch_object</span></tt> to <cite>patch.object</cite> (<tt class="docutils literal"><span class="pre">patch_object</span></tt> is
443 deprecated)</li>
444 <li>Addition of soft comparisons: <cite>call_args</cite>, <cite>call_args_list</cite> and <cite>method_calls</cite>
445 now return tuple-like objects which compare equal even when empty args
446 or kwargs are skipped</li>
447 <li>patchers (<cite>patch</cite>, <cite>patch.object</cite> and <cite>patch.dict</cite>) have start and stop
448 methods</li>
449 <li>Addition of <cite>assert_called_once_with</cite> method</li>
450 <li>Mocks can now be named (<cite>name</cite> argument to constructor) and the name is used
451 in the repr</li>
452 <li>repr of a mock with a spec includes the class name of the spec</li>
453 <li><cite>assert_called_with</cite> works with <cite>python -OO</cite></li>
454 <li>New <cite>spec_set</cite> keyword argument to <cite>Mock</cite> and <cite>patch</cite>. If used,
455 attempting to <em>set</em> an attribute on a mock not on the spec will raise an
456 <cite>AttributeError</cite></li>
457 <li>Mocks created with a spec can now pass <cite>isinstance</cite> tests (<cite>__class__</cite>
458 returns the type of the spec)</li>
459 <li>Added docstrings to all objects</li>
460 <li>Improved failure message for <cite>Mock.assert_called_with</cite> when the mock
461 has not been called at all</li>
462 <li>Decorated functions / methods have their docstring and <cite>__module__</cite>
463 preserved on Python 2.4.</li>
464 <li>BUGFIX: <cite>mock.patch</cite> now works correctly with certain types of objects that
465 proxy attribute access, like the django settings object</li>
466 <li>BUGFIX: mocks are now copyable (thanks to Ned Batchelder for reporting and
467 diagnosing this)</li>
468 <li>BUGFIX: <cite>spec=True</cite> works with old style classes</li>
469 <li>BUGFIX: <tt class="docutils literal"><span class="pre">help(mock)</span></tt> works now (on the module). Can no longer use <tt class="docutils literal"><span class="pre">__bases__</span></tt>
470 as a valid sentinel name (thanks to Stephen Emslie for reporting and
471 diagnosing this)</li>
472 <li>BUGFIX: <tt class="docutils literal"><span class="pre">side_effect</span></tt> now works with <tt class="docutils literal"><span class="pre">BaseException</span></tt> exceptions like
473 <tt class="docutils literal"><span class="pre">KeyboardInterrupt</span></tt></li>
474 <li>BUGFIX: <cite>reset_mock</cite> caused infinite recursion when a mock is set as its own
475 return value</li>
476 <li>BUGFIX: patching the same object twice now restores the patches correctly</li>
477 <li>with statement tests now skipped on Python 2.4</li>
478 <li>Tests require unittest2 (or unittest2-py3k) to run</li>
479 <li>Tested with <a class="reference external" href="http://pypi.python.org/pypi/tox">tox</a> on Python 2.4 - 3.2,
480 jython and pypy (excluding 3.0)</li>
481 <li>Added ‘build_sphinx’ command to setup.py (requires setuptools or distribute)
482 Thanks to Florian Bauer</li>
483 <li>Switched from subversion to mercurial for source code control</li>
484 <li><a class="reference external" href="http://konryd.blogspot.com/">Konrad Delong</a> added as co-maintainer</li>
485 </ul>
486 </div>
487 <div class="section" id="version-0-7-0-rc-1">
488 <h2>2011/02/16 Version 0.7.0 RC 1<a class="headerlink" href="#version-0-7-0-rc-1" title="Permalink to this headline">¶</a></h2>
489 <p>Changes since beta 4:</p>
490 <ul class="simple">
491 <li>Tested with jython, pypy and Python 3.2 and 3.1</li>
492 <li>Decorated functions / methods have their docstring and <cite>__module__</cite>
493 preserved on Python 2.4</li>
494 <li>BUGFIX: <cite>mock.patch</cite> now works correctly with certain types of objects that
495 proxy attribute access, like the django settings object</li>
496 <li>BUGFIX: <cite>reset_mock</cite> caused infinite recursion when a mock is set as its own
497 return value</li>
498 </ul>
499 </div>
500 <div class="section" id="version-0-7-0-beta-4">
501 <h2>2010/11/12 Version 0.7.0 beta 4<a class="headerlink" href="#version-0-7-0-beta-4" title="Permalink to this headline">¶</a></h2>
502 <ul class="simple">
503 <li>patchers (<cite>patch</cite>, <cite>patch.object</cite> and <cite>patch.dict</cite>) have start and stop
504 methods</li>
505 <li>Addition of <cite>assert_called_once_with</cite> method</li>
506 <li>repr of a mock with a spec includes the class name of the spec</li>
507 <li><cite>assert_called_with</cite> works with <cite>python -OO</cite></li>
508 <li>New <cite>spec_set</cite> keyword argument to <cite>Mock</cite> and <cite>patch</cite>. If used,
509 attempting to <em>set</em> an attribute on a mock not on the spec will raise an
510 <cite>AttributeError</cite></li>
511 <li>Attributes and return value of a <cite>MagicMock</cite> are <cite>MagicMock</cite> objects</li>
512 <li>Attempting to set an unsupported magic method now raises an <cite>AttributeError</cite></li>
513 <li><cite>patch.dict</cite> works as a class decorator</li>
514 <li>Switched from subversion to mercurial for source code control</li>
515 <li>BUGFIX: mocks are now copyable (thanks to Ned Batchelder for reporting and
516 diagnosing this)</li>
517 <li>BUGFIX: <cite>spec=True</cite> works with old style classes</li>
518 <li>BUGFIX: <cite>mocksignature=True</cite> can now patch instance methods via
519 <cite>patch.object</cite></li>
520 </ul>
521 </div>
522 <div class="section" id="version-0-7-0-beta-3">
523 <h2>2010/09/18 Version 0.7.0 beta 3<a class="headerlink" href="#version-0-7-0-beta-3" title="Permalink to this headline">¶</a></h2>
524 <ul class="simple">
525 <li>Using spec with <a class="reference internal" href="magicmock.html#mock.MagicMock" title="mock.MagicMock"><tt class="xref py py-class docutils literal"><span class="pre">MagicMock</span></tt></a> only pre-creates magic methods in the spec</li>
526 <li>Setting a magic method on a mock with a <tt class="docutils literal"><span class="pre">spec</span></tt> can only be done if the
527 spec has that method</li>
528 <li>Mocks can now be named (<cite>name</cite> argument to constructor) and the name is used
529 in the repr</li>
530 <li><cite>mocksignature</cite> can now be used with classes (signature based on <cite>__init__</cite>)
531 and callable objects (signature based on <cite>__call__</cite>)</li>
532 <li>Mocks created with a spec can now pass <cite>isinstance</cite> tests (<cite>__class__</cite>
533 returns the type of the spec)</li>
534 <li>Default numeric value for MagicMock is 1 rather than zero (because the
535 MagicMock bool defaults to True and 0 is False)</li>
536 <li>Improved failure message for <a class="reference internal" href="mock.html#mock.Mock.assert_called_with" title="mock.Mock.assert_called_with"><tt class="xref py py-meth docutils literal"><span class="pre">assert_called_with()</span></tt></a> when the mock
537 has not been called at all</li>
538 <li>Adding the following to the set of supported magic methods:<ul>
539 <li><tt class="docutils literal"><span class="pre">__getformat__</span></tt> and <tt class="docutils literal"><span class="pre">__setformat__</span></tt></li>
540 <li>pickle methods</li>
541 <li><tt class="docutils literal"><span class="pre">__trunc__</span></tt>, <tt class="docutils literal"><span class="pre">__ceil__</span></tt> and <tt class="docutils literal"><span class="pre">__floor__</span></tt></li>
542 <li><tt class="docutils literal"><span class="pre">__sizeof__</span></tt></li>
543 </ul>
544 </li>
545 <li>Added ‘build_sphinx’ command to setup.py (requires setuptools or distribute)
546 Thanks to Florian Bauer</li>
547 <li>with statement tests now skipped on Python 2.4</li>
548 <li>Tests require unittest2 to run on Python 2.7</li>
549 <li>Improved several docstrings and documentation</li>
550 </ul>
551 </div>
552 <div class="section" id="version-0-7-0-beta-2">
553 <h2>2010/06/23 Version 0.7.0 beta 2<a class="headerlink" href="#version-0-7-0-beta-2" title="Permalink to this headline">¶</a></h2>
554 <ul class="simple">
555 <li><a class="reference internal" href="patch.html#mock.patch.dict" title="mock.patch.dict"><tt class="xref py py-func docutils literal"><span class="pre">patch.dict()</span></tt></a> works as a context manager as well as a decorator</li>
556 <li><tt class="docutils literal"><span class="pre">patch.dict</span></tt> takes a string to specify dictionary as well as a dictionary
557 object. If a string is supplied the name specified is imported</li>
558 <li>BUGFIX: <tt class="docutils literal"><span class="pre">patch.dict</span></tt> restores dictionary even when an exception is raised</li>
559 </ul>
560 </div>
561 <div class="section" id="version-0-7-0-beta-1">
562 <h2>2010/06/22 Version 0.7.0 beta 1<a class="headerlink" href="#version-0-7-0-beta-1" title="Permalink to this headline">¶</a></h2>
563 <ul class="simple">
564 <li>Addition of <tt class="xref py py-func docutils literal"><span class="pre">mocksignature()</span></tt></li>
565 <li>Ability to mock magic methods</li>
566 <li>Ability to use <tt class="docutils literal"><span class="pre">patch</span></tt> and <tt class="docutils literal"><span class="pre">patch.object</span></tt> as class decorators</li>
567 <li>Renamed <tt class="docutils literal"><span class="pre">patch_object</span></tt> to <a class="reference internal" href="patch.html#mock.patch.object" title="mock.patch.object"><tt class="xref py py-func docutils literal"><span class="pre">patch.object()</span></tt></a> (<tt class="docutils literal"><span class="pre">patch_object</span></tt> is
568 deprecated)</li>
569 <li>Addition of <a class="reference internal" href="magicmock.html#mock.MagicMock" title="mock.MagicMock"><tt class="xref py py-class docutils literal"><span class="pre">MagicMock</span></tt></a> class with all magic methods pre-created for you</li>
570 <li>Python 3 compatibility (tested with 3.2 but should work with 3.0 & 3.1 as
571 well)</li>
572 <li>Addition of <a class="reference internal" href="patch.html#mock.patch.dict" title="mock.patch.dict"><tt class="xref py py-func docutils literal"><span class="pre">patch.dict()</span></tt></a> for changing dictionaries during a test</li>
573 <li>Addition of <tt class="docutils literal"><span class="pre">mocksignature</span></tt> argument to <tt class="docutils literal"><span class="pre">patch</span></tt> and <tt class="docutils literal"><span class="pre">patch.object</span></tt></li>
574 <li><tt class="docutils literal"><span class="pre">help(mock)</span></tt> works now (on the module). Can no longer use <tt class="docutils literal"><span class="pre">__bases__</span></tt>
575 as a valid sentinel name (thanks to Stephen Emslie for reporting and
576 diagnosing this)</li>
577 <li>Addition of soft comparisons: <cite>call_args</cite>, <cite>call_args_list</cite> and <cite>method_calls</cite>
578 now return tuple-like objects which compare equal even when empty args
579 or kwargs are skipped</li>
580 <li>Added docstrings.</li>
581 <li>BUGFIX: <tt class="docutils literal"><span class="pre">side_effect</span></tt> now works with <tt class="docutils literal"><span class="pre">BaseException</span></tt> exceptions like
582 <tt class="docutils literal"><span class="pre">KeyboardInterrupt</span></tt></li>
583 <li>BUGFIX: patching the same object twice now restores the patches correctly</li>
584 <li>The tests now require <a class="reference external" href="http://pypi.python.org/pypi/unittest2">unittest2</a>
585 to run</li>
586 <li><a class="reference external" href="http://konryd.blogspot.com/">Konrad Delong</a> added as co-maintainer</li>
587 </ul>
588 </div>
589 <div class="section" id="version-0-6-0">
590 <h2>2009/08/22 Version 0.6.0<a class="headerlink" href="#version-0-6-0" title="Permalink to this headline">¶</a></h2>
591 <ul class="simple">
592 <li>New test layout compatible with test discovery</li>
593 <li>Descriptors (static methods / class methods etc) can now be patched and
594 restored correctly</li>
595 <li>Mocks can raise exceptions when called by setting <tt class="docutils literal"><span class="pre">side_effect</span></tt> to an
596 exception class or instance</li>
597 <li>Mocks that wrap objects will not pass on calls to the underlying object if
598 an explicit return_value is set</li>
599 </ul>
600 </div>
601 <div class="section" id="version-0-5-0">
602 <h2>2009/04/17 Version 0.5.0<a class="headerlink" href="#version-0-5-0" title="Permalink to this headline">¶</a></h2>
603 <ul class="simple">
604 <li>Made DEFAULT part of the public api.</li>
605 <li>Documentation built with Sphinx.</li>
606 <li><tt class="docutils literal"><span class="pre">side_effect</span></tt> is now called with the same arguments as the mock is called with and
607 if returns a non-DEFAULT value that is automatically set as the <tt class="docutils literal"><span class="pre">mock.return_value</span></tt>.</li>
608 <li><tt class="docutils literal"><span class="pre">wraps</span></tt> keyword argument used for wrapping objects (and passing calls through to the wrapped object).</li>
609 <li><tt class="docutils literal"><span class="pre">Mock.reset</span></tt> renamed to <tt class="docutils literal"><span class="pre">Mock.reset_mock</span></tt>, as reset is a common API name.</li>
610 <li><tt class="docutils literal"><span class="pre">patch</span></tt> / <tt class="docutils literal"><span class="pre">patch_object</span></tt> are now context managers and can be used with <tt class="docutils literal"><span class="pre">with</span></tt>.</li>
611 <li>A new ‘create’ keyword argument to patch and patch_object that allows them to patch
612 (and unpatch) attributes that don’t exist. (Potentially unsafe to use - it can allow
613 you to have tests that pass when they are testing an API that doesn’t exist - use at
614 your own risk!)</li>
615 <li>The methods keyword argument to Mock has been removed and merged with spec. The spec
616 argument can now be a list of methods or an object to take the spec from.</li>
617 <li>Nested patches may now be applied in a different order (created mocks passed
618 in the opposite order). This is actually a bugfix.</li>
619 <li>patch and patch_object now take a spec keyword argument. If spec is
620 passed in as ‘True’ then the Mock created will take the object it is replacing
621 as its spec object. If the object being replaced is a class, then the return
622 value for the mock will also use the class as a spec.</li>
623 <li>A Mock created without a spec will not attempt to mock any magic methods / attributes
624 (they will raise an <tt class="docutils literal"><span class="pre">AttributeError</span></tt> instead).</li>
625 </ul>
626 </div>
627 <div class="section" id="version-0-4-0">
628 <h2>2008/10/12 Version 0.4.0<a class="headerlink" href="#version-0-4-0" title="Permalink to this headline">¶</a></h2>
629 <ul>
630 <li><p class="first">Default return value is now a new mock rather than None</p>
631 </li>
632 <li><p class="first">return_value added as a keyword argument to the constructor</p>
633 </li>
634 <li><p class="first">New method ‘assert_called_with’</p>
635 </li>
636 <li><p class="first">Added ‘side_effect’ attribute / keyword argument called when mock is called</p>
637 </li>
638 <li><p class="first">patch decorator split into two decorators:</p>
639 <blockquote>
640 <div><ul class="simple">
641 <li><tt class="docutils literal"><span class="pre">patch_object</span></tt> which takes an object and an attribute name to patch
642 (plus optionally a value to patch with which defaults to a mock object)</li>
643 <li><tt class="docutils literal"><span class="pre">patch</span></tt> which takes a string specifying a target to patch; in the form
644 ‘package.module.Class.attribute’. (plus optionally a value to
645 patch with which defaults to a mock object)</li>
646 </ul>
647 </div></blockquote>
648 </li>
649 <li><p class="first">Can now patch objects with <tt class="docutils literal"><span class="pre">None</span></tt></p>
650 </li>
651 <li><p class="first">Change to patch for nose compatibility with error reporting in wrapped functions</p>
652 </li>
653 <li><p class="first">Reset no longer clears children / return value etc - it just resets
654 call count and call args. It also calls reset on all children (and
655 the return value if it is a mock).</p>
656 </li>
657 </ul>
658 <p>Thanks to Konrad Delong, Kevin Dangoor and others for patches and suggestions.</p>
659 </div>
660 <div class="section" id="version-0-3-1">
661 <h2>2007/12/03 Version 0.3.1<a class="headerlink" href="#version-0-3-1" title="Permalink to this headline">¶</a></h2>
662 <p><tt class="docutils literal"><span class="pre">patch</span></tt> maintains the name of decorated functions for compatibility with nose
663 test autodiscovery.</p>
664 <p>Tests decorated with <tt class="docutils literal"><span class="pre">patch</span></tt> that use the two argument form (implicit mock
665 creation) will receive the mock(s) passed in as extra arguments.</p>
666 <p>Thanks to Kevin Dangoor for these changes.</p>
667 </div>
668 <div class="section" id="version-0-3-0">
669 <h2>2007/11/30 Version 0.3.0<a class="headerlink" href="#version-0-3-0" title="Permalink to this headline">¶</a></h2>
670 <p>Removed <tt class="docutils literal"><span class="pre">patch_module</span></tt>. <tt class="docutils literal"><span class="pre">patch</span></tt> can now take a string as the first
671 argument for patching modules.</p>
672 <p>The third argument to <tt class="docutils literal"><span class="pre">patch</span></tt> is optional - a mock will be created by
673 default if it is not passed in.</p>
674 </div>
675 <div class="section" id="version-0-2-1">
676 <h2>2007/11/21 Version 0.2.1<a class="headerlink" href="#version-0-2-1" title="Permalink to this headline">¶</a></h2>
677 <p>Bug fix, allows reuse of functions decorated with <tt class="docutils literal"><span class="pre">patch</span></tt> and <tt class="docutils literal"><span class="pre">patch_module</span></tt>.</p>
678 </div>
679 <div class="section" id="version-0-2-0">
680 <h2>2007/11/20 Version 0.2.0<a class="headerlink" href="#version-0-2-0" title="Permalink to this headline">¶</a></h2>
681 <p>Added <tt class="docutils literal"><span class="pre">spec</span></tt> keyword argument for creating <tt class="docutils literal"><span class="pre">Mock</span></tt> objects from a
682 specification object.</p>
683 <p>Added <tt class="docutils literal"><span class="pre">patch</span></tt> and <tt class="docutils literal"><span class="pre">patch_module</span></tt> monkey patching decorators.</p>
684 <p>Added <tt class="docutils literal"><span class="pre">sentinel</span></tt> for convenient access to unique objects.</p>
685 <p>Distribution includes unit tests.</p>
686 </div>
687 <div class="section" id="version-0-1-0">
688 <h2>2007/11/19 Version 0.1.0<a class="headerlink" href="#version-0-1-0" title="Permalink to this headline">¶</a></h2>
689 <p>Initial release.</p>
690 </div>
691 </div>
692 <div class="section" id="todo-and-limitations">
693 <h1>TODO and Limitations<a class="headerlink" href="#todo-and-limitations" title="Permalink to this headline">¶</a></h1>
694 <p>Contributions, bug reports and comments welcomed!</p>
695 <p>Feature requests and bug reports are handled on the issue tracker:</p>
696 <blockquote>
697 <div><ul class="simple">
698 <li><a class="reference external" href="http://code.google.com/p/mock/issues/list">mock issue tracker</a></li>
699 </ul>
700 </div></blockquote>
701 <p><cite>wraps</cite> is not integrated with magic methods.</p>
702 <p><cite>patch</cite> could auto-do the patching in the constructor and unpatch in the
703 destructor. This would be useful in itself, but violates TOOWTDI and would be
704 unsafe for IronPython & PyPy (non-deterministic calling of destructors).
705 Destructors aren’t called in CPython where there are cycles, but a weak
706 reference with a callback can be used to get round this.</p>
707 <p><cite>Mock</cite> has several attributes. This makes it unsuitable for mocking objects
708 that use these attribute names. A way round this would be to provide methods
709 that <em>hide</em> these attributes when needed. In 0.8 many, but not all, of these
710 attributes are renamed to gain a <cite>_mock</cite> prefix, making it less likely that
711 they will clash. Any outstanding attributes that haven’t been modified with
712 the prefix should be changed.</p>
713 <p>If a patch is started using <cite>patch.start</cite> and then not stopped correctly then
714 the unpatching is not done. Using weak references it would be possible to
715 detect and fix this when the patch object itself is garbage collected. This
716 would be tricky to get right though.</p>
717 <p>When a <cite>Mock</cite> is created by <cite>patch</cite>, arbitrary keywords can be used to set
718 attributes. If <cite>patch</cite> is created with a <cite>spec</cite>, and is replacing a class, then
719 a <cite>return_value</cite> mock is created. The keyword arguments are not applied to the
720 child mock, but could be.</p>
721 <p>When mocking a class with <cite>patch</cite>, passing in <cite>spec=True</cite> or <cite>autospec=True</cite>,
722 the mock class has an instance created from the same spec. Should this be the
723 default behaviour for mocks anyway (mock return values inheriting the spec
724 from their parent), or should it be controlled by an additional keyword
725 argument (<cite>inherit</cite>) to the Mock constructor? <cite>create_autospec</cite> does this, so
726 an additional keyword argument to Mock is probably unnecessary.</p>
727 <p>The <cite>mocksignature</cite> argument to <cite>patch</cite> with a non <cite>Mock</cite> passed into
728 <cite>new_callable</cite> will <em>probably</em> cause an error. Should it just be invalid?</p>
729 <p>Note that <cite>NonCallableMock</cite> and <cite>NonCallableMagicMock</cite> still have the unused
730 (and unusable) attributes: <cite>return_value</cite>, <cite>side_effect</cite>, <cite>call_count</cite>,
731 <cite>call_args</cite> and <cite>call_args_list</cite>. These could be removed or raise errors on
732 getting / setting. They also have the <cite>assert_called_with</cite> and
733 <cite>assert_called_once_with</cite> methods. Removing these would be pointless as
734 fetching them would create a mock (attribute) that could be called without
735 error.</p>
736 <p>Some outstanding technical debt. The way autospeccing mocks function
737 signatures was copied and modified from <cite>mocksignature</cite>. This could all be
738 refactored into one set of functions instead of two. The way we tell if
739 patchers are started and if a patcher is being used for a <cite>patch.multiple</cite>
740 call are both horrible. There are now a host of helper functions that should
741 be rationalised. (Probably time to split mock into a package instead of a
742 module.)</p>
743 <p>Passing arbitrary keyword arguments to <cite>create_autospec</cite>, or <cite>patch</cite> with
744 <cite>autospec</cite>, when mocking a <em>function</em> works fine. However, the arbitrary
745 attributes are set on the created mock - but <cite>create_autospec</cite> returns a
746 real function (which doesn’t have those attributes). However, what is the use
747 case for using autospec to create functions with attributes that don’t exist
748 on the original?</p>
749 <p><cite>mocksignature</cite>, plus the <cite>call_args_list</cite> and <cite>method_calls</cite> attributes of
750 <cite>Mock</cite> could all be deprecated.</p>
751 </div>
754 </div>
755 </div>
756 </div>
757 <div class="sphinxsidebar">
758 <div class="sphinxsidebarwrapper">
759 <h3><a href="index.html">Table Of Contents</a></h3>
760 <ul>
761 <li><a class="reference internal" href="#">CHANGELOG</a><ul>
762 <li><a class="reference internal" href="#version-1-0-0">2012/10/07 Version 1.0.0</a></li>
763 <li><a class="reference internal" href="#version-1-0-0-beta-1">2012/07/13 Version 1.0.0 beta 1</a></li>
764 <li><a class="reference internal" href="#version-1-0-0-alpha-2">2012/05/04 Version 1.0.0 alpha 2</a></li>
765 <li><a class="reference internal" href="#version-1-0-0-alpha-1">2012/03/25 Version 1.0.0 alpha 1</a></li>
766 <li><a class="reference internal" href="#version-0-8-0">2012/02/13 Version 0.8.0</a></li>
767 <li><a class="reference internal" href="#version-0-8-0-release-candidate-2">2012/01/10 Version 0.8.0 release candidate 2</a></li>
768 <li><a class="reference internal" href="#version-0-8-0-release-candidate-1">2011/12/29 Version 0.8.0 release candidate 1</a></li>
769 <li><a class="reference internal" href="#version-0-8-0-beta-4">2011/10/09 Version 0.8.0 beta 4</a></li>
770 <li><a class="reference internal" href="#version-0-8-0-beta-3">2011/08/15 Version 0.8.0 beta 3</a></li>
771 <li><a class="reference internal" href="#version-0-8-0-beta-2">2011/08/05 Version 0.8.0 beta 2</a></li>
772 <li><a class="reference internal" href="#version-0-8-0-beta-1">2011/07/25 Version 0.8.0 beta 1</a></li>
773 <li><a class="reference internal" href="#version-0-8-0-alpha-2">2011/07/16 Version 0.8.0 alpha 2</a></li>
774 <li><a class="reference internal" href="#version-0-8-0-alpha-1">2011/06/14 Version 0.8.0 alpha 1</a></li>
775 <li><a class="reference internal" href="#version-0-7-2">2011/05/30 Version 0.7.2</a></li>
776 <li><a class="reference internal" href="#version-0-7-1">2011/05/06 Version 0.7.1</a></li>
777 <li><a class="reference internal" href="#version-0-7-0">2011/03/05 Version 0.7.0</a></li>
778 <li><a class="reference internal" href="#version-0-7-0-rc-1">2011/02/16 Version 0.7.0 RC 1</a></li>
779 <li><a class="reference internal" href="#version-0-7-0-beta-4">2010/11/12 Version 0.7.0 beta 4</a></li>
780 <li><a class="reference internal" href="#version-0-7-0-beta-3">2010/09/18 Version 0.7.0 beta 3</a></li>
781 <li><a class="reference internal" href="#version-0-7-0-beta-2">2010/06/23 Version 0.7.0 beta 2</a></li>
782 <li><a class="reference internal" href="#version-0-7-0-beta-1">2010/06/22 Version 0.7.0 beta 1</a></li>
783 <li><a class="reference internal" href="#version-0-6-0">2009/08/22 Version 0.6.0</a></li>
784 <li><a class="reference internal" href="#version-0-5-0">2009/04/17 Version 0.5.0</a></li>
785 <li><a class="reference internal" href="#version-0-4-0">2008/10/12 Version 0.4.0</a></li>
786 <li><a class="reference internal" href="#version-0-3-1">2007/12/03 Version 0.3.1</a></li>
787 <li><a class="reference internal" href="#version-0-3-0">2007/11/30 Version 0.3.0</a></li>
788 <li><a class="reference internal" href="#version-0-2-1">2007/11/21 Version 0.2.1</a></li>
789 <li><a class="reference internal" href="#version-0-2-0">2007/11/20 Version 0.2.0</a></li>
790 <li><a class="reference internal" href="#version-0-1-0">2007/11/19 Version 0.1.0</a></li>
791 </ul>
792 </li>
793 <li><a class="reference internal" href="#todo-and-limitations">TODO and Limitations</a></li>
794 </ul>
796 <h4>Previous topic</h4>
797 <p class="topless"><a href="compare.html"
798 title="previous chapter">Mock Library Comparison</a></p>
799 <h3>This Page</h3>
800 <ul class="this-page-menu">
801 <li><a href="_sources/changelog.txt"
802 rel="nofollow">Show Source</a></li>
803 </ul>
804 <div id="searchbox" style="display: none">
805 <h3>Quick search</h3>
806 <form class="search" action="search.html" method="get">
807 <input type="text" name="q" />
808 <input type="submit" value="Go" />
809 <input type="hidden" name="check_keywords" value="yes" />
810 <input type="hidden" name="area" value="default" />
811 </form>
812 <p class="searchtip" style="font-size: 90%">
813 Enter search terms or a module, class or function name.
814 </p>
815 </div>
816 <script type="text/javascript">$('#searchbox').show(0);</script>
817 </div>
818 </div>
819 <div class="clearer"></div>
820 </div>
821 <div class="related">
822 <h3>Navigation</h3>
823 <ul>
824 <li class="right" style="margin-right: 10px">
825 <a href="genindex.html" title="General Index"
826 >index</a></li>
827 <li class="right" >
828 <a href="compare.html" title="Mock Library Comparison"
829 >previous</a> |</li>
830 <li><a href="index.html">Mock 1.0.0 documentation</a> »</li>
831 </ul>
832 </div>
833 <div class="footer">
834 © Copyright 2007-2012, Michael Foord & the mock team.
835 Last updated on Oct 07, 2012.
836 Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.3.
837 </div>
838 </body>
839 </html>