-í
ç¶<c       sÁ  d  Z  d d d d g Z d k Z d k Z d Z d Z e i d e i e ƒ ƒ i Z	 e i d e i e ƒ ƒ i Z
 e i d	 ƒ i Z e i d
 ƒ i Z [ d k l Z d k l Z d k l Z d k l Z d k l Z d „  Z d f  d „  ƒ  YZ d „  Z d „  Z d „  Z d „  Z d d e d „ Z  d „  Z! d „  Z" d f  d „  ƒ  YZ# e a$ e e e e d d „ Z% d f  d  „  ƒ  YZ& h  e& d <d! d" <Z' d# „  Z( e) d$ j o e( ƒ  n d S(%   s!  Module doctest -- a framework for running examples in docstrings.

NORMAL USAGE

In normal use, end each module M with:

def _test():
    import doctest, M           # replace M with your module's name
    return doctest.testmod(M)   # ditto

if __name__ == "__main__":
    _test()

Then running the module as a script will cause the examples in the
docstrings to get executed and verified:

python M.py

This won't display anything unless an example fails, in which case the
failing example(s) and the cause(s) of the failure(s) are printed to stdout
(why not stderr? because stderr is a lame hack <0.2 wink>), and the final
line of output is "Test failed.".

Run it with the -v switch instead:

python M.py -v

and a detailed report of all examples tried is printed to stdout, along
with assorted summaries at the end.

You can force verbose mode by passing "verbose=1" to testmod, or prohibit
it by passing "verbose=0".  In either of those cases, sys.argv is not
examined by testmod.

In any case, testmod returns a 2-tuple of ints (f, t), where f is the
number of docstring examples that failed and t is the total number of
docstring examples attempted.


WHICH DOCSTRINGS ARE EXAMINED?

+ M.__doc__.

+ f.__doc__ for all functions f in M.__dict__.values(), except those
  with private names and those defined in other modules.

+ C.__doc__ for all classes C in M.__dict__.values(), except those with
  private names and those defined in other modules.

+ If M.__test__ exists and "is true", it must be a dict, and
  each entry maps a (string) name to a function object, class object, or
  string.  Function and class object docstrings found from M.__test__
  are searched even if the name is private, and strings are searched
  directly as if they were docstrings.  In output, a key K in M.__test__
  appears with name
      <name of M>.__test__.K

Any classes found are recursively searched similarly, to test docstrings in
their contained methods and nested classes.  Private names reached from M's
globals are skipped, but all names reached from M.__test__ are searched.

By default, a name is considered to be private if it begins with an
underscore (like "_my_func") but doesn't both begin and end with (at least)
two underscores (like "__init__").  You can change the default by passing
your own "isprivate" function to testmod.

If you want to test docstrings in objects with private names too, stuff
them into an M.__test__ dict, or see ADVANCED USAGE below (e.g., pass your
own isprivate function to Tester's constructor, or call the rundoc method
of a Tester instance).

WHAT'S THE EXECUTION CONTEXT?

By default, each time testmod finds a docstring to test, it uses a *copy*
of M's globals (so that running tests on a module doesn't change the
module's real globals, and so that one test in M can't leave behind crumbs
that accidentally allow another test to work).  This means examples can
freely use any names defined at top-level in M.  It also means that sloppy
imports (see above) can cause examples in external docstrings to use
globals inappropriate for them.

You can force use of your own dict as the execution context by passing
"globs=your_dict" to testmod instead.  Presumably this would be a copy of
M.__dict__ merged with the globals from other imported modules.


WHAT IF I WANT TO TEST A WHOLE PACKAGE?

