File: index.html

package info (click to toggle)
python-mock 0.6.0-1.1
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 780 kB
  • ctags: 245
  • sloc: python: 755; makefile: 28
file content (234 lines) | stat: -rw-r--r-- 13,662 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
<!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>Mock - Mocking and Testing Library &mdash; Mock v0.6.0 documentation</title>
    <link rel="stylesheet" href="_static/default.css" type="text/css" />
    <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '',
        VERSION:     '0.6.0',
        COLLAPSE_MODINDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="_static/jquery.js"></script>
    <script type="text/javascript" src="_static/doctools.js"></script>
    <link rel="top" title="Mock v0.6.0 documentation" href="" />
    <link rel="next" title="The Mock Class" href="mock.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="mock.html" title="The Mock Class"
             accesskey="N">next</a> |</li>
        <li><a href="">Mock v0.6.0 documentation</a> &raquo;</li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <div class="section" id="module-mock">
<h1>Mock - Mocking and Testing Library<a class="headerlink" href="#module-mock" title="Permalink to this headline">¶</a></h1>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Author:</th><td class="field-body"><a class="reference external" href="http://www.voidspace.org.uk/python/weblog/index.shtml">Michael Foord</a></td>
</tr>
<tr class="field"><th class="field-name">Version:</th><td class="field-body">Mock 0.6.0</td>
</tr>
<tr class="field"><th class="field-name">Date:</th><td class="field-body">2009/08/22</td>
</tr>
<tr class="field"><th class="field-name">Homepage:</th><td class="field-body"><a class="reference external" href="http://www.voidspace.org.uk/python/mock/">Mock Homepage</a></td>
</tr>
<tr class="field"><th class="field-name">Documentation:</th><td class="field-body"><a class="reference external" href="http://www.voidspace.org.uk/downloads/mock.pdf">PDF Documentation</a></td>
</tr>
<tr class="field"><th class="field-name">License:</th><td class="field-body"><a class="reference external" href="http://www.voidspace.org.uk/python/license.shtml">BSD License</a></td>
</tr>
<tr class="field"><th class="field-name">Support:</th><td class="field-body"><a class="reference external" href="http://lists.idyll.org/listinfo/testing-in-python">Testing in Python Email List</a></td>
</tr>
<tr class="field"><th class="field-name">Contact:</th><td class="field-body"><a class="reference external" href="mailto:fuzzyman&#37;&#52;&#48;voidspace&#46;org&#46;uk">fuzzyman<span>&#64;</span>voidspace<span>&#46;</span>org<span>&#46;</span>uk</a></td>
</tr>
</tbody>
</table>
<div class="section" id="introduction">
<h2>Introduction<a class="headerlink" href="#introduction" title="Permalink to this headline">¶</a></h2>
<p><tt class="docutils literal"><span class="pre">mock</span></tt> provides a core <a title="mock.Mock" class="reference external" href="mock.html#mock.Mock"><tt class="xref docutils literal"><span class="pre">mock.Mock</span></tt></a> class that is intended to reduce the need to
create a host of trivial stubs throughout your test suite. After performing an
action, you can make assertions about which methods / attributes were used and
arguments they were called with. You can also specify return values and set
specific attributes in the normal way.</p>
<p>It also provides a <a title="mock.patch" class="reference external" href="patch.html#mock.patch"><tt class="xref docutils literal"><span class="pre">mock.patch()</span></tt></a> decorator that handles patching module and class
level attributes within the scope of a test, along with <a title="mock.sentinel" class="reference external" href="sentinel.html#mock.sentinel"><tt class="xref docutils literal"><span class="pre">mock.sentinel</span></tt></a> for
creating unique objects.</p>
<p>Most mocking libraries follow the &#8216;record -&gt; replay&#8217; pattern of mocking. I
prefer the &#8216;action -&gt; assertion&#8217; pattern, which is more readable and intuitive;
particularly when working with the Python <a class="reference external" href="http://docs.python.org/lib/module-unittest.html">unittest module</a>. For a discussion of the
merits of the two approaches, see <a class="reference external" href="http://www.voidspace.org.uk/python/articles/mocking.shtml">Mocking, Patching, Stubbing: all that Stuff</a>.</p>
</div>
<div class="section" id="downloading">
<h2>Downloading<a class="headerlink" href="#downloading" title="Permalink to this headline">¶</a></h2>
<p>The current version is <strong>0.6.0</strong>, dated 23rd August 2009. Mock is still
experimental; the API may change. If you find bugs or
have suggestions for improvements / extensions then please email me.</p>
<ul class="simple">
<li><a class="reference external" href="http://www.voidspace.org.uk/downloads/mock.py">mock.py (module only)</a></li>
<li><a class="reference external" href="http://www.voidspace.org.uk/downloads/mock-0.6.0.zip">mock-0.6.0.zip (module, tests and documentation)</a></li>
<li><a class="reference external" href="http://www.voidspace.org.uk/downloads/mock.pdf">mock documentation as PDF</a></li>
<li><a class="reference external" href="http://code.google.com/p/mock/">Google Code Home &amp; Subversion Repository</a></li>
</ul>
<p>You can checkout the latest development version from the Google Code Subversion
repository with the following command:</p>
<blockquote>
<tt class="docutils literal"><span class="pre">svn</span> <span class="pre">checkout</span> <span class="pre">http://mock.googlecode.com/svn/trunk/</span> <span class="pre">mock-read-only</span></tt></blockquote>
<p>Mock is registered with PyPi (<a class="reference external" href="http://pypi.python.org/pypi/mock/">Mock on PyPi</a>).
If you have pip or Distribute you can install mock with:</p>
<blockquote>
<div class="line-block">
<div class="line"><tt class="docutils literal"><span class="pre">easy_install</span> <span class="pre">mock</span></tt></div>
<div class="line"><tt class="docutils literal"><span class="pre">pip</span> <span class="pre">mock</span></tt></div>
</div>
</blockquote>
</div>
<div class="section" id="api-documentation">
<h2>API Documentation<a class="headerlink" href="#api-documentation" title="Permalink to this headline">¶</a></h2>
<ul>
<li class="toctree-l1"><a class="reference external" href="mock.html">The Mock Class</a><ul>
<li class="toctree-l2"><a class="reference external" href="mock.html#methods">Methods</a></li>
<li class="toctree-l2"><a class="reference external" href="mock.html#calling">Calling</a></li>
<li class="toctree-l2"><a class="reference external" href="mock.html#attributes">Attributes</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference external" href="patch.html">Patch Decorators</a><ul>
<li class="toctree-l2"><a class="reference external" href="patch.html#patch">patch</a></li>
<li class="toctree-l2"><a class="reference external" href="patch.html#patch-object">patch_object</a></li>
<li class="toctree-l2"><a class="reference external" href="patch.html#nesting-patch-decorators">Nesting Patch Decorators</a></li>
<li class="toctree-l2"><a class="reference external" href="patch.html#patching-descriptors">Patching Descriptors</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference external" href="sentinel.html">Sentinel</a><ul>
<li class="toctree-l2"><a class="reference external" href="sentinel.html#sentinel-example">Sentinel Example</a></li>
</ul>
</li>
</ul>
</div>
<div class="section" id="user-guide">
<h2>User Guide<a class="headerlink" href="#user-guide" title="Permalink to this headline">¶</a></h2>
<ul>
<li class="toctree-l1"><a class="reference external" href="getting-started.html">Getting Started with Mock</a><ul>
<li class="toctree-l2"><a class="reference external" href="getting-started.html#using-mock">Using Mock</a></li>
<li class="toctree-l2"><a class="reference external" href="getting-started.html#sentinel">Sentinel</a></li>
<li class="toctree-l2"><a class="reference external" href="getting-started.html#patch-decorators">Patch Decorators</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference external" href="examples.html">Examples</a><ul>
<li class="toctree-l2"><a class="reference external" href="examples.html#mock-examples">Mock Examples</a></li>
<li class="toctree-l2"><a class="reference external" href="examples.html#patch-decorator-examples">Patch Decorator Examples</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference external" href="todo.html">TODO and Limitations</a></li>
<li class="toctree-l1"><a class="reference external" href="changelog.html">CHANGELOG</a><ul>
<li class="toctree-l2"><a class="reference external" href="changelog.html#version-0-6-0">2009/08/22 Version 0.6.0</a></li>
<li class="toctree-l2"><a class="reference external" href="changelog.html#version-0-5-0">2009/04/17 Version 0.5.0</a></li>
<li class="toctree-l2"><a class="reference external" href="changelog.html#version-0-4-0">2008/10/12 Version 0.4.0</a></li>
<li class="toctree-l2"><a class="reference external" href="changelog.html#version-0-3-1">2007/12/03  Version 0.3.1</a></li>
<li class="toctree-l2"><a class="reference external" href="changelog.html#version-0-3-0">2007/11/30  Version 0.3.0</a></li>
<li class="toctree-l2"><a class="reference external" href="changelog.html#version-0-2-1">2007/11/21  Version 0.2.1</a></li>
<li class="toctree-l2"><a class="reference external" href="changelog.html#version-0-2-0">2007/11/20  Version 0.2.0</a></li>
<li class="toctree-l2"><a class="reference external" href="changelog.html#version-0-1-0">2007/11/19  Version 0.1.0</a></li>
</ul>
</li>
</ul>
</div>
<div class="section" id="references">
<h2>References<a class="headerlink" href="#references" title="Permalink to this headline">¶</a></h2>
<p>Articles and blog entries on testing with Mock:</p>
<ul class="simple">
<li><a class="reference external" href="http://agiletesting.blogspot.com/2009/07/python-mock-testing-techniques-and.html">Python mock testing techniques and tools</a></li>
<li><a class="reference external" href="http://techblog.ironfroggy.com/2008/10/how-to-test.html">How To Test Django Template Tags</a></li>
<li><a class="reference external" href="http://pypap.blogspot.com/2008/10/newbie-nugget-unit-testing-with-mock.html">A presentation on Unit Testing with Mock</a></li>
<li><a class="reference external" href="http://michael-a-nelson.blogspot.com/2008/09/mocking-with-django-and-google-app.html">Mocking with Django and Google AppEngine</a></li>
</ul>
</div>
</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
            <h3><a href="">Table Of Contents</a></h3>
            <ul>
<li><a class="reference external" href="">Mock - Mocking and Testing Library</a><ul>
<li><a class="reference external" href="#introduction">Introduction</a></li>
<li><a class="reference external" href="#downloading">Downloading</a></li>
<li><a class="reference external" href="#api-documentation">API Documentation</a><ul>
</ul>
</li>
<li><a class="reference external" href="#user-guide">User Guide</a><ul>
</ul>
</li>
<li><a class="reference external" href="#references">References</a></li>
</ul>
</li>
</ul>

            <h4>Next topic</h4>
            <p class="topless"><a href="mock.html"
                                  title="next chapter">The Mock Class</a></p>
            <h3>This Page</h3>
            <ul class="this-page-menu">
              <li><a href="_sources/index.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" size="18" />
                <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="mock.html" title="The Mock Class"
             >next</a> |</li>
        <li><a href="">Mock v0.6.0 documentation</a> &raquo;</li> 
      </ul>
    </div>
    <div class="footer">
      &copy; Copyright 2009, Michael Foord.
      Last updated on Aug 22, 2009.
      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 0.6.1.
    </div>
  </body>
</html>