This file is indexed.

/usr/share/doc/python-logutils-doc/html/testing.html is in python-logutils-doc 0.3.3-5.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
<!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>Unit testing &mdash; Logutils 0.3.3 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.3.3',
        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="Logutils 0.3.3 documentation" href="index.html" />
    <link rel="next" title="Dictionary-based Configuration" href="dictconfig.html" />
    <link rel="prev" title="Working with Redis queues" href="redis.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="py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="dictconfig.html" title="Dictionary-based Configuration"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="redis.html" title="Working with Redis queues"
             accesskey="P">previous</a> |</li>
        <li><a href="index.html">Logutils 0.3.3 documentation</a> &raquo;</li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <div class="section" id="unit-testing">
<h1>Unit testing<a class="headerlink" href="#unit-testing" title="Permalink to this headline"></a></h1>
<p>When developing unit tests, you may find the
<a class="reference internal" href="#logutils.testing.TestHandler" title="logutils.testing.TestHandler"><tt class="xref py py-class docutils literal"><span class="pre">TestHandler</span></tt></a> and <a class="reference internal" href="#logutils.testing.Matcher" title="logutils.testing.Matcher"><tt class="xref py py-class docutils literal"><span class="pre">Matcher</span></tt></a>
classes useful.</p>
<p>Typical usage:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">logging</span>
<span class="kn">from</span> <span class="nn">logutils.testing</span> <span class="kn">import</span> <span class="n">TestHandler</span><span class="p">,</span> <span class="n">Matcher</span>
<span class="kn">import</span> <span class="nn">unittest</span>

