[Python-checkins] python/dist/src/Lib doctest.py,1.29,1.30

rhettinger@users.sourceforge.net rhettinger@users.sourceforge.net
Wed, 16 Jul 2003 12:25:24 -0700


Update of /cvsroot/python/python/dist/src/Lib
In directory sc8-pr-cvs1:/tmp/cvs-serv32010/Lib

Modified Files:
	doctest.py 
Log Message:
Doctest now examines all docstrings by default.  Previously, it would
skip over functions with private names (as indicated by the underscore
naming convention).  The old default created too much of a risk that
user tests were being skipped inadvertently.  Note, this change could
break code in the unlikely case that someone had intentionally put
failing tests in the docstrings of private functions.  The breakage
is easily fixable by specifying the old behavior when calling testmod()
or Tester().  The more likely case is that the silent failure was 
unintended and that the user needed to be informed so the test could be
fixed.



Index: doctest.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/doctest.py,v
retrieving revision 1.29
retrieving revision 1.30
diff -C2 -d -r1.29 -r1.30
*** doctest.py	11 Jul 2003 22:36:52 -0000	1.29
--- doctest.py	16 Jul 2003 19:25:22 -0000	1.30
***************
*** 49,56 ****
  
  + 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
--- 49,56 ----
  
  + f.__doc__ for all functions f in M.__dict__.values(), except those
!   defined in other modules.
  
! + C.__doc__ for all classes C in M.__dict__.values(), except those
!   defined in other modules.
  
  + If M.__test__ exists and "is true", it must be a dict, and
***************
*** 63,73 ****
  
  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
--- 63,76 ----
  
  Any classes found are recursively searched similarly, to test docstrings in
! their contained methods and nested classes.  All names reached from
! M.__test__ are searched.
  
! Optionally, functions with private names can be skipped (unless listed in
! M.__test__) by supplying a function to the "isprivate" argument that will
! identify private functions.  For convenience, one such function is
! supplied.  docttest.is_private considers a name 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__").  By supplying this function
! or your own "isprivate" function to testmod, the behavior can be customized.
  
  If you want to test docstrings in objects with private names too, stuff
***************
*** 672,677 ****
  
  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.
  
  See doctest.testmod docs for the meaning of optionflags.
--- 675,682 ----
  
  Optional keyword arg "isprivate" specifies a function used to determine
! whether a name is private.  The default function is to assume that
! no functions are private.  The "isprivate" arg may be set to
! doctest.is_private in order to skip over functions marked as private
! using an underscore naming convention; see its docs for details.
  
  See doctest.testmod docs for the meaning of optionflags.
***************
*** 692,697 ****
          self.verbose = verbose
  
          if isprivate is None:
!             isprivate = is_private
          self.isprivate = isprivate
  
--- 697,703 ----
          self.verbose = verbose
  
+         # By default, assume that nothing is private
          if isprivate is None:
!             isprivate = lambda prefix, base:  0
          self.isprivate = isprivate
  
***************
*** 862,872 ****
          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)
--- 868,878 ----
          Tests that objects outside m1 are excluded:
  
!         >>> t = Tester(globs={}, verbose=0, isprivate=is_private)
          >>> t.rundict(m1.__dict__, "rundict_test", m1)  # _f, f2 and g2 and h2 skipped
          (0, 3)
  
!         Again, but with the default isprivate function allowing _f:
  
!         >>> t = Tester(globs={}, verbose=0)
          >>> t.rundict(m1.__dict__, "rundict_test_pvt", m1)  # Only f2, g2 and h2 skipped
          (0, 4)
***************
*** 874,878 ****
          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)
--- 880,884 ----
          And once more, not excluding stuff outside m1:
  
!         >>> t = Tester(globs={}, verbose=0)
          >>> t.rundict(m1.__dict__, "rundict_test_pvt")  # None are skipped.
          (0, 8)
***************
*** 881,885 ****
          meant to be invoked automagically by testmod.
  
!         >>> testmod(m1)
          (0, 3)
  
--- 887,891 ----
          meant to be invoked automagically by testmod.
  
!         >>> testmod(m1, isprivate=is_private)
          (0, 3)
  
***************
*** 1071,1075 ****
      Test examples in docstrings in functions and classes reachable
      from module m (or the current module if m is not supplied), starting
!     with m.__doc__.  Private names are skipped.
  
      Also test examples reachable from dict m.__test__ if it exists and is
--- 1077,1082 ----
      Test examples in docstrings in functions and classes reachable
      from module m (or the current module if m is not supplied), starting
!     with m.__doc__.  Unless isprivate is specified, private names
!     are not skipped.
  
      Also test examples reachable from dict m.__test__ if it exists and is
***************
*** 1095,1099 ****
      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,
--- 1102,1108 ----
      Optional keyword arg "isprivate" specifies a function used to
      determine whether a name is private.  The default function is
!     treat all functions as public.  Optionally, "isprivate" can be
!     set to doctest.is_private to skip over functions marked as private
!     using the underscore naming convention; see its docs for details.
  
      Optional keyword arg "report" prints a summary at the end when true,