blob: 0cbe3d43019ff1f12b3d7d5763ba0b4b006e86f3 [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
8import test_support
9
10# XXX The class docstring is skipped.
11class C(object):
12 """Class C.
13
14 >>> print C() # 2
15 42
16 """
17
18 def __init__(self):
19 """C.__init__.
20
21 >>> print C() # 3
22 42
23 """
24
25 def __str__(self):
26 """
27 >>> print C() # 4
28 42
29 """
30 return "42"
31
32 # XXX The class docstring is skipped.
33 class D(object):
34 """A nested D class.
35
36 >>> print "In D!" # 5
37 In D!
38 """
39
40 def nested(self):
41 """
42 >>> print 3 # 6
43 3
44 """
45
46 def getx(self):
47 """
48 >>> c = C() # 7
49 >>> c.x = 12 # 8
50 >>> print c.x # 9
51 -12
52 """
53 return -self._x
54
55 def setx(self, value):
56 """
57 >>> c = C() # 10
58 >>> c.x = 12 # 11
59 >>> print c.x # 12
60 -12
61 """
62 self._x = value
63
64 x = property(getx, setx, doc="""\
65 >>> c = C() # 13
66 >>> c.x = 12 # 14
67 >>> print c.x # 15
68 -12
69 """)
70
71 def statm():
72 """
73 A static method.
74
75 >>> print C.statm() # 16
76 666
77 >>> print C().statm() # 17
78 666
79 """
80 return 666
81
82 statm = staticmethod(statm)
83
84 def clsm(cls, val):
85 """
86 A class method.
87
88 >>> print C.clsm(22) # 18
89 22
90 >>> print C().clsm(22) # 19
91 22
92 """
93 return 22
94
95 clsm = classmethod(clsm)
96
97def test_main():
98 import test_doctest2
99 # XXX 2 class docstrings are skipped.
100 # EXPECTED = 19
101 EXPECTED = 17
102 f, t = test_support.run_doctest(test_doctest2)
103 if t != EXPECTED:
104 raise test_support.TestFailed("expected %d tests to run, not %d" %
105 (EXPECTED, t))
106
107# Pollute the namespace with a bunch of imported functions and classes,
108# to make sure they don't get tested.
109from doctest import *
110
111if __name__ == '__main__':
112 test_main()