1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/python/mock-1.0.0/html/sentinel.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,156 @@ 1.4 + 1.5 +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 1.6 + "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 1.7 + 1.8 + 1.9 +<html xmlns="http://www.w3.org/1999/xhtml"> 1.10 + <head> 1.11 + <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 1.12 + 1.13 + <title>Sentinel — Mock 1.0.0 documentation</title> 1.14 + 1.15 + <link rel="stylesheet" href="_static/nature.css" type="text/css" /> 1.16 + <link rel="stylesheet" href="_static/pygments.css" type="text/css" /> 1.17 + 1.18 + <script type="text/javascript"> 1.19 + var DOCUMENTATION_OPTIONS = { 1.20 + URL_ROOT: '', 1.21 + VERSION: '1.0.0', 1.22 + COLLAPSE_INDEX: false, 1.23 + FILE_SUFFIX: '.html', 1.24 + HAS_SOURCE: true 1.25 + }; 1.26 + </script> 1.27 + <script type="text/javascript" src="_static/jquery.js"></script> 1.28 + <script type="text/javascript" src="_static/underscore.js"></script> 1.29 + <script type="text/javascript" src="_static/doctools.js"></script> 1.30 + <link rel="top" title="Mock 1.0.0 documentation" href="index.html" /> 1.31 + <link rel="next" title="Mocking Magic Methods" href="magicmock.html" /> 1.32 + <link rel="prev" title="Helpers" href="helpers.html" /> 1.33 + </head> 1.34 + <body> 1.35 + <div class="related"> 1.36 + <h3>Navigation</h3> 1.37 + <ul> 1.38 + <li class="right" style="margin-right: 10px"> 1.39 + <a href="genindex.html" title="General Index" 1.40 + accesskey="I">index</a></li> 1.41 + <li class="right" > 1.42 + <a href="magicmock.html" title="Mocking Magic Methods" 1.43 + accesskey="N">next</a> |</li> 1.44 + <li class="right" > 1.45 + <a href="helpers.html" title="Helpers" 1.46 + accesskey="P">previous</a> |</li> 1.47 + <li><a href="index.html">Mock 1.0.0 documentation</a> »</li> 1.48 + </ul> 1.49 + </div> 1.50 + 1.51 + <div class="document"> 1.52 + <div class="documentwrapper"> 1.53 + <div class="bodywrapper"> 1.54 + <div class="body"> 1.55 + 1.56 + <div class="section" id="sentinel"> 1.57 +<h1>Sentinel<a class="headerlink" href="#sentinel" title="Permalink to this headline">¶</a></h1> 1.58 +<dl class="data"> 1.59 +<dt id="mock.sentinel"> 1.60 +<tt class="descname">sentinel</tt><a class="headerlink" href="#mock.sentinel" title="Permalink to this definition">¶</a></dt> 1.61 +<dd><p>The <tt class="docutils literal"><span class="pre">sentinel</span></tt> object provides a convenient way of providing unique 1.62 +objects for your tests.</p> 1.63 +<p>Attributes are created on demand when you access them by name. Accessing 1.64 +the same attribute will always return the same object. The objects 1.65 +returned have a sensible repr so that test failure messages are readable.</p> 1.66 +</dd></dl> 1.67 + 1.68 +<dl class="data"> 1.69 +<dt id="mock.DEFAULT"> 1.70 +<tt class="descname">DEFAULT</tt><a class="headerlink" href="#mock.DEFAULT" title="Permalink to this definition">¶</a></dt> 1.71 +<dd><p>The <cite>DEFAULT</cite> object is a pre-created sentinel (actually 1.72 +<cite>sentinel.DEFAULT</cite>). It can be used by <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> 1.73 +functions to indicate that the normal return value should be used.</p> 1.74 +</dd></dl> 1.75 + 1.76 +<div class="section" id="sentinel-example"> 1.77 +<h2>Sentinel Example<a class="headerlink" href="#sentinel-example" title="Permalink to this headline">¶</a></h2> 1.78 +<p>Sometimes when testing you need to test that a specific object is passed as an 1.79 +argument to another method, or returned. It can be common to create named 1.80 +sentinel objects to test this. <cite>sentinel</cite> provides a convenient way of 1.81 +creating and testing the identity of objects like this.</p> 1.82 +<p>In this example we monkey patch <cite>method</cite> to return 1.83 +<cite>sentinel.some_object</cite>:</p> 1.84 +<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">real</span> <span class="o">=</span> <span class="n">ProductionClass</span><span class="p">()</span> 1.85 +<span class="gp">>>> </span><span class="n">real</span><span class="o">.</span><span class="n">method</span> <span class="o">=</span> <span class="n">Mock</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s">"method"</span><span class="p">)</span> 1.86 +<span class="gp">>>> </span><span class="n">real</span><span class="o">.</span><span class="n">method</span><span class="o">.</span><span class="n">return_value</span> <span class="o">=</span> <span class="n">sentinel</span><span class="o">.</span><span class="n">some_object</span> 1.87 +<span class="gp">>>> </span><span class="n">result</span> <span class="o">=</span> <span class="n">real</span><span class="o">.</span><span class="n">method</span><span class="p">()</span> 1.88 +<span class="gp">>>> </span><span class="k">assert</span> <span class="n">result</span> <span class="ow">is</span> <span class="n">sentinel</span><span class="o">.</span><span class="n">some_object</span> 1.89 +<span class="gp">>>> </span><span class="n">sentinel</span><span class="o">.</span><span class="n">some_object</span> 1.90 +<span class="go">sentinel.some_object</span> 1.91 +</pre></div> 1.92 +</div> 1.93 +</div> 1.94 +</div> 1.95 + 1.96 + 1.97 + </div> 1.98 + </div> 1.99 + </div> 1.100 + <div class="sphinxsidebar"> 1.101 + <div class="sphinxsidebarwrapper"> 1.102 + <h3><a href="index.html">Table Of Contents</a></h3> 1.103 + <ul> 1.104 +<li><a class="reference internal" href="#">Sentinel</a><ul> 1.105 +<li><a class="reference internal" href="#sentinel-example">Sentinel Example</a></li> 1.106 +</ul> 1.107 +</li> 1.108 +</ul> 1.109 + 1.110 + <h4>Previous topic</h4> 1.111 + <p class="topless"><a href="helpers.html" 1.112 + title="previous chapter">Helpers</a></p> 1.113 + <h4>Next topic</h4> 1.114 + <p class="topless"><a href="magicmock.html" 1.115 + title="next chapter">Mocking Magic Methods</a></p> 1.116 + <h3>This Page</h3> 1.117 + <ul class="this-page-menu"> 1.118 + <li><a href="_sources/sentinel.txt" 1.119 + rel="nofollow">Show Source</a></li> 1.120 + </ul> 1.121 +<div id="searchbox" style="display: none"> 1.122 + <h3>Quick search</h3> 1.123 + <form class="search" action="search.html" method="get"> 1.124 + <input type="text" name="q" /> 1.125 + <input type="submit" value="Go" /> 1.126 + <input type="hidden" name="check_keywords" value="yes" /> 1.127 + <input type="hidden" name="area" value="default" /> 1.128 + </form> 1.129 + <p class="searchtip" style="font-size: 90%"> 1.130 + Enter search terms or a module, class or function name. 1.131 + </p> 1.132 +</div> 1.133 +<script type="text/javascript">$('#searchbox').show(0);</script> 1.134 + </div> 1.135 + </div> 1.136 + <div class="clearer"></div> 1.137 + </div> 1.138 + <div class="related"> 1.139 + <h3>Navigation</h3> 1.140 + <ul> 1.141 + <li class="right" style="margin-right: 10px"> 1.142 + <a href="genindex.html" title="General Index" 1.143 + >index</a></li> 1.144 + <li class="right" > 1.145 + <a href="magicmock.html" title="Mocking Magic Methods" 1.146 + >next</a> |</li> 1.147 + <li class="right" > 1.148 + <a href="helpers.html" title="Helpers" 1.149 + >previous</a> |</li> 1.150 + <li><a href="index.html">Mock 1.0.0 documentation</a> »</li> 1.151 + </ul> 1.152 + </div> 1.153 + <div class="footer"> 1.154 + © Copyright 2007-2012, Michael Foord & the mock team. 1.155 + Last updated on Oct 07, 2012. 1.156 + Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.3. 1.157 + </div> 1.158 + </body> 1.159 +</html> 1.160 \ No newline at end of file