<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    On 24/03/2012 21:00, John MacKenzie wrote:
    <blockquote
cite="mid:CAM1mgc9Msb3KbxraFMVdSV-LidbqhzLiYsA_Tkc0iCrZiuYZXQ@mail.gmail.com"
      type="cite">
      <div><a moz-do-not-send="true"
          href="http://github.com/198d/sclara">http://github.com/198d/sclara</a></div>
      <div><br>
      </div>
      I wrote this library based on a thought I had at the TiP BoF this
      year (hence the name "s(anta)clara"): RSpec for Python (unoriginal
      idea) written entirely with context managers (original idea,
      hopefully). I had been writing Ruby for 3 years up until about
      December of last year and have been writing Python full time since
      then. What I like most about RSpec is the way you define and
      organize tests. You end up grouping similar test cases in a sort
      of hierarchical manner (without resorting to OOP, which I hate the
      most about writing tests with unittest) and get things like
      cumulative setup/teardown from parent contexts while producing an
      english statement that is either true or false after the test is
      run. These are the main ideas I tried to capture with sclara.
      Context mangers, at first glance kind of make sense; if you make a
      quick sketch of what this might look like, you get something like
      this:
      <div>
        <br>
      </div>
      <div>with description('Our object under test'):</div>
      <div>&nbsp; with test('does something'):</div>
      <div>&nbsp; &nbsp; assert True</div>
      <div>&nbsp; with test('does something else'):</div>
      <div>&nbsp; &nbsp; assert True</div>
      <div>&nbsp; with description('when some condition is met'):</div>
      <div>&nbsp; &nbsp; with test('acts a specific way'):</div>
      <div>&nbsp; &nbsp; &nbsp; assert True</div>
      <div><br>
      </div>
      <div>Production test cases that read:</div>
      <div><br>
      </div>
      <div>Our object under test does something.</div>
      <div>Our object under test does something else.</div>
      <div>Our object when some condition is met acts a specific way.</div>
      <div><br>
      </div>
      <div>It gets a bit more complicated once you remember how context
        managers actually work (e.g. delayed execution). My answers to a
        lot of the questions that will arise when you start thinking
        about how you'd actually implement this are greenlets and AST
        manipulation. Check out sclara.runner and sclara.builder for the
        more interesting parts. You can run the examples like so (from
        the root of the project):</div>
      <div><br>
      </div>
      <div>$ PYTHONPATH=. python examples/test_sclara.py</div>
      <div>$ PYTHONPATH=. python sclara/plugin.py
        examples/test_simple.py</div>
      <div><br>
      </div>
      <div>There are failures in both as a demonstration of how this
        interacts with a TestRunner. The first one proves mainly that
        this is just Python; if you use one of the provided runners you
        can execute your test files with the Python interpreter (a big
        goal after looking at a tool like komira for this sort of
        thing). The latter demonstrates that a nose plugin is possible
        and probably implies that a py.test plugin is doable to.&nbsp;</div>
      <div><br>
      </div>
      <div>Beyond sclara, I'm considering the idea that, more than a
        testing framework, I stumbled on an interesting pattern for
        building generic DSLs in Python (more on this soon, hopefully).</div>
      <div><br>
      </div>
      <div>Thoughts?</div>
      <div><br>
      </div>
      <div>(I just realized I should start a blog or something...haha)</div>
    </blockquote>
    <br>
    <br>
    Interesting we had a discussion about a theoretical tool similar to
    this a while back. Here's my post with my suggested syntax (that I
    never got round to implementing - so kudos to you for doing it):<br>
    <br>
    &nbsp;&nbsp;&nbsp;
    <a class="moz-txt-link-freetext" href="http://permalink.gmane.org/gmane.comp.python.testing.general/3740">http://permalink.gmane.org/gmane.comp.python.testing.general/3740</a><br>
    <br>
    All the best,<br>
    <br>
    Michael<br>
    <blockquote
cite="mid:CAM1mgc9Msb3KbxraFMVdSV-LidbqhzLiYsA_Tkc0iCrZiuYZXQ@mail.gmail.com"
      type="cite">
      <div><br>
      </div>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <br>
      <pre wrap="">_______________________________________________
testing-in-python mailing list
<a class="moz-txt-link-abbreviated" href="mailto:testing-in-python@lists.idyll.org">testing-in-python@lists.idyll.org</a>
<a class="moz-txt-link-freetext" href="http://lists.idyll.org/listinfo/testing-in-python">http://lists.idyll.org/listinfo/testing-in-python</a>
</pre>
    </blockquote>
    <br>
    <br>
    <pre class="moz-signature" cols="72">-- 
<a class="moz-txt-link-freetext" href="http://www.voidspace.org.uk/">http://www.voidspace.org.uk/</a>

May you do good and not evil
May you find forgiveness for yourself and forgive others
May you share freely, never taking more than you give.
-- the sqlite blessing <a class="moz-txt-link-freetext" href="http://www.sqlite.org/different.html">http://www.sqlite.org/different.html</a>
</pre>
  </body>
</html>