gecko-dev/third_party/python/mock-1.0.0/html/changelog.html

839 строки
57 KiB
HTML

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>CHANGELOG &mdash; Mock 1.0.0 documentation</title>
<link rel="stylesheet" href="_static/nature.css" type="text/css" />
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: '',
VERSION: '1.0.0',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true
};
</script>
<script type="text/javascript" src="_static/jquery.js"></script>
<script type="text/javascript" src="_static/underscore.js"></script>
<script type="text/javascript" src="_static/doctools.js"></script>
<link rel="top" title="Mock 1.0.0 documentation" href="index.html" />
<link rel="prev" title="Mock Library Comparison" href="compare.html" />
</head>
<body>
<div class="related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="compare.html" title="Mock Library Comparison"
accesskey="P">previous</a> |</li>
<li><a href="index.html">Mock 1.0.0 documentation</a> &raquo;</li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body">
<div class="section" id="changelog">
<h1>CHANGELOG<a class="headerlink" href="#changelog" title="Permalink to this headline"></a></h1>
<div class="section" id="version-1-0-0">
<h2>2012/10/07 Version 1.0.0<a class="headerlink" href="#version-1-0-0" title="Permalink to this headline"></a></h2>
<p>No changes since 1.0.0 beta 1. This version has feature parity with
<a class="reference external" href="http://docs.python.org/py3k/library/unittest.mock.html#module-unittest.mock">unittest.mock</a>
in Python 3.3.</p>
<p>Full list of changes since 0.8:</p>
<ul class="simple">
<li><cite>mocksignature</cite>, along with the <cite>mocksignature</cite> argument to <cite>patch</cite>, removed</li>
<li>Support for deleting attributes (accessing deleted attributes will raise an
<cite>AttributeError</cite>)</li>
<li>Added the <cite>mock_open</cite> helper function for mocking the builtin <cite>open</cite></li>
<li><cite>__class__</cite> is assignable, so a mock can pass an <cite>isinstance</cite> check without
requiring a spec</li>
<li>Addition of <cite>PropertyMock</cite>, for mocking properties</li>
<li><cite>MagicMocks</cite> made unorderable by default (in Python 3). The comparison
methods (other than equality and inequality) now return <cite>NotImplemented</cite></li>
<li>Propagate traceback info to support subclassing of <cite>_patch</cite> by other
libraries</li>
<li><cite>create_autospec</cite> works with attributes present in results of <cite>dir</cite> that
can&#8217;t be fetched from the object&#8217;s class. Contributed by Konstantine Rybnikov</li>
<li>Any exceptions in an iterable <cite>side_effect</cite> will be raised instead of
returned</li>
<li>In Python 3, <cite>create_autospec</cite> now supports keyword only arguments</li>
<li>Added <cite>patch.stopall</cite> method to stop all active patches created by <cite>start</cite></li>
<li>BUGFIX: calling <cite>MagicMock.reset_mock</cite> wouldn&#8217;t reset magic method mocks</li>
<li>BUGFIX: calling <cite>reset_mock</cite> on a <cite>MagicMock</cite> created with autospec could
raise an exception</li>
<li>BUGFIX: passing multiple spec arguments to patchers (<cite>spec</cite> , <cite>spec_set</cite> and
<cite>autospec</cite>) had unpredictable results, now it is an error</li>
<li>BUGFIX: using <cite>spec=True</cite> <em>and</em> <cite>create=True</cite> as arguments to patchers could
result in using <cite>DEFAULT</cite> as the spec. Now it is an error instead</li>
<li>BUGFIX: using <cite>spec</cite> or <cite>autospec</cite> arguments to patchers, along with
<cite>spec_set=True</cite> did not work correctly</li>
<li>BUGFIX: using an object that evaluates to False as a spec could be ignored</li>
<li>BUGFIX: a list as the <cite>spec</cite> argument to a patcher would always result in a
non-callable mock. Now if <cite>__call__</cite> is in the spec the mock is callable</li>
</ul>
</div>
<div class="section" id="version-1-0-0-beta-1">
<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>
<ul class="simple">
<li>Added <cite>patch.stopall</cite> method to stop all active patches created by <cite>start</cite></li>
<li>BUGFIX: calling <cite>MagicMock.reset_mock</cite> wouldn&#8217;t reset magic method mocks</li>
<li>BUGFIX: calling <cite>reset_mock</cite> on a <cite>MagicMock</cite> created with autospec could
raise an exception</li>
</ul>
</div>
<div class="section" id="version-1-0-0-alpha-2">
<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>
<ul class="simple">
<li><cite>PropertyMock</cite> attributes are now standard <cite>MagicMocks</cite></li>
<li><cite>create_autospec</cite> works with attributes present in results of <cite>dir</cite> that
can&#8217;t be fetched from the object&#8217;s class. Contributed by Konstantine Rybnikov</li>
<li>Any exceptions in an iterable <cite>side_effect</cite> will be raised instead of
returned</li>
<li>In Python 3, <cite>create_autospec</cite> now supports keyword only arguments</li>
</ul>
</div>
<div class="section" id="version-1-0-0-alpha-1">
<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>
<p>The standard library version!</p>
<ul class="simple">
<li><cite>mocksignature</cite>, along with the <cite>mocksignature</cite> argument to <cite>patch</cite>, removed</li>
<li>Support for deleting attributes (accessing deleted attributes will raise an
<cite>AttributeError</cite>)</li>
<li>Added the <cite>mock_open</cite> helper function for mocking the builtin <cite>open</cite></li>
<li><cite>__class__</cite> is assignable, so a mock can pass an <cite>isinstance</cite> check without
requiring a spec</li>
<li>Addition of <cite>PropertyMock</cite>, for mocking properties</li>
<li><cite>MagicMocks</cite> made unorderable by default (in Python 3). The comparison
methods (other than equality and inequality) now return <cite>NotImplemented</cite></li>
<li>Propagate traceback info to support subclassing of <cite>_patch</cite> by other
libraries</li>
<li>BUGFIX: passing multiple spec arguments to patchers (<cite>spec</cite> , <cite>spec_set</cite> and
<cite>autospec</cite>) had unpredictable results, now it is an error</li>
<li>BUGFIX: using <cite>spec=True</cite> <em>and</em> <cite>create=True</cite> as arguments to patchers could
result in using <cite>DEFAULT</cite> as the spec. Now it is an error instead</li>
<li>BUGFIX: using <cite>spec</cite> or <cite>autospec</cite> arguments to patchers, along with
<cite>spec_set=True</cite> did not work correctly</li>
<li>BUGFIX: using an object that evaluates to False as a spec could be ignored</li>
<li>BUGFIX: a list as the <cite>spec</cite> argument to a patcher would always result in a
non-callable mock. Now if <cite>__call__</cite> is in the spec the mock is callable</li>
</ul>
</div>
<div class="section" id="version-0-8-0">
<h2>2012/02/13 Version 0.8.0<a class="headerlink" href="#version-0-8-0" title="Permalink to this headline"></a></h2>
<p>The only changes since 0.8rc2 are:</p>
<ul class="simple">
<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>
<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>
<li>The return value of <cite>MagicMock.__iter__</cite> method can be set to
any iterable and isn&#8217;t required to be an iterator</li>
</ul>
<p>Full List of changes since 0.7:</p>
<p>mock 0.8.0 is the last version that will support Python 2.4.</p>
<ul class="simple">
<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
methods and chained calls)</li>
<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>
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>
<li>The patchers (<cite>patch</cite>, <cite>patch.object</cite> and <cite>patch.dict</cite>), plus <cite>Mock</cite> and
<cite>MagicMock</cite>, take arbitrary keyword arguments for configuration</li>
<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
return values / side effects on the mock and its attributes</li>
<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
<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>
<li>Implemented <a class="reference internal" href="helpers.html#auto-speccing"><em>Autospeccing</em></a> (recursive, lazy speccing of mocks with
mocked signatures for functions/methods), as the <cite>autospec</cite> argument to
<cite>patch</cite></li>
<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
&#8216;auto-specced&#8217; mocks</li>
<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
keyword arguments</li>
<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
to return the next value from the iterable</li>
<li>New <cite>new_callable</cite> argument to <cite>patch</cite> and <cite>patch.object</cite> allowing you to
pass in a class or callable object (instead of <cite>MagicMock</cite>) that will be
called to replace the object being patched</li>
<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
without a <cite>__call__</cite> method</li>
<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
spec on an existing mock</li>
<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
lazily on first lookup. This means the result of calling a protocol method is
a <cite>MagicMock</cite> instead of a <cite>Mock</cite> as it was previously</li>
<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>
<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>
calls</li>
<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>
<li>Improved repr for mocks</li>
<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
<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
<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>
<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>
<li><cite>patch</cite> lookup is done at use time not at decoration time</li>
<li>In Python 2.6 or more recent, <cite>dir</cite> on a mock will report all the dynamically
created attributes (or the full list of attributes if there is a spec) as
well as all the mock methods and attributes.</li>
<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
private attributes. <cite>True</cite> by default.</li>
<li><cite>patch.TEST_PREFIX</cite> for controlling how patchers recognise test methods when
used to decorate a class</li>
<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>
<li><cite>Mock</cite> call lists (<cite>call_args_list</cite>, <cite>method_calls</cite> &amp; <cite>mock_calls</cite>) are now
custom list objects that allow membership tests for &#8220;sub lists&#8221; and have
a nicer representation if you <cite>str</cite> or <cite>print</cite> them</li>
<li>Mocks attached as attributes or return values to other mocks have calls
recorded in <cite>method_calls</cite> and <cite>mock_calls</cite> of the parent (unless a name is
already set on the child)</li>
<li>Improved failure messages for <cite>assert_called_with</cite> and
<cite>assert_called_once_with</cite></li>
<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
any iterable and isn&#8217;t required to be an iterator</li>
<li>Added the Mock API (<cite>assert_called_with</cite> etc) to functions created by
<tt class="xref py py-func docutils literal"><span class="pre">mocksignature()</span></tt></li>
<li>Tuples as well as lists can be used to specify allowed methods for <cite>spec</cite> &amp;
<cite>spec_set</cite> arguments</li>
<li>Calling <cite>stop</cite> on an unstarted patcher fails with a more meaningful error
message</li>
<li>Renamed the internal classes <cite>Sentinel</cite> and <cite>SentinelObject</cite> to prevent abuse</li>
<li>BUGFIX: an error creating a patch, with nested patch decorators, won&#8217;t leave
patches in place</li>
<li>BUGFIX: <cite>__truediv__</cite> and <cite>__rtruediv__</cite> not available as magic methods on
mocks in Python 3</li>
<li>BUGFIX: <cite>assert_called_with</cite> / <cite>assert_called_once_with</cite> can be used with
<cite>self</cite> as a keyword argument</li>
<li>BUGFIX: when patching a class with an explicit spec / spec_set (not a
boolean) it applies &#8220;spec inheritance&#8221; to the return value of the created
mock (the &#8220;instance&#8221;)</li>
<li>BUGFIX: remove the <cite>__unittest</cite> marker causing traceback truncation</li>
<li>Removal of deprecated <cite>patch_object</cite></li>
<li>Private attributes <cite>_name</cite>, <cite>_methods</cite>, &#8216;_children&#8217;, <cite>_wraps</cite> and <cite>_parent</cite>
(etc) renamed to reduce likelihood of clash with user attributes.</li>
<li>Added license file to the distribution</li>
</ul>
</div>
<div class="section" id="version-0-8-0-release-candidate-2">
<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>
<ul class="simple">
<li>Removed the <cite>configure</cite> keyword argument to <cite>create_autospec</cite> and allow
arbitrary keyword arguments (for the <cite>Mock</cite> constructor) instead</li>
<li>Fixed <cite>ANY</cite> equality with some types in <cite>assert_called_with</cite> calls</li>
<li>Switched to a standard Sphinx theme (compatible with
<a class="reference external" href="http://mock.readthedocs.org">readthedocs.org</a>)</li>
</ul>
</div>
<div class="section" id="version-0-8-0-release-candidate-1">
<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>
<ul class="simple">
<li><cite>create_autospec</cite> on the return value of a mocked class will use <cite>__call__</cite>
for the signature rather than <cite>__init__</cite></li>
<li>Performance improvement instantiating <cite>Mock</cite> and <cite>MagicMock</cite></li>
<li>Mocks used as magic methods have the same type as their parent instead of
being hardcoded to <cite>MagicMock</cite></li>
</ul>
<p>Special thanks to Julian Berman for his help with diagnosing and improving
performance in this release.</p>
</div>
<div class="section" id="version-0-8-0-beta-4">
<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>
<ul class="simple">
<li><cite>patch</cite> lookup is done at use time not at decoration time</li>
<li>When attaching a Mock to another Mock as a magic method, calls are recorded
in mock_calls</li>
<li>Addition of <cite>attach_mock</cite> method</li>
<li>Renamed the internal classes <cite>Sentinel</cite> and <cite>SentinelObject</cite> to prevent abuse</li>
<li>BUGFIX: various issues around circular references with mocks (setting a mock
return value to be itself etc)</li>
</ul>
</div>
<div class="section" id="version-0-8-0-beta-3">
<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>
<ul class="simple">
<li>Mocks attached as attributes or return values to other mocks have calls
recorded in <cite>method_calls</cite> and <cite>mock_calls</cite> of the parent (unless a name is
already set on the child)</li>
<li>Addition of <cite>mock_add_spec</cite> method for adding (or changing) a spec on an
existing mock</li>
<li>Improved repr for <cite>Mock.call_args</cite> and entries in <cite>Mock.call_args_list</cite>,
<cite>Mock.method_calls</cite> and <cite>Mock.mock_calls</cite></li>
<li>Improved repr for mocks</li>
<li>BUGFIX: minor fixes in the way <cite>mock_calls</cite> is worked out,
especially for &#8220;intermediate&#8221; mocks in a call chain</li>
</ul>
</div>
<div class="section" id="version-0-8-0-beta-2">
<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>
<ul class="simple">
<li>Setting <cite>side_effect</cite> to an iterable will cause calls to the mock to return
the next value from the iterable</li>
<li>Added <cite>assert_any_call</cite> method</li>
<li>Moved <cite>assert_has_calls</cite> from call lists onto mocks</li>
<li>BUGFIX: <cite>call_args</cite> and all members of <cite>call_args_list</cite> are two tuples of
<cite>(args, kwargs)</cite> again instead of three tuples of <cite>(name, args, kwargs)</cite></li>
</ul>
</div>
<div class="section" id="version-0-8-0-beta-1">
<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>
<ul class="simple">
<li><cite>patch.TEST_PREFIX</cite> for controlling how patchers recognise test methods when
used to decorate a class</li>
<li><cite>Mock</cite> call lists (<cite>call_args_list</cite>, <cite>method_calls</cite> &amp; <cite>mock_calls</cite>) are now
custom list objects that allow membership tests for &#8220;sub lists&#8221; and have
an <cite>assert_has_calls</cite> method for unordered call checks</li>
<li><cite>callargs</cite> changed to <em>always</em> be a three-tuple of <cite>(name, args, kwargs)</cite></li>
<li>Addition of <cite>mock_calls</cite> list for <em>all</em> calls (including magic methods and
chained calls)</li>
<li>Extension of <cite>call</cite> object to support chained calls and <cite>callargs</cite> for better
comparisons with or without names. <cite>call</cite> object has a <cite>call_list</cite> method for
chained calls</li>
<li>Added the public <cite>instance</cite> argument to <cite>create_autospec</cite></li>
<li>Support for using Java exceptions as a <cite>side_effect</cite> on Jython</li>
<li>Improved failure messages for <cite>assert_called_with</cite> and
<cite>assert_called_once_with</cite></li>
<li>Tuples as well as lists can be used to specify allowed methods for <cite>spec</cite> &amp;
<cite>spec_set</cite> arguments</li>
<li>BUGFIX: Fixed bug in <cite>patch.multiple</cite> for argument passing when creating
mocks</li>
<li>Added license file to the distribution</li>
</ul>
</div>
<div class="section" id="version-0-8-0-alpha-2">
<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>
<ul class="simple">
<li><cite>patch.multiple</cite> for doing multiple patches in a single call, using keyword
arguments</li>
<li>New <cite>new_callable</cite> argument to <cite>patch</cite> and <cite>patch.object</cite> allowing you to
pass in a class or callable object (instead of <cite>MagicMock</cite>) that will be
called to replace the object being patched</li>
<li>Addition of <cite>NonCallableMock</cite> and <cite>NonCallableMagicMock</cite>, mocks without a
<cite>__call__</cite> method</li>
<li>Mocks created by <cite>patch</cite> have a <cite>MagicMock</cite> as the <cite>return_value</cite> where a
class is being patched</li>
<li><cite>create_autospec</cite> can create non-callable mocks for non-callable objects.
<cite>return_value</cite> mocks of classes will be non-callable unless the class has
a <cite>__call__</cite> method</li>
<li><cite>autospec</cite> creates a <cite>MagicMock</cite> without a spec for properties and slot
descriptors, because we don&#8217;t know the type of object they return</li>
<li>Removed the &#8220;inherit&#8221; argument from <cite>create_autospec</cite></li>
<li>Calling <cite>stop</cite> on an unstarted patcher fails with a more meaningful error
message</li>
<li>BUGFIX: an error creating a patch, with nested patch decorators, won&#8217;t leave
patches in place</li>
<li>BUGFIX: <cite>__truediv__</cite> and <cite>__rtruediv__</cite> not available as magic methods on
mocks in Python 3</li>
<li>BUGFIX: <cite>assert_called_with</cite> / <cite>assert_called_once_with</cite> can be used with
<cite>self</cite> as a keyword argument</li>
<li>BUGFIX: autospec for functions / methods with an argument named self that
isn&#8217;t the first argument no longer broken</li>
<li>BUGFIX: when patching a class with an explicit spec / spec_set (not a
boolean) it applies &#8220;spec inheritance&#8221; to the return value of the created
mock (the &#8220;instance&#8221;)</li>
<li>BUGFIX: remove the <cite>__unittest</cite> marker causing traceback truncation</li>
</ul>
</div>
<div class="section" id="version-0-8-0-alpha-1">
<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>
<p>mock 0.8.0 is the last version that will support Python 2.4.</p>
<ul>
<li><p class="first">The patchers (<cite>patch</cite>, <cite>patch.object</cite> and <cite>patch.dict</cite>), plus <cite>Mock</cite> and
<cite>MagicMock</cite>, take arbitrary keyword arguments for configuration</p>
</li>
<li><p class="first">New mock method <cite>configure_mock</cite> for setting attributes and return values /
side effects on the mock and its attributes</p>
</li>
<li><p class="first">In Python 2.6 or more recent, <cite>dir</cite> on a mock will report all the dynamically
created attributes (or the full list of attributes if there is a spec) as
well as all the mock methods and attributes.</p>
</li>
<li><p class="first">Module level <cite>FILTER_DIR</cite> added to control whether <cite>dir(mock)</cite> filters
private attributes. <cite>True</cite> by default. Note that <cite>vars(Mock())</cite> can still be
used to get all instance attributes and <cite>dir(type(Mock())</cite> will still return
all the other attributes (irrespective of <cite>FILTER_DIR</cite>)</p>
</li>
<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
default</p>
</li>
<li><p class="first">Added <cite>ANY</cite> for ignoring arguments in <cite>assert_called_with</cite> calls</p>
</li>
<li><p class="first">Addition of <cite>call</cite> helper object</p>
</li>
<li><p class="first">Protocol methods on <cite>MagicMock</cite> are magic mocks, and are created lazily on
first lookup. This means the result of calling a protocol method is a
MagicMock instead of a Mock as it was previously</p>
</li>
<li><p class="first">Added the Mock API (<cite>assert_called_with</cite> etc) to functions created by
<cite>mocksignature</cite></p>
</li>
<li><p class="first">Private attributes <cite>_name</cite>, <cite>_methods</cite>, &#8216;_children&#8217;, <cite>_wraps</cite> and <cite>_parent</cite>
(etc) renamed to reduce likelihood of clash with user attributes.</p>
</li>
<li><p class="first">Implemented auto-speccing (recursive, lazy speccing of mocks with mocked
signatures for functions/methods)</p>
<p>Limitations:</p>
<ul class="simple">
<li>Doesn&#8217;t mock magic methods or attributes (it creates MagicMocks, so the
magic methods are <em>there</em>, they just don&#8217;t have the signature mocked nor
are attributes followed)</li>
<li>Doesn&#8217;t mock function / method attributes</li>
<li>Uses object traversal on the objects being mocked to determine types - so
properties etc may be triggered</li>
<li>The return value of mocked classes (the &#8216;instance&#8217;) has the same call
signature as the class __init__ (as they share the same spec)</li>
</ul>
<p>You create auto-specced mocks by passing <cite>autospec=True</cite> to <cite>patch</cite>.</p>
<p>Note that attributes that are None are special cased and mocked without a
spec (so any attribute / method can be used). This is because None is
typically used as a default value for attributes that may be of some other
type, and as we don&#8217;t know what type that may be we allow all access.</p>
<p>Note that the <cite>autospec</cite> option to <cite>patch</cite> obsoletes the <cite>mocksignature</cite>
option.</p>
</li>
<li><p class="first">Added the <cite>create_autospec</cite> function for manually creating &#8216;auto-specced&#8217;
mocks</p>
</li>
<li><p class="first">Removal of deprecated <cite>patch_object</cite></p>
</li>
</ul>
</div>
<div class="section" id="version-0-7-2">
<h2>2011/05/30 Version 0.7.2<a class="headerlink" href="#version-0-7-2" title="Permalink to this headline"></a></h2>
<ul class="simple">
<li>BUGFIX: instances of list subclasses can now be used as mock specs</li>
<li>BUGFIX: MagicMock equality / inequality protocol methods changed to use the
default equality / inequality. This is done through a <cite>side_effect</cite> on
the mocks used for <cite>__eq__</cite> / <cite>__ne__</cite></li>
</ul>
</div>
<div class="section" id="version-0-7-1">
<h2>2011/05/06 Version 0.7.1<a class="headerlink" href="#version-0-7-1" title="Permalink to this headline"></a></h2>
<p>Package fixes contributed by Michael Fladischer. No code changes.</p>
<ul class="simple">
<li>Include template in package</li>
<li>Use isolated binaries for the tox tests</li>
<li>Unset executable bit on docs</li>
<li>Fix DOS line endings in getting-started.txt</li>
</ul>
</div>
<div class="section" id="version-0-7-0">
<h2>2011/03/05 Version 0.7.0<a class="headerlink" href="#version-0-7-0" title="Permalink to this headline"></a></h2>
<p>No API changes since 0.7.0 rc1. Many documentation changes including a stylish
new <a class="reference external" href="https://github.com/coordt/ADCtheme/">Sphinx theme</a>.</p>
<p>The full set of changes since 0.6.0 are:</p>
<ul class="simple">
<li>Python 3 compatibility</li>
<li>Ability to mock magic methods with <cite>Mock</cite> and addition of <cite>MagicMock</cite>
with pre-created magic methods</li>
<li>Addition of <cite>mocksignature</cite> and <cite>mocksignature</cite> argument to <cite>patch</cite> and
<cite>patch.object</cite></li>
<li>Addition of <cite>patch.dict</cite> for changing dictionaries during a test</li>
<li>Ability to use <cite>patch</cite>, <cite>patch.object</cite> and <cite>patch.dict</cite> as class decorators</li>
<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
deprecated)</li>
<li>Addition of soft comparisons: <cite>call_args</cite>, <cite>call_args_list</cite> and <cite>method_calls</cite>
now return tuple-like objects which compare equal even when empty args
or kwargs are skipped</li>
<li>patchers (<cite>patch</cite>, <cite>patch.object</cite> and <cite>patch.dict</cite>) have start and stop
methods</li>
<li>Addition of <cite>assert_called_once_with</cite> method</li>
<li>Mocks can now be named (<cite>name</cite> argument to constructor) and the name is used
in the repr</li>
<li>repr of a mock with a spec includes the class name of the spec</li>
<li><cite>assert_called_with</cite> works with <cite>python -OO</cite></li>
<li>New <cite>spec_set</cite> keyword argument to <cite>Mock</cite> and <cite>patch</cite>. If used,
attempting to <em>set</em> an attribute on a mock not on the spec will raise an
<cite>AttributeError</cite></li>
<li>Mocks created with a spec can now pass <cite>isinstance</cite> tests (<cite>__class__</cite>
returns the type of the spec)</li>
<li>Added docstrings to all objects</li>
<li>Improved failure message for <cite>Mock.assert_called_with</cite> when the mock
has not been called at all</li>
<li>Decorated functions / methods have their docstring and <cite>__module__</cite>
preserved on Python 2.4.</li>
<li>BUGFIX: <cite>mock.patch</cite> now works correctly with certain types of objects that
proxy attribute access, like the django settings object</li>
<li>BUGFIX: mocks are now copyable (thanks to Ned Batchelder for reporting and
diagnosing this)</li>
<li>BUGFIX: <cite>spec=True</cite> works with old style classes</li>
<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>
as a valid sentinel name (thanks to Stephen Emslie for reporting and
diagnosing this)</li>
<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
<tt class="docutils literal"><span class="pre">KeyboardInterrupt</span></tt></li>
<li>BUGFIX: <cite>reset_mock</cite> caused infinite recursion when a mock is set as its own
return value</li>
<li>BUGFIX: patching the same object twice now restores the patches correctly</li>
<li>with statement tests now skipped on Python 2.4</li>
<li>Tests require unittest2 (or unittest2-py3k) to run</li>
<li>Tested with <a class="reference external" href="http://pypi.python.org/pypi/tox">tox</a> on Python 2.4 - 3.2,
jython and pypy (excluding 3.0)</li>
<li>Added &#8216;build_sphinx&#8217; command to setup.py (requires setuptools or distribute)
Thanks to Florian Bauer</li>
<li>Switched from subversion to mercurial for source code control</li>
<li><a class="reference external" href="http://konryd.blogspot.com/">Konrad Delong</a> added as co-maintainer</li>
</ul>
</div>
<div class="section" id="version-0-7-0-rc-1">
<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>
<p>Changes since beta 4:</p>
<ul class="simple">
<li>Tested with jython, pypy and Python 3.2 and 3.1</li>
<li>Decorated functions / methods have their docstring and <cite>__module__</cite>
preserved on Python 2.4</li>
<li>BUGFIX: <cite>mock.patch</cite> now works correctly with certain types of objects that
proxy attribute access, like the django settings object</li>
<li>BUGFIX: <cite>reset_mock</cite> caused infinite recursion when a mock is set as its own
return value</li>
</ul>
</div>
<div class="section" id="version-0-7-0-beta-4">
<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>
<ul class="simple">
<li>patchers (<cite>patch</cite>, <cite>patch.object</cite> and <cite>patch.dict</cite>) have start and stop
methods</li>
<li>Addition of <cite>assert_called_once_with</cite> method</li>
<li>repr of a mock with a spec includes the class name of the spec</li>
<li><cite>assert_called_with</cite> works with <cite>python -OO</cite></li>
<li>New <cite>spec_set</cite> keyword argument to <cite>Mock</cite> and <cite>patch</cite>. If used,
attempting to <em>set</em> an attribute on a mock not on the spec will raise an
<cite>AttributeError</cite></li>
<li>Attributes and return value of a <cite>MagicMock</cite> are <cite>MagicMock</cite> objects</li>
<li>Attempting to set an unsupported magic method now raises an <cite>AttributeError</cite></li>
<li><cite>patch.dict</cite> works as a class decorator</li>
<li>Switched from subversion to mercurial for source code control</li>
<li>BUGFIX: mocks are now copyable (thanks to Ned Batchelder for reporting and
diagnosing this)</li>
<li>BUGFIX: <cite>spec=True</cite> works with old style classes</li>
<li>BUGFIX: <cite>mocksignature=True</cite> can now patch instance methods via
<cite>patch.object</cite></li>
</ul>
</div>
<div class="section" id="version-0-7-0-beta-3">
<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>
<ul class="simple">
<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>
<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
spec has that method</li>
<li>Mocks can now be named (<cite>name</cite> argument to constructor) and the name is used
in the repr</li>
<li><cite>mocksignature</cite> can now be used with classes (signature based on <cite>__init__</cite>)
and callable objects (signature based on <cite>__call__</cite>)</li>
<li>Mocks created with a spec can now pass <cite>isinstance</cite> tests (<cite>__class__</cite>
returns the type of the spec)</li>
<li>Default numeric value for MagicMock is 1 rather than zero (because the
MagicMock bool defaults to True and 0 is False)</li>
<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
has not been called at all</li>
<li>Adding the following to the set of supported magic methods:<ul>
<li><tt class="docutils literal"><span class="pre">__getformat__</span></tt> and <tt class="docutils literal"><span class="pre">__setformat__</span></tt></li>
<li>pickle methods</li>
<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>
<li><tt class="docutils literal"><span class="pre">__sizeof__</span></tt></li>
</ul>
</li>
<li>Added &#8216;build_sphinx&#8217; command to setup.py (requires setuptools or distribute)
Thanks to Florian Bauer</li>
<li>with statement tests now skipped on Python 2.4</li>
<li>Tests require unittest2 to run on Python 2.7</li>
<li>Improved several docstrings and documentation</li>
</ul>
</div>
<div class="section" id="version-0-7-0-beta-2">
<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>
<ul class="simple">
<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>
<li><tt class="docutils literal"><span class="pre">patch.dict</span></tt> takes a string to specify dictionary as well as a dictionary
object. If a string is supplied the name specified is imported</li>
<li>BUGFIX: <tt class="docutils literal"><span class="pre">patch.dict</span></tt> restores dictionary even when an exception is raised</li>
</ul>
</div>
<div class="section" id="version-0-7-0-beta-1">
<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>
<ul class="simple">
<li>Addition of <tt class="xref py py-func docutils literal"><span class="pre">mocksignature()</span></tt></li>
<li>Ability to mock magic methods</li>
<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>
<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
deprecated)</li>
<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>
<li>Python 3 compatibility (tested with 3.2 but should work with 3.0 &amp; 3.1 as
well)</li>
<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>
<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>
<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>
as a valid sentinel name (thanks to Stephen Emslie for reporting and
diagnosing this)</li>
<li>Addition of soft comparisons: <cite>call_args</cite>, <cite>call_args_list</cite> and <cite>method_calls</cite>
now return tuple-like objects which compare equal even when empty args
or kwargs are skipped</li>
<li>Added docstrings.</li>
<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
<tt class="docutils literal"><span class="pre">KeyboardInterrupt</span></tt></li>
<li>BUGFIX: patching the same object twice now restores the patches correctly</li>
<li>The tests now require <a class="reference external" href="http://pypi.python.org/pypi/unittest2">unittest2</a>
to run</li>
<li><a class="reference external" href="http://konryd.blogspot.com/">Konrad Delong</a> added as co-maintainer</li>
</ul>
</div>
<div class="section" id="version-0-6-0">
<h2>2009/08/22 Version 0.6.0<a class="headerlink" href="#version-0-6-0" title="Permalink to this headline"></a></h2>
<ul class="simple">
<li>New test layout compatible with test discovery</li>
<li>Descriptors (static methods / class methods etc) can now be patched and
restored correctly</li>
<li>Mocks can raise exceptions when called by setting <tt class="docutils literal"><span class="pre">side_effect</span></tt> to an
exception class or instance</li>
<li>Mocks that wrap objects will not pass on calls to the underlying object if
an explicit return_value is set</li>
</ul>
</div>
<div class="section" id="version-0-5-0">
<h2>2009/04/17 Version 0.5.0<a class="headerlink" href="#version-0-5-0" title="Permalink to this headline"></a></h2>
<ul class="simple">
<li>Made DEFAULT part of the public api.</li>
<li>Documentation built with Sphinx.</li>
<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
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>
<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>
<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>
<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>
<li>A new &#8216;create&#8217; keyword argument to patch and patch_object that allows them to patch
(and unpatch) attributes that don&#8217;t exist. (Potentially unsafe to use - it can allow
you to have tests that pass when they are testing an API that doesn&#8217;t exist - use at
your own risk!)</li>
<li>The methods keyword argument to Mock has been removed and merged with spec. The spec
argument can now be a list of methods or an object to take the spec from.</li>
<li>Nested patches may now be applied in a different order (created mocks passed
in the opposite order). This is actually a bugfix.</li>
<li>patch and patch_object now take a spec keyword argument. If spec is
passed in as &#8216;True&#8217; then the Mock created will take the object it is replacing
as its spec object. If the object being replaced is a class, then the return
value for the mock will also use the class as a spec.</li>
<li>A Mock created without a spec will not attempt to mock any magic methods / attributes
(they will raise an <tt class="docutils literal"><span class="pre">AttributeError</span></tt> instead).</li>
</ul>
</div>
<div class="section" id="version-0-4-0">
<h2>2008/10/12 Version 0.4.0<a class="headerlink" href="#version-0-4-0" title="Permalink to this headline"></a></h2>
<ul>
<li><p class="first">Default return value is now a new mock rather than None</p>
</li>
<li><p class="first">return_value added as a keyword argument to the constructor</p>
</li>
<li><p class="first">New method &#8216;assert_called_with&#8217;</p>
</li>
<li><p class="first">Added &#8216;side_effect&#8217; attribute / keyword argument called when mock is called</p>
</li>
<li><p class="first">patch decorator split into two decorators:</p>
<blockquote>
<div><ul class="simple">
<li><tt class="docutils literal"><span class="pre">patch_object</span></tt> which takes an object and an attribute name to patch
(plus optionally a value to patch with which defaults to a mock object)</li>
<li><tt class="docutils literal"><span class="pre">patch</span></tt> which takes a string specifying a target to patch; in the form
&#8216;package.module.Class.attribute&#8217;. (plus optionally a value to
patch with which defaults to a mock object)</li>
</ul>
</div></blockquote>
</li>
<li><p class="first">Can now patch objects with <tt class="docutils literal"><span class="pre">None</span></tt></p>
</li>
<li><p class="first">Change to patch for nose compatibility with error reporting in wrapped functions</p>
</li>
<li><p class="first">Reset no longer clears children / return value etc - it just resets
call count and call args. It also calls reset on all children (and
the return value if it is a mock).</p>
</li>
</ul>
<p>Thanks to Konrad Delong, Kevin Dangoor and others for patches and suggestions.</p>
</div>
<div class="section" id="version-0-3-1">
<h2>2007/12/03 Version 0.3.1<a class="headerlink" href="#version-0-3-1" title="Permalink to this headline"></a></h2>
<p><tt class="docutils literal"><span class="pre">patch</span></tt> maintains the name of decorated functions for compatibility with nose
test autodiscovery.</p>
<p>Tests decorated with <tt class="docutils literal"><span class="pre">patch</span></tt> that use the two argument form (implicit mock
creation) will receive the mock(s) passed in as extra arguments.</p>
<p>Thanks to Kevin Dangoor for these changes.</p>
</div>
<div class="section" id="version-0-3-0">
<h2>2007/11/30 Version 0.3.0<a class="headerlink" href="#version-0-3-0" title="Permalink to this headline"></a></h2>
<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
argument for patching modules.</p>
<p>The third argument to <tt class="docutils literal"><span class="pre">patch</span></tt> is optional - a mock will be created by
default if it is not passed in.</p>
</div>
<div class="section" id="version-0-2-1">
<h2>2007/11/21 Version 0.2.1<a class="headerlink" href="#version-0-2-1" title="Permalink to this headline"></a></h2>
<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>
</div>
<div class="section" id="version-0-2-0">
<h2>2007/11/20 Version 0.2.0<a class="headerlink" href="#version-0-2-0" title="Permalink to this headline"></a></h2>
<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
specification object.</p>
<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>
<p>Added <tt class="docutils literal"><span class="pre">sentinel</span></tt> for convenient access to unique objects.</p>
<p>Distribution includes unit tests.</p>
</div>
<div class="section" id="version-0-1-0">
<h2>2007/11/19 Version 0.1.0<a class="headerlink" href="#version-0-1-0" title="Permalink to this headline"></a></h2>
<p>Initial release.</p>
</div>
</div>
<div class="section" id="todo-and-limitations">
<h1>TODO and Limitations<a class="headerlink" href="#todo-and-limitations" title="Permalink to this headline"></a></h1>
<p>Contributions, bug reports and comments welcomed!</p>
<p>Feature requests and bug reports are handled on the issue tracker:</p>
<blockquote>
<div><ul class="simple">
<li><a class="reference external" href="http://code.google.com/p/mock/issues/list">mock issue tracker</a></li>
</ul>
</div></blockquote>
<p><cite>wraps</cite> is not integrated with magic methods.</p>
<p><cite>patch</cite> could auto-do the patching in the constructor and unpatch in the
destructor. This would be useful in itself, but violates TOOWTDI and would be
unsafe for IronPython &amp; PyPy (non-deterministic calling of destructors).
Destructors aren&#8217;t called in CPython where there are cycles, but a weak
reference with a callback can be used to get round this.</p>
<p><cite>Mock</cite> has several attributes. This makes it unsuitable for mocking objects
that use these attribute names. A way round this would be to provide methods
that <em>hide</em> these attributes when needed. In 0.8 many, but not all, of these
attributes are renamed to gain a <cite>_mock</cite> prefix, making it less likely that
they will clash. Any outstanding attributes that haven&#8217;t been modified with
the prefix should be changed.</p>
<p>If a patch is started using <cite>patch.start</cite> and then not stopped correctly then
the unpatching is not done. Using weak references it would be possible to
detect and fix this when the patch object itself is garbage collected. This
would be tricky to get right though.</p>
<p>When a <cite>Mock</cite> is created by <cite>patch</cite>, arbitrary keywords can be used to set
attributes. If <cite>patch</cite> is created with a <cite>spec</cite>, and is replacing a class, then
a <cite>return_value</cite> mock is created. The keyword arguments are not applied to the
child mock, but could be.</p>
<p>When mocking a class with <cite>patch</cite>, passing in <cite>spec=True</cite> or <cite>autospec=True</cite>,
the mock class has an instance created from the same spec. Should this be the
default behaviour for mocks anyway (mock return values inheriting the spec
from their parent), or should it be controlled by an additional keyword
argument (<cite>inherit</cite>) to the Mock constructor? <cite>create_autospec</cite> does this, so
an additional keyword argument to Mock is probably unnecessary.</p>
<p>The <cite>mocksignature</cite> argument to <cite>patch</cite> with a non <cite>Mock</cite> passed into
<cite>new_callable</cite> will <em>probably</em> cause an error. Should it just be invalid?</p>
<p>Note that <cite>NonCallableMock</cite> and <cite>NonCallableMagicMock</cite> still have the unused
(and unusable) attributes: <cite>return_value</cite>, <cite>side_effect</cite>, <cite>call_count</cite>,
<cite>call_args</cite> and <cite>call_args_list</cite>. These could be removed or raise errors on
getting / setting. They also have the <cite>assert_called_with</cite> and
<cite>assert_called_once_with</cite> methods. Removing these would be pointless as
fetching them would create a mock (attribute) that could be called without
error.</p>
<p>Some outstanding technical debt. The way autospeccing mocks function
signatures was copied and modified from <cite>mocksignature</cite>. This could all be
refactored into one set of functions instead of two. The way we tell if
patchers are started and if a patcher is being used for a <cite>patch.multiple</cite>
call are both horrible. There are now a host of helper functions that should
be rationalised. (Probably time to split mock into a package instead of a
module.)</p>
<p>Passing arbitrary keyword arguments to <cite>create_autospec</cite>, or <cite>patch</cite> with
<cite>autospec</cite>, when mocking a <em>function</em> works fine. However, the arbitrary
attributes are set on the created mock - but <cite>create_autospec</cite> returns a
real function (which doesn&#8217;t have those attributes). However, what is the use
case for using autospec to create functions with attributes that don&#8217;t exist
on the original?</p>
<p><cite>mocksignature</cite>, plus the <cite>call_args_list</cite> and <cite>method_calls</cite> attributes of
<cite>Mock</cite> could all be deprecated.</p>
</div>
</div>
</div>
</div>
<div class="sphinxsidebar">
<div class="sphinxsidebarwrapper">
<h3><a href="index.html">Table Of Contents</a></h3>
<ul>
<li><a class="reference internal" href="#">CHANGELOG</a><ul>
<li><a class="reference internal" href="#version-1-0-0">2012/10/07 Version 1.0.0</a></li>
<li><a class="reference internal" href="#version-1-0-0-beta-1">2012/07/13 Version 1.0.0 beta 1</a></li>
<li><a class="reference internal" href="#version-1-0-0-alpha-2">2012/05/04 Version 1.0.0 alpha 2</a></li>
<li><a class="reference internal" href="#version-1-0-0-alpha-1">2012/03/25 Version 1.0.0 alpha 1</a></li>
<li><a class="reference internal" href="#version-0-8-0">2012/02/13 Version 0.8.0</a></li>
<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>
<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>
<li><a class="reference internal" href="#version-0-8-0-beta-4">2011/10/09 Version 0.8.0 beta 4</a></li>
<li><a class="reference internal" href="#version-0-8-0-beta-3">2011/08/15 Version 0.8.0 beta 3</a></li>
<li><a class="reference internal" href="#version-0-8-0-beta-2">2011/08/05 Version 0.8.0 beta 2</a></li>
<li><a class="reference internal" href="#version-0-8-0-beta-1">2011/07/25 Version 0.8.0 beta 1</a></li>
<li><a class="reference internal" href="#version-0-8-0-alpha-2">2011/07/16 Version 0.8.0 alpha 2</a></li>
<li><a class="reference internal" href="#version-0-8-0-alpha-1">2011/06/14 Version 0.8.0 alpha 1</a></li>
<li><a class="reference internal" href="#version-0-7-2">2011/05/30 Version 0.7.2</a></li>
<li><a class="reference internal" href="#version-0-7-1">2011/05/06 Version 0.7.1</a></li>
<li><a class="reference internal" href="#version-0-7-0">2011/03/05 Version 0.7.0</a></li>
<li><a class="reference internal" href="#version-0-7-0-rc-1">2011/02/16 Version 0.7.0 RC 1</a></li>
<li><a class="reference internal" href="#version-0-7-0-beta-4">2010/11/12 Version 0.7.0 beta 4</a></li>
<li><a class="reference internal" href="#version-0-7-0-beta-3">2010/09/18 Version 0.7.0 beta 3</a></li>
<li><a class="reference internal" href="#version-0-7-0-beta-2">2010/06/23 Version 0.7.0 beta 2</a></li>
<li><a class="reference internal" href="#version-0-7-0-beta-1">2010/06/22 Version 0.7.0 beta 1</a></li>
<li><a class="reference internal" href="#version-0-6-0">2009/08/22 Version 0.6.0</a></li>
<li><a class="reference internal" href="#version-0-5-0">2009/04/17 Version 0.5.0</a></li>
<li><a class="reference internal" href="#version-0-4-0">2008/10/12 Version 0.4.0</a></li>
<li><a class="reference internal" href="#version-0-3-1">2007/12/03 Version 0.3.1</a></li>
<li><a class="reference internal" href="#version-0-3-0">2007/11/30 Version 0.3.0</a></li>
<li><a class="reference internal" href="#version-0-2-1">2007/11/21 Version 0.2.1</a></li>
<li><a class="reference internal" href="#version-0-2-0">2007/11/20 Version 0.2.0</a></li>
<li><a class="reference internal" href="#version-0-1-0">2007/11/19 Version 0.1.0</a></li>
</ul>
</li>
<li><a class="reference internal" href="#todo-and-limitations">TODO and Limitations</a></li>
</ul>
<h4>Previous topic</h4>
<p class="topless"><a href="compare.html"
title="previous chapter">Mock Library Comparison</a></p>
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="_sources/changelog.txt"
rel="nofollow">Show Source</a></li>
</ul>
<div id="searchbox" style="display: none">
<h3>Quick search</h3>
<form class="search" action="search.html" method="get">
<input type="text" name="q" />
<input type="submit" value="Go" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
<p class="searchtip" style="font-size: 90%">
Enter search terms or a module, class or function name.
</p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="compare.html" title="Mock Library Comparison"
>previous</a> |</li>
<li><a href="index.html">Mock 1.0.0 documentation</a> &raquo;</li>
</ul>
</div>
<div class="footer">
&copy; Copyright 2007-2012, Michael Foord &amp; the mock team.
Last updated on Oct 07, 2012.
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.3.
</div>
</body>
</html>