<p dir="ltr">I did quite a lot of testing for my book about testing. If you&#39;re looking for inspiration for future features, the code is at:</p>
<p dir="ltr"><a href="https://github.com/hjwp/Book-TDD-Web-Dev-Python/tree/master/tests">https://github.com/hjwp/Book-TDD-Web-Dev-Python/tree/master/tests</a></p>
<p dir="ltr">I wanted to be able to:</p>
<p dir="ltr">- parse listings and incomplete listings<br>
- handle state including multiple files, including non-python code<br>
- check that arbitrary terminal commands, if executed in the cumulative context of the listings so far, actually produce the output the book says they do (tests and their tracebacks mostly)</p>
<p dir="ltr">I ended up with something that may be a little too specific to my use case, and a little overengineered, and spaghetti code full of the vestiges of abandoned dead end approached.  A brief attempt to roll my own textwrap.textwrap for example.</p>
<p dir="ltr">But still, end results are there. And of course yes there are tests for the tests of the tests in the testing book.</p>
<p dir="ltr">Happy to talk anyone through any of the code if it&#39;s of interest.</p>
<p dir="ltr">Otherwise please just pat me on the back and tell me how smart I am?  ;-)<br>
HP</p>
<br><div class="gmail_quote"><div dir="ltr">On Fri, 26 May 2017, 08:43 Chris Withers, &lt;<a href="mailto:chris@withers.org">chris@withers.org</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi All,<br>
<br>
I&#39;m pleased to announce the first release of Sybil, a library to help<br>
you test the examples in your documents.<br>
<br>
For example, given the following Sphinx source file:<br>
<br>
     Sample Documentation<br>
     ====================<br>
<br>
     Let&#39;s put something in the Sybil document&#39;s namespace:<br>
<br>
     .. invisible-code-block: python<br>
<br>
       remember_me = b&#39;see how namespaces work?&#39;<br>
<br>
     Suppose we define a function, convoluted and pointless but shows<br>
     stuff nicely:<br>
<br>
     .. code-block:: python<br>
<br>
       import sys<br>
<br>
       def prefix_and_print(message):<br>
           print(&#39;prefix:&#39;, message.decode(&#39;ascii&#39;))<br>
<br>
     Now we can use a doctest REPL to show it in action:<br>
<br>
     &gt;&gt;&gt; prefix_and_print(remember_me)<br>
     prefix: see how namespaces work?<br>
<br>
     The namespace carries across from example to example, no matter<br>
     what parser:<br>
<br>
     &gt;&gt;&gt; remember_me<br>
     b&#39;see how namespaces work?&#39;<br>
<br>
<br>
All the examples can be tested when using pytest by putting the<br>
following in a conftest.py in your Sphinx source directory:<br>
<br>
from doctest import ELLIPSIS<br>
from sybil import Sybil<br>
from sybil.parsers.codeblock import CodeBlockParser<br>
from sybil.parsers.doctest import DocTestParser, FIX_BYTE_UNICODE_REPR<br>
<br>
pytest_collect_file = Sybil(<br>
     parsers=[<br>
         DocTestParser(optionflags=ELLIPSIS|FIX_BYTE_UNICODE_REPR),<br>
         CodeBlockParser(future_imports=[&#39;print_function&#39;]),<br>
     ],<br>
     pattern=&#39;*.rst&#39;,<br>
).pytest()<br>
<br>
The package is on PyPI and a full list of all the links to docs, issue<br>
trackers and the like can be found here:<br>
<br>
<a href="https://github.com/cjw96/sybil" rel="noreferrer" target="_blank">https://github.com/cjw96/sybil</a><br>
<br>
Any questions, please do ask on the Testing in Python list or on the<br>
Simplistix open source mailing list...<br>
<br>
cheers,<br>
<br>
Chris<br>
<br>
PS: The name comes from Fawlty Towers, as this package is heavily<br>
inspired by Benji York&#39;s fantastic Manuel package, which also took it&#39;s<br>
name from the series!<br>
<br>
_______________________________________________<br>
testing-in-python mailing list<br>
<a href="mailto:testing-in-python@lists.idyll.org" target="_blank">testing-in-python@lists.idyll.org</a><br>
<a href="http://lists.idyll.org/listinfo/testing-in-python" rel="noreferrer" target="_blank">http://lists.idyll.org/listinfo/testing-in-python</a><br>
</blockquote></div><div dir="ltr">-- <br></div><div data-smartmail="gmail_signature"><div dir="ltr"><p dir="ltr">--<br>
Harry Percival<br>
+44 78877 02511</p>
</div></div>