Sophie

Sophie

distrib > Fedora > 13 > x86_64 > by-pkgid > 552d72b401c5b4a5a4c52922e7b31f2c > files > 95

python-eventlet-doc-0.9.12-1.fc13.noarch.rpm

<!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 &mdash; Eventlet v0.9.12 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.9.12',
        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="Eventlet v0.9.12 documentation" href="index.html" />
    <link rel="next" title="Environment Variables" href="environment.html" />
    <link rel="prev" title="Understanding Eventlet Hubs" href="hubs.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="modindex.html" title="Global Module Index"
             accesskey="M">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><a href="index.html">Eventlet v0.9.12 documentation</a> &raquo;</li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <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 class="nv">$ </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 class="nv">$ </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 class="nv">$ </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 Twisted-specific functionality when Twisted is not installed.  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="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">If running Python version 2.4, use this command instead: <tt class="docutils literal"><span class="pre">python</span> <span class="pre">tests/nosewrapper.py</span></tt>.  There are several tests which make use of the <cite>with</cite> statement and therefore will cause nose grief when it tries to import them; nosewrapper.py excludes these tests so they are skipped.</p>
</div>
<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 class="nv">$ </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 for 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 class="nv">$ </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 <tt class="docutils literal"><span class="pre">EVENTLET_HUB</span></tt> environment variable.</p>
<div class="highlight-sh"><div class="highlight"><pre><span class="nv">$ EVENTLET_HUB</span><span class="o">=</span>epolls nosetests
</pre></div>
</div>
<p>See <a class="reference external" href="hubs.html#understanding-hubs"><em>Understanding Eventlet Hubs</em></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-python"><div class="highlight"><pre><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="s">&#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="s">&#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>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 <tt class="docutils literal"><span class="pre">--cover-inclusive</span></tt> 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 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>coverage html -d cover --omit<span class="o">=</span><span class="s1">&#39;tempmod,&lt;console&gt;,tests&#39;</span>
</pre></div>
</div>
<p>(<tt class="docutils literal"><span class="pre">tempmod</span></tt> and <tt class="docutils literal"><span class="pre">console</span></tt> are omitted because they gets 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">
        <div class="sphinxsidebarwrapper">
            <h3><a href="index.html">Table Of Contents</a></h3>
            <ul>
<li><a class="reference external" href="#">Testing Eventlet</a><ul>
<li><a class="reference external" href="#doctests">Doctests</a></li>
<li><a class="reference external" href="#standard-library-tests">Standard Library Tests</a></li>
<li><a class="reference external" href="#testing-eventlet-hubs">Testing Eventlet Hubs</a></li>
<li><a class="reference external" href="#writing-tests">Writing Tests</a></li>
<li><a class="reference external" 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>
            <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" 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="modindex.html" title="Global 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><a href="index.html">Eventlet v0.9.12 documentation</a> &raquo;</li> 
      </ul>
    </div>
    <div class="footer">
      &copy; Copyright 2005-2010, Eventlet Contributors.
      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 0.6.6.
    </div>
  </body>
</html>