blob: 31bf6e854c1b03ddd865f7ec8226ca1574317ad3 [file] [log] [blame]
Tim Peters17111f32001-10-03 04:08:26 +00001"""A module to test whether doctest recognizes some 2.2 features,
2like static and class methods.
3
4>>> print 'yup' # 1
5yup
6"""
7
Barry Warsaw04f357c2002-07-23 19:04:11 +00008from test import test_support
Tim Peters17111f32001-10-03 04:08:26 +00009
Tim Peters17111f32001-10-03 04:08:26 +000010class C(object):
11 """Class C.
12
13 >>> print C() # 2
14 42
15 """
16
17 def __init__(self):
18 """C.__init__.
19
20 >>> print C() # 3
21 42
22 """
23
24 def __str__(self):
25 """
26 >>> print C() # 4
27 42
28 """
29 return "42"
30
Tim Peters17111f32001-10-03 04:08:26 +000031 class D(object):
32 """A nested D class.
33
34 >>> print "In D!" # 5
35 In D!
36 """
37
38 def nested(self):
39 """
40 >>> print 3 # 6
41 3
42 """
43
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
52
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
61
62 x = property(getx, setx, doc="""\
63 >>> c = C() # 13
64 >>> c.x = 12 # 14
65 >>> print c.x # 15
66 -12
67 """)
68
69 def statm():
70 """
71 A static method.
72
73 >>> print C.statm() # 16
74 666
75 >>> print C().statm() # 17
76 666
77 """
78 return 666
79
80 statm = staticmethod(statm)
81
82 def clsm(cls, val):
83 """
84 A class method.
85
86 >>> print C.clsm(22) # 18
87 22
Tim Peters1b0e5492001-10-03 04:15:28 +000088 >>> print C().clsm(23) # 19
89 23
Tim Peters17111f32001-10-03 04:08:26 +000090 """
Tim Peters1b0e5492001-10-03 04:15:28 +000091 return val
Tim Peters17111f32001-10-03 04:08:26 +000092
93 clsm = classmethod(clsm)
94
95def test_main():
96 import test_doctest2
Tim Peters2f93e282001-10-04 05:27:00 +000097 EXPECTED = 19
Tim Peters17111f32001-10-03 04:08:26 +000098 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))
102
103# Pollute the namespace with a bunch of imported functions and classes,
104# to make sure they don't get tested.
105from doctest import *
106
107if __name__ == '__main__':
108 test_main()