Piece o' cake, provided the modules do their testing from docstrings.
Here's the test.py I use for the world's most elaborate Rational/
floating-base-conversion pkg (which I'll distribute some day):

from Rational import Cvt
from Rational import Format
from Rational import machprec
from Rational import Rat
from Rational import Round
from Rational import utils

modules = (Cvt,
           Format,
           machprec,
           Rat,
           Round,
           utils)

def _test():
    import doctest
    import sys
    verbose = "-v" in sys.argv
    for mod in modules:
        doctest.testmod(mod, verbose=verbose, report=0)
    doctest.master.summarize()

if __name__ == "__main__":
    _test()

IOW, it just runs testmod on all the pkg modules.  testmod remembers the
names and outcomes (# of failures, # of tries) for each item it's seen, and
passing "report=0" prevents it from printing a summary in verbose mode.
Instead, the summary is delayed until all modules have been tested, and
then "doctest.master.summarize()" forces the summary at the end.

So this is very nice in practice:  each module can be tested individually
with almost no work beyond writing up docstring examples, and collections
of modules can be tested too as a unit with no more work than the above.


WHAT ABOUT EXCEPTIONS?

No problem, as long as the only output generated by the example is the
traceback itself.  For example:

    >>> [1, 2, 3].remove(42)
    Traceback (most recent call last):
      File "<stdin>", line 1, in ?
    ValueError: list.remove(x): x not in list
    >>>

Note that only the exception type and value are compared (specifically,
only the last line in the traceback).


ADVANCED USAGE

doctest.testmod() captures the testing policy I find most useful most
often.  You may want other policies.

testmod() actually creates a local instance of class doctest.Tester, runs
appropriate methods of that class, and merges the results into global
Tester instance doctest.master.

You can create your own instances of doctest.Tester, and so build your own
policies, or even run methods of doctest.master directly.  See
doctest.Tester.__doc__ for details.


SO WHAT DOES A DOCSTRING EXAMPLE LOOK LIKE ALREADY!?

Oh ya.  It's easy!  In most cases a copy-and-paste of an interactive
console session works fine -- just make sure the leading whitespace is
rigidly consistent (you can mix tabs and spaces if you're too lazy to do it
right, but doctest is not in the business of guessing what you think a tab
means).

    >>> # comments are ignored
    >>> x = 12
    >>> x
    12
    >>> if x == 13:
    ...     print "yes"
    ... else:
    ...     print "no"
    ...     print "NO"
    ...     print "NO!!!"
    ...
    no
    NO
    NO!!!
    >>>

Any expected output must immediately follow the final ">>>" or "..." line
containing the code, and the expected output (if any) extends to the next
">>>" or all-whitespace line.  That's it.

Bummers:

+ Expected output cannot contain an all-whitespace line, since such a line
  is taken to signal the end of expected output.

+ Output to stdout is captured, but not output to stderr (exception
  tracebacks are captured via a different means).

+ If you continue a line via backslashing in an interactive session, or for
  any other reason use a backslash, you need to double the backslash in the
  docstring version.  This is simply because you're in a string, and so the
  backslash must be escaped for it to survive intact.  Like:

>>> if "yes" == \
...     "y" +   \
...     "es":   # in the source code you'll see the doubled backslashes
...     print 'yes'
yes

The starting column doesn't matter:

>>> assert "Easy!"
     >>> import math
            >>> math.floor(1.9)
            1.0

and as many leading whitespace characters are stripped from the expected
output as appeared in the initial ">>>" line that triggered it.

If you execute this very file, the examples above will be found and
executed, leading to this output in verbose mode:

Running doctest.__doc__
Trying: [1, 2, 3].remove(42)
Expecting:
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
ValueError: list.remove(x): x not in list
ok
Trying: x = 12
Expecting: nothing
ok
Trying: x
Expecting: 12
ok
Trying:
if x == 13:
    print "yes"
else:
    print "no"
    print "NO"
    print "NO!!!"
Expecting:
no
NO
NO!!!
ok
... and a bunch more like that, with this summary at the end:

5 items had no tests:
    doctest.Tester.__init__
    doctest.Tester.run__test__
    doctest.Tester.summarize
    doctest.run_docstring_examples
    doctest.testmod
12 items passed all tests:
   8 tests in doctest
   6 tests in doctest.Tester
  10 tests in doctest.Tester.merge
  14 tests in doctest.Tester.rundict
   3 tests in doctest.Tester.rundoc
   3 tests in doctest.Tester.runstring
   2 tests in doctest.__test__._TestClass
   2 tests in doctest.__test__._TestClass.__init__
   2 tests in doctest.__test__._TestClass.get
   1 tests in doctest.__test__._TestClass.square
   2 tests in doctest.__test__.string
   7 tests in doctest.is_private
60 tests in 17 items.
60 passed and 0 failed.
Test passed.
s   testmods   run_docstring_exampless
   is_privates   TesterNs   >>>s   ...s   (\s*)s   \s*$s   \s*#(   s   StringTypes(   s   isclass(   s
   isfunction(   s   ismodule(   s   classify_class_attrsc    sæ  t  t f \ } } t t f \ } } g  } |  i
 d ƒ } d t | ƒ f \ } } xŠ| | j  o|| | } | d } | | ƒ }
 |
 t j o qT n |
 i d ƒ }	 | | |	 ƒ p | | |	 ƒ o qT n | d } | |	 d j o% t d | d t d | ƒ ‚ n |	 d }	 |
 i d ƒ } t | ƒ } g  } x| d ot | i | |	 ƒ | | } | | ƒ }
 |
 oA |
 i d ƒ | j o t d | d	 | ƒ ‚ n | d } n Pq9Wt | ƒ d j o | d } n0 | d
 d j o | d
 =n d i | ƒ d } | | ƒ p
 | | ƒ o
 d } n› g  } x~ d ov | |  | j o t d | d	 | ƒ ‚ n | i | | ƒ | d } | | } | | ƒ p
 | | ƒ o Pn q2Wd i | ƒ d } | i | | | f ƒ qT W| Sd  S(   Ns   
i    i   s    s   line s     of docstring lacks blank after s   : s(   inconsistent leading whitespace in line s    of docstring: iÿÿÿÿs    (   s   _isPS1s   _isPS2s   isPS1s   isPS2s   _isEmptys
   _isComments   isEmptys	   isComments   exampless   ss   splits   liness   lens   is   ns   lines   ms   Nones   ends   js   linenos
   ValueErrors   PS1s   groups   blankss   nblankss   sources   appends   joins   expect(   s   ss   blankss	   isComments   liness   expects   isPS1s   isPS2s   lines   is   js   ms   ns   sources   isEmptys   linenos   nblankss   examples(    (    s   /usr/lib/python2.2/doctest.pys   _extract_examples3sh     

 
%
 

 


s	   _SpoofOutc      s5   t  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   Nc    s   |  i ƒ  d  S(   N(   s   selfs   clear(   s   self(    (    s   /usr/lib/python2.2/doctest.pys   __init__ss    c    s   |  i i | ƒ d  S(   N(   s   selfs   bufs   appends   s(   s   selfs   s(    (    s   /usr/lib/python2.2/doctest.pys   writeus    c    sZ   d i  |  i ƒ } | o | i d ƒ o | d } n t |  d ƒ o
 |  ` n | Sd  S(   Ns    s   
s	   softspace(   s   joins   selfs   bufs   gutss   endswiths   hasattrs	   softspace(   s   selfs   guts(    (    s   /usr/lib/python2.2/doctest.pys   getws    
c    s'   g  |  _ t |  d ƒ o
 |  ` n d  S(   Ns	   softspace(   s   selfs   bufs   hasattrs	   softspace(   s   self(    (    s   /usr/lib/python2.2/doctest.pys   clearƒs    	c    s   d  S(   N(    (   s   self(    (    s   /usr/lib/python2.2/doctest.pys   flush‡s    (   s   __name__s
   __module__s   __init__s   writes   gets   clears   flush(    (    (    s   /usr/lib/python2.2/doctest.pys	   _SpoofOutrs
   				c    s¼   xµ | D]­ \ } } |  | d ƒ | d d j } | o | i d ƒ t | ƒ d j  } t | ƒ t | ƒ d j  o | o |  d ƒ n |  d ƒ |  | ƒ | o |  d ƒ n q Wd  S(   Ns   :iÿÿÿÿs   
i   iL   s    (   s   tag_msg_pairss   tags   msgs   printers
   msg_has_nls   finds   lens   msg_has_two_nl(   s   printers   tag_msg_pairss   msg_has_two_nls   msgs   tags
   msg_has_nl(    (    s   /usr/lib/python2.2/doctest.pys   _tag_outŽs     &%

c    sL  d  k  } d  k } e d ƒ \ } } } d } e ƒ  } d } xù| D]ñ\ } }	 } | o' e |  d | f d |	 p | f ƒ n | i ƒ  y0 e | d d | d ƒ | U| i ƒ  }
 | } Wn  |	 i d	 ƒ d j p |	 i d
 ƒ d j oM |	 i d ƒ d d }	 | i ƒ  d  \ } } | i | | ƒ d }
 | } n! | i ƒ  | i d | ƒ | } n X| | j o3 |
 |	 j o | o |  d ƒ n qC n | } n | d } |  d d d ƒ e |  d | f ƒ |  d | d | d ƒ | | j o' e |  d |	 p | f d |
 f ƒ n e |  d | i ƒ  f ƒ qC W| e! | ƒ f Sd  S(   Ni   s   nothingi    s   Tryings	   Expectings   <string>s   singlei   s   Traceback (innermost last):
s#   Traceback (most recent call last):
s   
iþÿÿÿi   iÿÿÿÿs   files   ok
s   *iA   s   Failure in examples   from line #s    of s   Expecteds   Gots   Exception raised("   s   syss	   tracebacks   ranges   OKs   BOOMs   FAILs   NADAs	   _SpoofOuts   stderrs   failuress   exampless   sources   wants   linenos   verboses   _tag_outs   outs   fakeouts   clears   compiles   compileflagss   globss   gets   gots   states   finds   splits   exc_infos   exc_types   exc_vals   format_exception_onlys	   print_excs   names   len(   s   outs   fakeouts   exampless   globss   verboses   names   compileflagss   NADAs   syss   wants   gots   FAILs   exc_types   OKs	   tracebacks   states   sources   linenos   stderrs   failuress   exc_vals   BOOM(    (    s   /usr/lib/python2.2/doctest.pys   _run_examples_inner sR    	 

,



 
' c    s[   d } xJ t i D]? } |  i | t ƒ } | t t | ƒ j o | | i	 O} n q W| Sd  S(   Ni    (
   s   flagss
   __future__s   all_feature_namess   fnames   globss   gets   Nones   features   getattrs   compiler_flag(   s   globss   flagss   fnames   feature(    (    s   /usr/lib/python2.2/doctest.pys   _extract_future_flagsØs    
 c 	   sr   d  k  } | i } | i ƒ  } z5 t ƒ  | _ } t | i | |  | | | | ƒ } Wd  | | _ | i ƒ  X| Sd  S(   N(   s   syss   stdouts   saveouts   globss   copys	   _SpoofOuts   fakeouts   _run_examples_inners   writes   exampless   verboses   names   compileflagss   xs   clear(	   s   exampless   globss   verboses   names   compileflagss   syss   fakeouts   xs   saveout(    (    s   /usr/lib/python2.2/doctest.pys   _run_examplesãs    		 		i    s   NoNamec    sœ   y/ |  i } | o d d f Sn t | ƒ } Wn d d f Sn Xt | ƒ } | o d d f Sn | t j o t | ƒ } n t
 | | | | | ƒ Sd S(   s'  f, globs, verbose=0, name="NoName" -> run examples from f.__doc__.

    Use (a shallow copy of) dict globs as the globals for execution.
    Return (#failures, #tries).

    If optional arg verbose is true, print stuff even if there are no
    failures.
    Use string name in failure msgs.
    i    N(   s   fs   __doc__s   docs   strs   _extract_exampless   es   compileflagss   Nones   _extract_future_flagss   globss   _run_exampless   verboses   name(   s   fs   globss   verboses   names   compileflagss   es   doc(    (    s   /usr/lib/python2.2/doctest.pys   run_docstring_examplesøs    
 	c    s9   | d  d j o$ | d  d j o | d j n Sd S(   sÅ  prefix, base -> true iff name prefix + "." + base is "private".

    Prefix may be an empty string, and base does not contain a period.
    Prefix is ignored (although functions you write conforming to this
    protocol may make use of it).
    Return true iff base begins with an (at least one) underscore, but
    does not both begin and end with (at least) two underscores.

    >>> is_private("a.b", "my_func")
    0
    >>> is_private("____", "_my_func")
    1
    >>> is_private("someclass", "__init__")
    0
    >>> is_private("sometypo", "__init_")
    1
    >>> is_private("x.y.z", "_")
    1
    >>> is_private("_x.y.z", "__")
    0
    >>> is_private("", "")  # senseless but consistent
    0
    i   s   _i   s   __iþÿÿÿN(   s   base(   s   prefixs   base(    (    s   /usr/lib/python2.2/doctest.pys
   is_privates     c    sR   t  | ƒ o |  i | i j Sn t | ƒ o |  i | i j Sn t d ƒ ‚ d  S(   Ns"   object must be a class or function(	   s   _isfunctions   objects   modules   __dict__s   func_globalss   _isclasss   __name__s
   __module__s
   ValueError(   s   modules   object(    (    s   /usr/lib/python2.2/doctest.pys   _from_module3s
    c      st   t  Z d  Z e e e e d „ Z d „  Z e d „ Z e d „ Z d „  Z e d „ Z	 d „  Z
 d „  Z d	 „  Z RS(
   s@  Class Tester -- runs docstring examples and accumulates stats.

In normal use, function doctest.testmod() hides all this from you,
so use that if you can.  Create your own instances of Tester to do
fancier things.

Methods:
    runstring(s, name)
        Search string s for examples to run; use name for logging.
        Return (#failures, #tries).

    rundoc(object, name=None)
        Search object.__doc__ for examples to run; use name (or
        object.__name__) for logging.  Return (#failures, #tries).

    rundict(d, name, module=None)
        Search for examples in docstrings in all of d.values(); use name
        for logging.  Exclude functions and classes not defined in module
        if specified.  Return (#failures, #tries).

    run__test__(d, name)
        Treat dict d like module.__test__.  Return (#failures, #tries).

    summarize(verbose=None)
        Display summary of testing results, to stdout.  Return
        (#failures, #tries).

    merge(other)
        Merge in the test results from Tester instance "other".

>>> from doctest import Tester
>>> t = Tester(globs={'x': 42}, verbose=0)
>>> t.runstring(r'''
...      >>> x = x * 2
...      >>> print x
...      42
... ''', 'XYZ')
*****************************************************************
Failure in example: print x
from line #2 of XYZ
Expected: 42
Got: 84
(1, 2)
>>> t.runstring(">>> x = x * 2\n>>> print x\n84\n", 'example2')
(0, 2)
>>> t.summarize()
*****************************************************************
1 items had failures:
   1 of   2 in XYZ
***Test Failed*** 1 failures.
(1, 4)
>>> t.summarize(verbose=1)
1 items passed all tests:
   2 tests in example2
*****************************************************************
1 items had failures:
   1 of   2 in XYZ
4 tests in 2 items.
3 passed and 1 failed.
***Test Failed*** 1 failures.
(1, 4)
>>>
c    së   | t j o
 | t j o t d ƒ ‚ n | t j	 o t | ƒ o t d | ƒ ‚ n | t j o | i } n | |  _ | t j o d k } d | i	 j } n | |  _ | t j o
 t } n | |  _
 h  |  _ t | ƒ |  _ d S(   sç  mod=None, globs=None, verbose=None, isprivate=None

See doctest.__doc__ for an overview.

Optional keyword arg "mod" is a module, whose globals are used for
executing examples.  If not specified, globs must be specified.

Optional keyword arg "globs" gives a dict to be used as the globals
when executing examples; if not specified, use the globals from
module mod.

In either case, a copy of the dict is used for each docstring
examined.

Optional keyword arg "verbose" prints lots of stuff if true, only
failures if false; by default, it's true iff "-v" is in sys.argv.

Optional keyword arg "isprivate" specifies a function used to determine
whether a name is private.  The default function is doctest.is_private;
see its docs for details.
s*   Tester.__init__: must specify mod or globss'   Tester.__init__: mod must be a module; Ns   -v(   s   mods   Nones   globss	   TypeErrors	   _ismodules   __dict__s   selfs   verboses   syss   argvs	   isprivates
   is_privates   name2fts   _extract_future_flagss   compileflags(   s   selfs   mods   globss   verboses	   isprivates   sys(    (    s   /usr/lib/python2.2/doctest.pys   __init__{s"     			
		c    s£   |  i o d G| GHn d } } t | ƒ } | o+ t | |  i	 |  i | |  i
 ƒ \ } } n |  i o | Gd G| Gd G| GHn |  i | | | ƒ | | f Sd S(   si  
        s, name -> search string s for examples to run, logging as name.

        Use string name as the key for logging the outcome.
        Return (#failures, #examples).

        >>> t = Tester(globs={}, verbose=1)
        >>> test = r'''
        ...    # just an example
        ...    >>> x = 1 + 2
        ...    >>> x
        ...    3
        ... '''
        >>> t.runstring(test, "Example")
        Running string Example
        Trying: x = 1 + 2
        Expecting: nothing
        ok
        Trying: x
        Expecting: 3
        ok
        0 of 2 examples failed in string Example
        (0, 2)
        s   Running stringi    s   ofs   examples failed in stringN(   s   selfs   verboses   names   fs   ts   _extract_exampless   ss   es   _run_exampless   globss   compileflagss   _Tester__record_outcome(   s   selfs   ss   names   es   ts   f(    (    s   /usr/lib/python2.2/doctest.pys	   runstring©s     


c    s=  | t j o8 y | i } Wn$ t j
 o t d | ƒ ‚ n Xn |  i o d G| d GHn t | |  i	 |  i | |  i
 ƒ \ } } |  i o | Gd G| Gd G| d GHn |  i | | | ƒ t | ƒ oah  } x(t | ƒ D]\ }
 } } } | | j	 o qá nõ |  i | |
 ƒ o qá nÛ | d j o | | |
 <nÀ | d j o t | |
 ƒ | |
 <nœ | d j o t | |
 ƒ i | |
 <nu | d	 j o+ | i t j	 o t | i ƒ | |
 <n n= | d
 j o t | ƒ o | | |
 <n n t d | ƒ ‚ qá W|  i | | ƒ \ }	 } | |	 7} | | 7} n | | f Sd S(   s#  
        object, name=None -> search object.__doc__ for examples to run.

        Use optional string name as the key for logging the outcome;
        by default use object.__name__.
        Return (#failures, #examples).
        If object is a class object, search recursively for method
        docstrings too.
        object.__doc__ is examined regardless of name, but if object is
        a class, whether private names reached from object are searched
        depends on the constructor's "isprivate" argument.

        >>> t = Tester(globs={}, verbose=0)
        >>> def _f():
        ...     '''Trivial docstring example.
        ...     >>> assert 2 == 2
        ...     '''
        ...     return 32
        ...
        >>> t.rundoc(_f)  # expect 0 failures in 1 example
        (0, 1)
        sF   Tester.rundoc: name must be given when object.__name__ doesn't exist; s   Runnings   .__doc__s   ofs   examples failed ins   methods   static methods   class methods   propertys   datas   teach doctest about %rN(   s   names   Nones   objects   __name__s   AttributeErrors
   ValueErrors   selfs   verboses   run_docstring_exampless   globss   compileflagss   fs   ts   _Tester__record_outcomes   _isclasss   ds   _classify_class_attrss   tags   kinds   homeclss   values	   isprivates   getattrs   im_funcs   __doc__s   strs   run__test__s   f2s   t2(   s   selfs   objects   names   homeclss   ds   fs   t2s   kinds   values   f2s   tags   t(    (    s   /usr/lib/python2.2/doctest.pys   rundocÏsL     

 
c    sà   t  | d ƒ o t d | ƒ ‚ n d } } | i ƒ  }
 |
 i ƒ  x‰ |
 D] }	 | |	 } t
 | ƒ p
 t | ƒ oW | o t | | ƒ o qM n |  i | | d |	 ƒ \ } } | | } | | } n qM W| | f Sd S(   sò  
        d, name, module=None -> search for docstring examples in d.values().

        For k, v in d.items() such that v is a function or class,
        do self.rundoc(v, name + "." + k).  Whether this includes
        objects with private names depends on the constructor's
        "isprivate" argument.  If module is specified, functions and
        classes that are not defined in module are excluded.
        Return aggregate (#failures, #examples).

        Build and populate two modules with sample functions to test that
        exclusion of external functions and classes works.

        >>> import new
        >>> m1 = new.module('_m1')
        >>> m2 = new.module('_m2')
        >>> test_data = """
        ... def _f():
        ...     '''>>> assert 1 == 1
        ...     '''
        ... def g():
        ...    '''>>> assert 2 != 1
        ...    '''
        ... class H:
        ...    '''>>> assert 2 > 1
        ...    '''
        ...    def bar(self):
        ...        '''>>> assert 1 < 2
        ...        '''
        ... """
        >>> exec test_data in m1.__dict__
        >>> exec test_data in m2.__dict__
        >>> m1.__dict__.update({"f2": m2._f, "g2": m2.g, "h2": m2.H})

        Tests that objects outside m1 are excluded:

        >>> t = Tester(globs={}, verbose=0)
        >>> t.rundict(m1.__dict__, "rundict_test", m1)  # _f, f2 and g2 and h2 skipped
        (0, 3)

        Again, but with a custom isprivate function allowing _f:

        >>> t = Tester(globs={}, verbose=0, isprivate=lambda x,y: 0)
        >>> t.rundict(m1.__dict__, "rundict_test_pvt", m1)  # Only f2, g2 and h2 skipped
        (0, 4)

        And once more, not excluding stuff outside m1:

        >>> t = Tester(globs={}, verbose=0, isprivate=lambda x,y: 0)
        >>> t.rundict(m1.__dict__, "rundict_test_pvt")  # None are skipped.
        (0, 8)

        The exclusion of objects from outside the designated module is
        meant to be invoked automagically by testmod.

        >>> testmod(m1)
        (0, 3)

        s   itemss)   Tester.rundict: d must support .items(); i    s   .N(   s   hasattrs   ds	   TypeErrors   fs   ts   keyss   namess   sorts   thisnames   values   _isfunctions   _isclasss   modules   _from_modules   selfs   _Tester__runones   names   f2s   t2(   s   selfs   ds   names   modules   f2s   fs   t2s   values   ts   thisnames   names(    (    s   /usr/lib/python2.2/doctest.pys   rundict$s     ; 

 
 
c    s  d }
 } | d } |  i } zÕ d „  |  _ | i ƒ  } | i	 ƒ  x¬ | D]¤ } | | }	 | | } t |	 ƒ t j o |  i |	 | ƒ \ } } nH t |	 ƒ p
 t |	 ƒ o |  i |	 | ƒ \ } } n t d |	 ƒ ‚ |
 | }
 | | } qI WWd | |  _ X|
 | f Sd S(   s„   d, name -> Treat dict d like module.__test__.

        Return (#failures, #tries).
        See testmod.__doc__ for details.
        i    s   .c     s   d S(   Ni    (    (   s   args(    (    s   /usr/lib/python2.2/doctest.pys   <lambda>~s    sJ   Tester.run__test__: values in dict must be strings, functions or classes; N(   s   failuress   triess   names   prefixs   selfs	   isprivates   savepvts   ds   keyss   sorts   ks   vs   thisnames   types   _StringTypess	   runstrings   fs   ts   _isfunctions   _isclasss   rundocs	   TypeError(   s   selfs   ds   names   savepvts   keyss   fs   prefixs   triess   ts   vs   failuress   thisnames   k(    (    s   /usr/lib/python2.2/doctest.pys   run__test__ss,     

	
 


 
c    s$  | t j o |  i  } n g  } g  } g  } d } }
 xŒ |  i i	 ƒ  D]{ }	 |	 \ } \ } } | | } |
 | }
 | d j o | i | ƒ n2 | d j o | i | | f ƒ n | i |	 ƒ qF W| oŒ | o7 t | ƒ Gd GH| i ƒ  x | D] } d G| GHqó Wn | oC t | ƒ Gd GH| i ƒ  x# | D] \ } } d | | f GHq1Wn n | oU d d GHt | ƒ Gd GH| i ƒ  x, | D]$ \ } \ } } d	 | | | f GHqˆWn | o3 | Gd
 Gt |  i ƒ Gd GH| |
 Gd G|
 Gd GHn |
 o d G|
 Gd GHn | o	 d GHn |
 | f Sd S(   s  
        verbose=None -> summarize results, return (#failures, #tests).

        Print summary of test results to stdout.
        Optional arg 'verbose' controls how wordy this is.  By
        default, use the verbose setting established by the
        constructor.
        i    s   items had no tests:s      s   items passed all tests:s    %3d tests in %ss   *iA   s   items had failures:s    %3d of %3d in %ss   tests ins   items.s
   passed ands   failed.s   ***Test Failed***s	   failures.s   Test passed.N(   s   verboses   Nones   selfs   notestss   passeds   faileds   totalts   totalfs   name2fts   itemss   xs   names   fs   ts   appends   lens   sorts   things   count(   s   selfs   verboses   things   counts   fs   totalts   faileds   ts   passeds   xs   totalfs   notestss   name(    (    s   /usr/lib/python2.2/doctest.pys	   summarize”s\     
  


 
 	
 	c    sˆ   |  i } xx | i i ƒ  D]g \ } \ } } | i | ƒ o5 d | d GH| | \ } } | | } | | } n | | f | | <q Wd S(   s«  
        other -> merge in test results from the other Tester instance.

        If self and other both have a test result for something
        with the same name, the (#failures, #tests) results are
        summed, and a warning is printed to stdout.

        >>> from doctest import Tester
        >>> t1 = Tester(globs={}, verbose=0)
        >>> t1.runstring('''
        ... >>> x = 12
        ... >>> print x
        ... 12
        ... ''', "t1example")
        (0, 2)
        >>>
        >>> t2 = Tester(globs={}, verbose=0)
        >>> t2.runstring('''
        ... >>> x = 13
        ... >>> print x
        ... 13
        ... ''', "t2example")
        (0, 2)
        >>> common = ">>> assert 1 + 2 == 3\n"
        >>> t1.runstring(common, "common")
        (0, 1)
        >>> t2.runstring(common, "common")
        (0, 1)
        >>> t1.merge(t2)
        *** Tester.merge: 'common' in both testers; summing outcomes.
        >>> t1.summarize(1)
        3 items passed all tests:
           2 tests in common
           2 tests in t1example
           2 tests in t2example
        6 tests in 3 items.
        6 passed and 0 failed.
        Test passed.
        (0, 6)
        >>>
        s   *** Tester.merge: 's$   ' in both testers; summing outcomes.N(   s   selfs   name2fts   ds   others   itemss   names   fs   ts   has_keys   f2s   t2(   s   selfs   others   f2s   ts   names   fs   t2s   d(    (    s   /usr/lib/python2.2/doctest.pys   mergeÉs    ) 	 
c    sf   |  i i | ƒ o< d | d Gd GH|  i | \ } } | | } | | } n | | f |  i | <d  S(   Ns   *** Warning: 's   ' was tested before;s   summing outcomes.(   s   selfs   name2fts   has_keys   names   f2s   t2s   fs   t(   s   selfs   names   fs   ts   f2s   t2(    (    s   /usr/lib/python2.2/doctest.pys   __record_outcomeþs    
c    s…   d | j o1 | i d ƒ } | |  | | d f \ } } n d | f \ } } |  i | | ƒ o d d f Sn |  i | | ƒ Sd  S(   Ns   .i   s    i    (	   s   names   rindexs   is   prefixs   bases   selfs	   isprivates   rundocs   target(   s   selfs   targets   names   prefixs   bases   i(    (    s   /usr/lib/python2.2/doctest.pys   __runones    "(   s   __name__s
   __module__s   __doc__s   Nones   __init__s	   runstrings   rundocs   rundicts   run__test__s	   summarizes   merges   _Tester__record_outcomes   _Tester__runone(    (    (    s   /usr/lib/python2.2/doctest.pys   Tester:s   ? .	&UO	!5	5		i   c    sj  t  |  ƒ o t d |  ƒ ‚ n | t j o |  i } n t |  d | d | d | ƒ} | i |  | ƒ \ } }	 | i |  i | |  ƒ \ } }
 | | } |	 |
 }	 t |  d ƒ on |  i } | oZ t | d ƒ o t d | ƒ ‚ n | i | | d ƒ \ } }
 | | } |	 |
 }	 n n | o | i ƒ  n t t j o
 | a n t i | ƒ | |	 f Sd	 S(
   so  m, name=None, globs=None, verbose=None, isprivate=None, report=1

    Test examples in docstrings in functions and classes reachable from
    module m, starting with m.__doc__.  Private names are skipped.

    Also test examples reachable from dict m.__test__ if it exists and is
    not None.  m.__dict__ maps names to functions, classes and strings;
    function and class docstrings are tested even if the name is private;
    strings are tested directly, as if they were docstrings.

    Return (#failures, #tests).

    See doctest.__doc__ for an overview.

    Optional keyword arg "name" gives the name of the module; by default
    use m.__name__.

    Optional keyword arg "globs" gives a dict to be used as the globals
    when executing examples; by default, use m.__dict__.  A copy of this
    dict is actually used for each docstring, so that each docstring's
    examples start with a clean slate.

    Optional keyword arg "verbose" prints lots of stuff if true, prints
    only failures if false; by default, it's true iff "-v" is in sys.argv.

    Optional keyword arg "isprivate" specifies a function used to
    determine whether a name is private.  The default function is
    doctest.is_private; see its docs for details.

    Optional keyword arg "report" prints a summary at the end when true,
    else prints nothing at the end.  In verbose mode, the summary is
    detailed, else very brief (in fact, empty if all tests passed).

    Advanced tomfoolery:  testmod runs methods of a local instance of
    class doctest.Tester, then merges the results into (or creates)
    global Tester instance doctest.master.  Methods of doctest.master
    can be called directly too, if you want to do something unusual.
    Passing report=0 to testmod is especially useful then, to delay
    displaying a summary.  Invoke doctest.master.summarize(verbose)
    when you're done fiddling.
    s   testmod: module required; s   globss   verboses	   isprivates   __test__s   itemss0   testmod: module.__test__ must support .items(); s	   .__test__N(   s	   _ismodules   ms	   TypeErrors   names   Nones   __name__s   Testers   globss   verboses	   isprivates   testers   rundocs   failuress   triess   rundicts   __dict__s   fs   ts   hasattrs   __test__s   testdicts   run__test__s   reports	   summarizes   masters   merge(   s   ms   names   globss   verboses	   isprivates   reports   testdicts   fs   testers   triess   ts   failures(    (    s   /usr/lib/python2.2/doctest.pys   testmods2    *  

	

s
   _TestClassc      s)   t  Z d  Z d „  Z d „  Z d „  Z RS(   så   
    A pointless class, for sanity-checking of docstring testing.

    Methods:
        square()
        get()

    >>> _TestClass(13).get() + _TestClass(-12).get()
    1
    >>> hex(_TestClass(13).square().get())
    '0xa9'
    c    s   | |  _  d S(   sƒ   val -> _TestClass object with associated value val.

        >>> t = _TestClass(123)
        >>> print t.get()
        123
        N(   s   vals   self(   s   selfs   val(    (    s   /usr/lib/python2.2/doctest.pys   __init__is     c    s   |  i d |  _ |  Sd S(   so   square() -> square TestClass's associated value

        >>> _TestClass(13).square().get()
        169
        i   N(   s   selfs   val(   s   self(    (    s   /usr/lib/python2.2/doctest.pys   squaress     c    s   |  i Sd S(   s}   get() -> return TestClass's associated value.

        >>> x = _TestClass(-42)
        >>> print x.get()
        -42
        N(   s   selfs   val(   s   self(    (    s   /usr/lib/python2.2/doctest.pys   get}s     (   s   __name__s
   __module__s   __doc__s   __init__s   squares   get(    (    (    s   /usr/lib/python2.2/doctest.pys
   _TestClass[s    	
	
sÄ   
                      Example of a string object, searched as-is.
                      >>> x = 1; y = 2
                      >>> x + y, x * y
                      (3, 2)
                      s   stringc     s   d  k  }  |  i |  ƒ Sd  S(   N(   s   doctests   testmod(   s   doctest(    (    s   /usr/lib/python2.2/doctest.pys   _tests    	s   __main__(*   s   __doc__s   __all__s
   __future__s   res   PS1s   PS2s   compiles   escapes   matchs   _isPS1s   _isPS2s   _isEmptys
   _isComments   typess   StringTypess   _StringTypess   inspects   isclasss   _isclasss
   isfunctions   _isfunctions   ismodules	   _ismodules   classify_class_attrss   _classify_class_attrss   _extract_exampless	   _SpoofOuts   _tag_outs   _run_examples_inners   _extract_future_flagss   _run_exampless   Nones   run_docstring_exampless
   is_privates   _from_modules   Testers   masters   testmods
   _TestClasss   __test__s   _tests   __name__(   s   _run_examples_inners
   __future__s   _StringTypess   _tag_outs   run_docstring_exampless   _tests	   _SpoofOuts   testmods   PS2s   __test__s   _extract_future_flagss
   _isComments   _isEmptys   PS1s   _from_modules	   _ismodules   _isfunctions
   _TestClasss   _isclasss   __all__s   res   Testers   _run_exampless
   is_privates   _extract_exampless   _isPS2s   _isPS1s   _classify_class_attrs(    (    s   /usr/lib/python2.2/doctest.pys   ?sB   				?		8				ÿ ØH,		