[FRPythoneers] Doctest

Sean Reifschneider jafo at tummy.com
Wed Jul 25 19:49:38 MDT 2001

On Wed, Jul 25, 2001 at 05:33:50PM -0600, Quent wrote:
>How does it handle testing functions that return things like objects
>or values that can't be easily represented as text in a comment?

Well, it repr()s whatever it gets, I would presume.  For example:

   Failure in example: socket.socket(socket.AF_INET, socket.SOCK_STREAM)
   from line #2 of dt.t2
   Expected: <socket object, fd=4, family=2, type=1, protocol=0>
   Got: <socket object, fd=3, family=2, type=1, protocol=0>
   1 items had failures:
      1 of   2 in dt.t2
   ***Test Failed*** 1 failures.

So, if simply a repr() is not acceptable, you'd better have it print
something else.  You could do something like:

   >>> s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
   >>> type(s)
   <type 'socket'>

So, it's not the right tool for every testing job, but for things where you
have a function and you want to make sure that the results are as you
expect, it's ideal.  Exactly what I wanted for the function that did RPM
version string comparisons (you should see some of the version strings it
has to compare).

 This mountain is PURE SNOW!  Do you know what the street value of this
 mountain is!?!                -- Better Off Dead
Sean Reifschneider, Inimitably Superfluous <jafo at tummy.com>
tummy.com - Linux Consulting since 1995. Qmail, KRUD, Firewalls, Python

More information about the FRPythoneers mailing list