deb-python-eventlet/doc/testing.html

203 lines
12 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>Testing Eventlet &#8212; Eventlet 0.21.0 documentation</title>
<link rel="stylesheet" href="_static/classic.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.21.0',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true,
SOURCELINK_SUFFIX: '.txt'
};
</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="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
<link rel="next" title="Environment Variables" href="environment.html" />
<link rel="prev" title="Understanding Eventlet Hubs" href="hubs.html" />
</head>
<body role="document">
<div class="related" role="navigation" aria-label="related navigation">
<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="environment.html" title="Environment Variables"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="hubs.html" title="Understanding Eventlet Hubs"
accesskey="P">previous</a> |</li>
<li class="nav-item nav-item-0"><a href="index.html">Eventlet 0.21.0 documentation</a> &#187;</li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<div class="section" id="testing-eventlet">
<h1>Testing Eventlet<a class="headerlink" href="#testing-eventlet" title="Permalink to this headline"></a></h1>
<p>Eventlet is tested using <a class="reference external" href="http://somethingaboutorange.com/mrl/projects/nose/">Nose</a>. To run tests, simply install nose, and then, in the eventlet tree, do:</p>
<div class="highlight-sh"><div class="highlight"><pre><span></span>$ python setup.py <span class="nb">test</span>
</pre></div>
</div>
<p>If you want access to all the nose plugins via command line, you can run:</p>
<div class="highlight-sh"><div class="highlight"><pre><span></span>$ python setup.py nosetests
</pre></div>
</div>
<p>Lastly, you can just use nose directly if you want:</p>
<div class="highlight-sh"><div class="highlight"><pre><span></span>$ nosetests
</pre></div>
</div>
<p>That&#8217;s it! The output from running nose is the same as unittest&#8217;s output, if the entire directory was one big test file.</p>
<p>Many tests are skipped based on environmental factors; for example, it makes no sense to test kqueue-specific functionality when your OS does not support it. These are printed as S&#8217;s during execution, and in the summary printed after the tests run it will tell you how many were skipped.</p>
<div class="section" id="doctests">
<h2>Doctests<a class="headerlink" href="#doctests" title="Permalink to this headline"></a></h2>
<p>To run the doctests included in many of the eventlet modules, use this command:</p>
<div class="highlight-sh"><div class="highlight"><pre><span></span>$ nosetests --with-doctest eventlet/*.py
</pre></div>
</div>
<p>Currently there are 16 doctests.</p>
</div>
<div class="section" id="standard-library-tests">
<h2>Standard Library Tests<a class="headerlink" href="#standard-library-tests" title="Permalink to this headline"></a></h2>
<p>Eventlet provides the ability to test itself with the standard Python networking tests. This verifies that the libraries it wraps work at least as well as the standard ones do. The directory tests/stdlib contains a bunch of stubs that import the standard lib tests from your system and run them. If you do not have any tests in your python distribution, they&#8217;ll simply fail to import.</p>
<p>There&#8217;s a convenience module called all.py designed to handle the impedance mismatch between Nose and the standard tests:</p>
<div class="highlight-sh"><div class="highlight"><pre><span></span>$ nosetests tests/stdlib/all.py
</pre></div>
</div>
<p>That will run all the tests, though the output will be a little weird because it will look like Nose is running about 20 tests, each of which consists of a bunch of sub-tests. Not all test modules are present in all versions of Python, so there will be an occasional printout of &#8220;Not importing %s, it doesn&#8217;t exist in this installation/version of Python&#8221;.</p>
<p>If you see &#8220;Ran 0 tests in 0.001s&#8221;, it means that your Python installation lacks its own tests. This is usually the case for Linux distributions. One way to get the missing tests is to download a source tarball (of the same version you have installed on your system!) and copy its Lib/test directory into the correct place on your PYTHONPATH.</p>
</div>
<div class="section" id="testing-eventlet-hubs">
<h2>Testing Eventlet Hubs<a class="headerlink" href="#testing-eventlet-hubs" title="Permalink to this headline"></a></h2>
<p>When you run the tests, Eventlet will use the most appropriate hub for the current platform to do its dispatch. It&#8217;s sometimes useful when making changes to Eventlet to test those changes on hubs other than the default. You can do this with the <code class="docutils literal"><span class="pre">EVENTLET_HUB</span></code> environment variable.</p>
<div class="highlight-sh"><div class="highlight"><pre><span></span>$ <span class="nv">EVENTLET_HUB</span><span class="o">=</span>epolls nosetests
</pre></div>
</div>
<p>See <a class="reference internal" href="hubs.html#understanding-hubs"><span class="std std-ref">Understanding Eventlet Hubs</span></a> for the full list of hubs.</p>
</div>
<div class="section" id="writing-tests">
<h2>Writing Tests<a class="headerlink" href="#writing-tests" title="Permalink to this headline"></a></h2>
<p>What follows are some notes on writing tests, in no particular order.</p>
<p>The filename convention when writing a test for module <cite>foo</cite> is to name the test <cite>foo_test.py</cite>. We don&#8217;t yet have a convention for tests that are of finer granularity, but a sensible one might be <cite>foo_class_test.py</cite>.</p>
<p>If you are writing a test that involves a client connecting to a spawned server, it is best to not use a hardcoded port because that makes it harder to parallelize tests. Instead bind the server to 0, and then look up its port when connecting the client, like this:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">server_sock</span> <span class="o">=</span> <span class="n">eventlet</span><span class="o">.</span><span class="n">listener</span><span class="p">((</span><span class="s1">&#39;127.0.0.1&#39;</span><span class="p">,</span> <span class="mi">0</span><span class="p">))</span>
<span class="n">client_sock</span> <span class="o">=</span> <span class="n">eventlet</span><span class="o">.</span><span class="n">connect</span><span class="p">((</span><span class="s1">&#39;localhost&#39;</span><span class="p">,</span> <span class="n">server_sock</span><span class="o">.</span><span class="n">getsockname</span><span class="p">()[</span><span class="mi">1</span><span class="p">]))</span>
</pre></div>
</div>
</div>
<div class="section" id="coverage">
<h2>Coverage<a class="headerlink" href="#coverage" title="Permalink to this headline"></a></h2>
<p>Coverage.py is an awesome tool for evaluating how much code was exercised by unit tests. Nose supports it if both are installed, so it&#8217;s easy to generate coverage reports for eventlet. Here&#8217;s how:</p>
<div class="highlight-sh"><div class="highlight"><pre><span></span>nosetests --with-coverage --cover-package<span class="o">=</span>eventlet
</pre></div>
</div>
<p>After running the tests to completion, this will emit a huge wodge of module names and line numbers. For some reason, the <code class="docutils literal"><span class="pre">--cover-inclusive</span></code> option breaks everything rather than serving its purpose of limiting the coverage to the local files, so don&#8217;t use that.</p>
<p>The html option is quite useful because it generates nicely-formatted HTML files that are much easier to read than line-number soup. Here&#8217;s a command that generates the annotation, dumping the html files into a directory called &#8220;cover&#8221;:</p>
<div class="highlight-sh"><div class="highlight"><pre><span></span>coverage html -d cover --omit<span class="o">=</span><span class="s1">&#39;tempmod,&lt;console&gt;,tests&#39;</span>
</pre></div>
</div>
<p>(<code class="docutils literal"><span class="pre">tempmod</span></code> and <code class="docutils literal"><span class="pre">console</span></code> are omitted because they get thrown away at the completion of their unit tests and coverage.py isn&#8217;t smart enough to detect this.)</p>
</div>
</div>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<h3><a href="index.html">Table Of Contents</a></h3>
<ul>
<li><a class="reference internal" href="#">Testing Eventlet</a><ul>
<li><a class="reference internal" href="#doctests">Doctests</a></li>
<li><a class="reference internal" href="#standard-library-tests">Standard Library Tests</a></li>
<li><a class="reference internal" href="#testing-eventlet-hubs">Testing Eventlet Hubs</a></li>
<li><a class="reference internal" href="#writing-tests">Writing Tests</a></li>
<li><a class="reference internal" href="#coverage">Coverage</a></li>
</ul>
</li>
</ul>
<h4>Previous topic</h4>
<p class="topless"><a href="hubs.html"
title="previous chapter">Understanding Eventlet Hubs</a></p>
<h4>Next topic</h4>
<p class="topless"><a href="environment.html"
title="next chapter">Environment Variables</a></p>
<div role="note" aria-label="source link">
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="_sources/testing.rst.txt"
rel="nofollow">Show Source</a></li>
</ul>
</div>
<div id="searchbox" style="display: none" role="search">
<h3>Quick search</h3>
<form class="search" action="search.html" method="get">
<div><input type="text" name="q" /></div>
<div><input type="submit" value="Go" /></div>
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="related navigation">
<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="environment.html" title="Environment Variables"
>next</a> |</li>
<li class="right" >
<a href="hubs.html" title="Understanding Eventlet Hubs"
>previous</a> |</li>
<li class="nav-item nav-item-0"><a href="index.html">Eventlet 0.21.0 documentation</a> &#187;</li>
</ul>
</div>
<div class="footer" role="contentinfo">
&#169; Copyright 2005-2010, Eventlet Contributors.
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.5.
</div>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-42952223-1', 'eventlet.net');
ga('send', 'pageview');
</script>
</body>
</html>