[Python-checkins] CVS: python/dist/src/Lib/test test_doctest2.py,NONE,1.1 test_pyclbr.py,1.5,1.6 test_support.py,1.37,1.38

Tim Peters tim_one@users.sourceforge.net
2001年10月02日 21:08:28 -0700


Update of /cvsroot/python/python/dist/src/Lib/test
In directory usw-pr-cvs1:/tmp/cvs-serv14897/python/Lib/test
Modified Files:
	test_pyclbr.py test_support.py 
Added Files:
	test_doctest2.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.
--- NEW FILE: test_doctest2.py ---
"""A module to test whether doctest recognizes some 2.2 features,
like static and class methods.
>>> print 'yup' # 1
yup
"""
import test_support
# XXX The class docstring is skipped.
class C(object):
 """Class C.
 >>> print C() # 2
 42
 """
 def __init__(self):
 """C.__init__.
 >>> print C() # 3
 42
 """
 def __str__(self):
 """
 >>> print C() # 4
 42
 """
 return "42"
 # XXX The class docstring is skipped.
 class D(object):
 """A nested D class.
 >>> print "In D!" # 5
 In D!
 """
 def nested(self):
 """
 >>> print 3 # 6
 3
 """
 def getx(self):
 """
 >>> c = C() # 7
 >>> c.x = 12 # 8
 >>> print c.x # 9
 -12
 """
 return -self._x
 def setx(self, value):
 """
 >>> c = C() # 10
 >>> c.x = 12 # 11
 >>> print c.x # 12
 -12
 """
 self._x = value
 x = property(getx, setx, doc="""\
 >>> c = C() # 13
 >>> c.x = 12 # 14
 >>> print c.x # 15
 -12
 """)
 def statm():
 """
 A static method.
 >>> print C.statm() # 16
 666
 >>> print C().statm() # 17
 666
 """
 return 666
 statm = staticmethod(statm)
 def clsm(cls, val):
 """
 A class method.
 >>> print C.clsm(22) # 18
 22
 >>> print C().clsm(22) # 19
 22
 """
 return 22
 clsm = classmethod(clsm)
def test_main():
 import test_doctest2
 # XXX 2 class docstrings are skipped.
 # EXPECTED = 19
 EXPECTED = 17
 f, t = test_support.run_doctest(test_doctest2)
 if t != EXPECTED:
 raise test_support.TestFailed("expected %d tests to run, not %d" %
 (EXPECTED, t))
# Pollute the namespace with a bunch of imported functions and classes,
# to make sure they don't get tested.
from doctest import *
if __name__ == '__main__':
 test_main()
Index: test_pyclbr.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_pyclbr.py,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** test_pyclbr.py	2001年10月02日 03:53:41	1.5
--- test_pyclbr.py	2001年10月03日 04:08:26	1.6
***************
*** 102,106 ****
 self.checkModule('pyclbr')
 self.checkModule('doctest',
! ignore=['_isclass', '_isfunction', '_ismodule'])
 self.checkModule('rfc822')
 self.checkModule('xmllib')
--- 102,109 ----
 self.checkModule('pyclbr')
 self.checkModule('doctest',
! ignore=['_isclass',
! '_isfunction',
! '_ismodule',
! '_classify_class_attrs'])
 self.checkModule('rfc822')
 self.checkModule('xmllib')
Index: test_support.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_support.py,v
retrieving revision 1.37
retrieving revision 1.38
diff -C2 -d -r1.37 -r1.38
*** test_support.py	2001年09月25日 20:05:11	1.37
--- test_support.py	2001年10月03日 04:08:26	1.38
***************
*** 177,181 ****
 
 def run_doctest(module, verbosity=None):
! """Run doctest on the given module.
 
 If optional argument verbosity is not specified (or is None), pass
--- 177,181 ----
 
 def run_doctest(module, verbosity=None):
! """Run doctest on the given module. Return (#failures, #tests).
 
 If optional argument verbosity is not specified (or is None), pass
***************
*** 199,202 ****
--- 199,203 ----
 if f:
 raise TestFailed("%d of %d doctests failed" % (f, t))
+ return f, t
 finally:
 sys.stdout = save_stdout

AltStyle によって変換されたページ (->オリジナル) /