python/mock-1.0.0/html/changelog.html

Fri, 16 Jan 2015 18:13:44 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Fri, 16 Jan 2015 18:13:44 +0100
branch
TOR_BUG_9701
changeset 14
925c144e1f1f
permissions
-rw-r--r--

Integrate suggestion from review to improve consistency with existing code.

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

mercurial