This commit was manufactured by cvs2svn to create tag 'r23b1-mac'.
[python/dscho.git] / Lib / test / test_doctest2.py
blob3593d4199ab34ed6a07c8db575d23a6c21499008
1 """A module to test whether doctest recognizes some 2.2 features,
2 like static and class methods.
4 >>> print 'yup' # 1
5 yup
6 """
8 from test import test_support
10 class C(object):
11 """Class C.
13 >>> print C() # 2
15 """
17 def __init__(self):
18 """C.__init__.
20 >>> print C() # 3
22 """
24 def __str__(self):
25 """
26 >>> print C() # 4
28 """
29 return "42"
31 class D(object):
32 """A nested D class.
34 >>> print "In D!" # 5
35 In D!
36 """
38 def nested(self):
39 """
40 >>> print 3 # 6
42 """
44 def getx(self):
45 """
46 >>> c = C() # 7
47 >>> c.x = 12 # 8
48 >>> print c.x # 9
49 -12
50 """
51 return -self._x
53 def setx(self, value):
54 """
55 >>> c = C() # 10
56 >>> c.x = 12 # 11
57 >>> print c.x # 12
58 -12
59 """
60 self._x = value
62 x = property(getx, setx, doc="""\
63 >>> c = C() # 13
64 >>> c.x = 12 # 14
65 >>> print c.x # 15
66 -12
67 """)
69 def statm():
70 """
71 A static method.
73 >>> print C.statm() # 16
74 666
75 >>> print C().statm() # 17
76 666
77 """
78 return 666
80 statm = staticmethod(statm)
82 def clsm(cls, val):
83 """
84 A class method.
86 >>> print C.clsm(22) # 18
88 >>> print C().clsm(23) # 19
90 """
91 return val
93 clsm = classmethod(clsm)
95 def test_main():
96 from test import test_doctest2
97 EXPECTED = 19
98 f, t = test_support.run_doctest(test_doctest2)
99 if t != EXPECTED:
100 raise test_support.TestFailed("expected %d tests to run, not %d" %
101 (EXPECTED, t))
103 # Pollute the namespace with a bunch of imported functions and classes,
104 # to make sure they don't get tested.
105 from doctest import *
107 if __name__ == '__main__':
108 test_main()