<span class="k">class</span> <span class="nc">LoggingTest</span><span class="p">(</span><span class="n">unittest</span><span class="o">.</span><span class="n">TestCase</span><span class="p">):</span>
    <span class="k">def</span> <span class="nf">setUp</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">handler</span> <span class="o">=</span> <span class="n">h</span> <span class="o">=</span> <span class="n">TestHandler</span><span class="p">(</span><span class="n">Matcher</span><span class="p">())</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">logger</span> <span class="o">=</span> <span class="n">l</span> <span class="o">=</span> <span class="n">logging</span><span class="o">.</span><span class="n">getLogger</span><span class="p">()</span>
        <span class="n">l</span><span class="o">.</span><span class="n">addHandler</span><span class="p">(</span><span class="n">h</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">tearDown</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">removeHandler</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">handler</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">handler</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>

    <span class="k">def</span> <span class="nf">test_simple</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="s">&quot;Simple test of logging test harness.&quot;</span>
        <span class="c"># Just as a demo, let&#39;s log some messages.</span>
        <span class="c"># Only one should show up in the log.</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s">&quot;This won&#39;t show up.&quot;</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s">&quot;Neither will this.&quot;</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">warning</span><span class="p">(</span><span class="s">&quot;But this will.&quot;</span><span class="p">)</span>
        <span class="n">h</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">handler</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">assertTrue</span><span class="p">(</span><span class="n">h</span><span class="o">.</span><span class="n">matches</span><span class="p">(</span><span class="n">levelno</span><span class="o">=</span><span class="n">logging</span><span class="o">.</span><span class="n">WARNING</span><span class="p">))</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">assertFalse</span><span class="p">(</span><span class="n">h</span><span class="o">.</span><span class="n">matches</span><span class="p">(</span><span class="n">levelno</span><span class="o">=</span><span class="n">logging</span><span class="o">.</span><span class="n">DEBUG</span><span class="p">))</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">assertFalse</span><span class="p">(</span><span class="n">h</span><span class="o">.</span><span class="n">matches</span><span class="p">(</span><span class="n">levelno</span><span class="o">=</span><span class="n">logging</span><span class="o">.</span><span class="n">INFO</span><span class="p">))</span>

    <span class="k">def</span> <span class="nf">test_partial</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="s">&quot;Test of partial matching in logging test harness.&quot;</span>
        <span class="c"># Just as a demo, let&#39;s log some messages.</span>
        <span class="c"># Only one should show up in the log.</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s">&quot;This won&#39;t show up.&quot;</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s">&quot;Neither will this.&quot;</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">warning</span><span class="p">(</span><span class="s">&quot;But this will.&quot;</span><span class="p">)</span>
        <span class="n">h</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">handler</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">assertTrue</span><span class="p">(</span><span class="n">h</span><span class="o">.</span><span class="n">matches</span><span class="p">(</span><span class="n">msg</span><span class="o">=</span><span class="s">&quot;ut th&quot;</span><span class="p">))</span> <span class="c"># from &quot;But this will&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">assertTrue</span><span class="p">(</span><span class="n">h</span><span class="o">.</span><span class="n">matches</span><span class="p">(</span><span class="n">message</span><span class="o">=</span><span class="s">&quot;ut th&quot;</span><span class="p">))</span> <span class="c"># from &quot;But this will&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">assertFalse</span><span class="p">(</span><span class="n">h</span><span class="o">.</span><span class="n">matches</span><span class="p">(</span><span class="n">message</span><span class="o">=</span><span class="s">&quot;either&quot;</span><span class="p">))</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">assertFalse</span><span class="p">(</span><span class="n">h</span><span class="o">.</span><span class="n">matches</span><span class="p">(</span><span class="n">message</span><span class="o">=</span><span class="s">&quot;won&#39;t&quot;</span><span class="p">))</span>

    <span class="k">def</span> <span class="nf">test_multiple</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="s">&quot;Test of matching multiple values in logging test harness.&quot;</span>
        <span class="c"># Just as a demo, let&#39;s log some messages.</span>
        <span class="c"># Only one should show up in the log.</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s">&quot;This won&#39;t show up.&quot;</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s">&quot;Neither will this.&quot;</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">warning</span><span class="p">(</span><span class="s">&quot;But this will.&quot;</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s">&quot;And so will this.&quot;</span><span class="p">)</span>
        <span class="n">h</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">handler</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">assertTrue</span><span class="p">(</span><span class="n">h</span><span class="o">.</span><span class="n">matches</span><span class="p">(</span><span class="n">levelno</span><span class="o">=</span><span class="n">logging</span><span class="o">.</span><span class="n">WARNING</span><span class="p">,</span>
                                  <span class="n">message</span><span class="o">=</span><span class="s">&#39;ut thi&#39;</span><span class="p">))</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">assertTrue</span><span class="p">(</span><span class="n">h</span><span class="o">.</span><span class="n">matches</span><span class="p">(</span><span class="n">levelno</span><span class="o">=</span><span class="n">logging</span><span class="o">.</span><span class="n">ERROR</span><span class="p">,</span>
                                  <span class="n">message</span><span class="o">=</span><span class="s">&#39;nd so wi&#39;</span><span class="p">))</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">assertFalse</span><span class="p">(</span><span class="n">h</span><span class="o">.</span><span class="n">matches</span><span class="p">(</span><span class="n">levelno</span><span class="o">=</span><span class="n">logging</span><span class="o">.</span><span class="n">INFO</span><span class="p">))</span>
</pre></div>
</div>
<span class="target" id="module-logutils.testing"></span><dl class="class">
<dt id="logutils.testing.Matcher">
<em class="property">class </em><tt class="descclassname">logutils.testing.</tt><tt class="descname">Matcher</tt><a class="headerlink" href="#logutils.testing.Matcher" title="Permalink to this definition"></a></dt>
<dd><p>This utility class matches a stored dictionary of
<tt class="xref py py-class docutils literal"><span class="pre">logging.LogRecord</span></tt> attributes with keyword arguments
passed to its <a class="reference internal" href="#logutils.testing.Matcher.matches" title="logutils.testing.Matcher.matches"><tt class="xref py py-meth docutils literal"><span class="pre">matches()</span></tt></a> method.</p>
<dl class="method">
<dt id="logutils.testing.Matcher.match_value">
<tt class="descname">match_value</tt><big>(</big><em>k</em>, <em>dv</em>, <em>v</em><big>)</big><a class="headerlink" href="#logutils.testing.Matcher.match_value" title="Permalink to this definition"></a></dt>
<dd><p>Try to match a single stored value (dv) with a supplied value (v).</p>
<p>Return <cite>True</cite> if found, else <cite>False</cite>.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>k</strong> &#8211; The key value (LogRecord attribute name).</li>
<li><strong>dv</strong> &#8211; The stored value to match against.</li>
<li><strong>v</strong> &#8211; The value to compare with the stored value.</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="method">
<dt id="logutils.testing.Matcher.matches">
<tt class="descname">matches</tt><big>(</big><em>d</em>, <em>**kwargs</em><big>)</big><a class="headerlink" href="#logutils.testing.Matcher.matches" title="Permalink to this definition"></a></dt>
<dd><p>Try to match a single dict with the supplied arguments.</p>
<p>Keys whose values are strings and which are in self._partial_matches
will be checked for partial (i.e. substring) matches. You can extend
this scheme to (for example) do regular expression matching, etc.</p>
<p>Return <cite>True</cite> if found, else <cite>False</cite>.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>kwargs</strong> &#8211; A set of keyword arguments whose names are LogRecord
attributes and whose values are what you want to 
match in a stored LogRecord.</td>
</tr>
</tbody>
</table>
</dd></dl>

</dd></dl>

<dl class="class">
<dt id="logutils.testing.TestHandler">
<em class="property">class </em><tt class="descclassname">logutils.testing.</tt><tt class="descname">TestHandler</tt><big>(</big><em>matcher</em><big>)</big><a class="headerlink" href="#logutils.testing.TestHandler" title="Permalink to this definition"></a></dt>
<dd><p>This handler collects records in a buffer for later inspection by
your unit test code.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>matcher</strong> &#8211; The <a class="reference internal" href="#logutils.testing.Matcher" title="logutils.testing.Matcher"><tt class="xref py py-class docutils literal"><span class="pre">Matcher</span></tt></a> instance to
use for matching.</td>
</tr>
</tbody>
</table>
<dl class="attribute">
<dt id="logutils.testing.TestHandler.count">
<tt class="descname">count</tt><a class="headerlink" href="#logutils.testing.TestHandler.count" title="Permalink to this definition"></a></dt>
<dd><p>The number of records in the buffer.</p>
</dd></dl>

<dl class="method">
<dt id="logutils.testing.TestHandler.emit">
<tt class="descname">emit</tt><big>(</big><em>record</em><big>)</big><a class="headerlink" href="#logutils.testing.TestHandler.emit" title="Permalink to this definition"></a></dt>
<dd><p>Saves the <cite>__dict__</cite> of the record in the <cite>buffer</cite> attribute,
and the formatted records in the <cite>formatted</cite> attribute.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>record</strong> &#8211; The record to emit.</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="method">
<dt id="logutils.testing.TestHandler.flush">
<tt class="descname">flush</tt><big>(</big><big>)</big><a class="headerlink" href="#logutils.testing.TestHandler.flush" title="Permalink to this definition"></a></dt>
<dd><p>Clears out the <cite>buffer</cite> and <cite>formatted</cite> attributes.</p>
</dd></dl>

<dl class="method">
<dt id="logutils.testing.TestHandler.matchall">
<tt class="descname">matchall</tt><big>(</big><em>kwarglist</em><big>)</big><a class="headerlink" href="#logutils.testing.TestHandler.matchall" title="Permalink to this definition"></a></dt>
<dd><p>Accept a list of keyword argument values and ensure that the handler&#8217;s
buffer of stored records matches the list one-for-one.</p>
<p>Return <cite>True</cite> if exactly matched, else <cite>False</cite>.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>kwarglist</strong> &#8211; A list of keyword-argument dictionaries, each of
which will be passed to <a class="reference internal" href="#logutils.testing.TestHandler.matches" title="logutils.testing.TestHandler.matches"><tt class="xref py py-meth docutils literal"><span class="pre">matches()</span></tt></a> with the
corresponding record from the buffer.</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="method">
<dt id="logutils.testing.TestHandler.matches">
<tt class="descname">matches</tt><big>(</big><em>**kwargs</em><big>)</big><a class="headerlink" href="#logutils.testing.TestHandler.matches" title="Permalink to this definition"></a></dt>
<dd><p>Look for a saved dict whose keys/values match the supplied arguments.</p>
<p>Return <cite>True</cite> if found, else <cite>False</cite>.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>kwargs</strong> &#8211; A set of keyword arguments whose names are LogRecord
attributes and whose values are what you want to 
match in a stored LogRecord.</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="method">
<dt id="logutils.testing.TestHandler.shouldFlush">
<tt class="descname">shouldFlush</tt><big>(</big><big>)</big><a class="headerlink" href="#logutils.testing.TestHandler.shouldFlush" title="Permalink to this definition"></a></dt>
<dd><p>Should the buffer be flushed?</p>
<p>This returns <cite>False</cite> - you&#8217;ll need to flush manually, usually after
your unit test code checks the buffer contents against your
expectations.</p>
</dd></dl>

</dd></dl>

</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
  <h4>Previous topic</h4>
  <p class="topless"><a href="redis.html"
                        title="previous chapter">Working with Redis queues</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="dictconfig.html"
                        title="next chapter">Dictionary-based Configuration</a></p>
  <h3>This Page</h3>
  <ul class="this-page-menu">
    <li><a href="_sources/testing.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="py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="dictconfig.html" title="Dictionary-based Configuration"
             >next</a> |</li>
        <li class="right" >
          <a href="redis.html" title="Working with Redis queues"
             >previous</a> |</li>
        <li><a href="index.html">Logutils 0.3.3 documentation</a> &raquo;</li> 
      </ul>
    </div>
    <div class="footer">
        &copy; Copyright 2010-2013, Vinay Sajip.
      Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.2.3.
    </div>
  </body>
</html>