[Python-checkins] CVS: python/dist/src/Lib doctest.py,1.19,1.20
Tim Peters
tim_one@users.sourceforge.net
Tue, 02 Oct 2001 21:08:28 -0700
Update of /cvsroot/python/python/dist/src/Lib
In directory usw-pr-cvs1:/tmp/cvs-serv14897/python/Lib
Modified Files:
doctest.py
Log Message:
SF bug [#467336] doctest failures w/ new-style classes.
Taught doctest about static methods, class methods, and property docstrings
in new-style classes. As for inspect.py/pydoc.py before it, the new stuff
needed didn't really fit into the old architecture (but was less of a
strain to force-fit here).
New-style class docstrings still aren't found, but that's the subject
of a different bug and I want to fix that right instead of hacking around
it in doctest.
Index: doctest.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/doctest.py,v
retrieving revision 1.19
retrieving revision 1.20
diff -C2 -d -r1.19 -r1.20
*** doctest.py 2001/10/02 22:47:08 1.19
--- doctest.py 2001/10/03 04:08:26 1.20
***************
*** 259,263 ****
6 tests in doctest.Tester
10 tests in doctest.Tester.merge
! 7 tests in doctest.Tester.rundict
3 tests in doctest.Tester.rundoc
3 tests in doctest.Tester.runstring
--- 259,263 ----
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
***************
*** 268,273 ****
2 tests in doctest.__test__.string
7 tests in doctest.is_private
! 53 tests in 17 items.
! 53 passed and 0 failed.
Test passed.
"""
--- 268,273 ----
2 tests in doctest.__test__.string
7 tests in doctest.is_private
! 60 tests in 17 items.
! 60 passed and 0 failed.
Test passed.
"""
***************
*** 296,299 ****
--- 296,300 ----
from inspect import isfunction as _isfunction
from inspect import ismodule as _ismodule
+ from inspect import classify_class_attrs as _classify_class_attrs
# Extract interactive examples from a string. Return a list of triples,
***************
*** 748,754 ****
self.__record_outcome(name, f, t)
if _isclass(object):
! f2, t2 = self.rundict(object.__dict__, name)
! f = f + f2
! t = t + t2
return f, t
--- 749,797 ----
self.__record_outcome(name, f, t)
if _isclass(object):
! # In 2.2, class and static methods complicate life. Build
! # a dict "that works", by hook or by crook.
! d = {}
! for tag, kind, homecls, value in _classify_class_attrs(object):
!
! if homecls is not object:
! # Only look at names defined immediately by the class.
! continue
!
! elif self.isprivate(name, tag):
! continue
!
! elif kind == "method":
! # value is already a function
! d[tag] = value
!
! elif kind == "static method":
! # value isn't a function, but getattr reveals one
! d[tag] = getattr(object, tag)
!
! elif kind == "class method":
! # Hmm. A classmethod object doesn't seem to reveal
! # enough. But getattr turns it into a bound method,
! # and from there .im_func retrieves the underlying
! # function.
! d[tag] = getattr(object, tag).im_func
!
! elif kind == "property":
! # The methods implementing the property have their
! # own docstrings -- but the property may have one too.
! if value.__doc__ is not None:
! d[tag] = str(value.__doc__)
!
! elif kind == "data":
! # Grab nested classes.
! if _isclass(value):
! d[tag] = value
!
! else:
! raise ValueError("teach doctest about %r" % kind)
!
! f2, t2 = self.run__test__(d, name)
! f += f2
! t += t2
!
return f, t