blob: 5b7f36f0f738d94b8f96b30a0141b374f6dccaa2 [file] [log] [blame]
Jim Fulton7d428782004-10-13 14:15:32 +00001# -*- coding: utf-8 -*-
2u"""A module to test whether doctest recognizes some 2.2 features,
Tim Peters17111f32001-10-03 04:08:26 +00003like static and class methods.
4
5>>> print 'yup' # 1
6yup
Jim Fulton7d428782004-10-13 14:15:32 +00007
8We include some (random) encoded (utf-8) text in the text surrounding
9the example. It should be ignored:
10
11ЉЊЈЁЂ
12
Tim Peters17111f32001-10-03 04:08:26 +000013"""
14
Barry Warsaw04f357c2002-07-23 19:04:11 +000015from test import test_support
Tim Peters17111f32001-10-03 04:08:26 +000016
Tim Peters17111f32001-10-03 04:08:26 +000017class C(object):
Jim Fulton7d428782004-10-13 14:15:32 +000018 u"""Class C.
Tim Peters17111f32001-10-03 04:08:26 +000019
20 >>> print C() # 2
21 42
Jim Fulton7d428782004-10-13 14:15:32 +000022
23
24 We include some (random) encoded (utf-8) text in the text surrounding
25 the example. It should be ignored:
26
27 ЉЊЈЁЂ
28
Tim Peters17111f32001-10-03 04:08:26 +000029 """
30
31 def __init__(self):
32 """C.__init__.
33
34 >>> print C() # 3
35 42
36 """
37
38 def __str__(self):
39 """
40 >>> print C() # 4
41 42
42 """
43 return "42"
44
Tim Peters17111f32001-10-03 04:08:26 +000045 class D(object):
46 """A nested D class.
47
48 >>> print "In D!" # 5
49 In D!
50 """
51
52 def nested(self):
53 """
54 >>> print 3 # 6
55 3
56 """
57
58 def getx(self):
59 """
60 >>> c = C() # 7
61 >>> c.x = 12 # 8
62 >>> print c.x # 9
63 -12
64 """
65 return -self._x
66
67 def setx(self, value):
68 """
69 >>> c = C() # 10
70 >>> c.x = 12 # 11
71 >>> print c.x # 12
72 -12
73 """
74 self._x = value
75
76 x = property(getx, setx, doc="""\
77 >>> c = C() # 13
78 >>> c.x = 12 # 14
79 >>> print c.x # 15
80 -12
81 """)
82
83 def statm():
84 """
85 A static method.
86
87 >>> print C.statm() # 16
88 666
89 >>> print C().statm() # 17
90 666
91 """
92 return 666
93
94 statm = staticmethod(statm)
95
96 def clsm(cls, val):
97 """
98 A class method.
99
100 >>> print C.clsm(22) # 18
101 22
Tim Peters1b0e5492001-10-03 04:15:28 +0000102 >>> print C().clsm(23) # 19
103 23
Tim Peters17111f32001-10-03 04:08:26 +0000104 """
Tim Peters1b0e5492001-10-03 04:15:28 +0000105 return val
Tim Peters17111f32001-10-03 04:08:26 +0000106
107 clsm = classmethod(clsm)
108
109def test_main():
Barry Warsaw408b6d32002-07-30 23:27:12 +0000110 from test import test_doctest2
Tim Peters2f93e282001-10-04 05:27:00 +0000111 EXPECTED = 19
Tim Peters17111f32001-10-03 04:08:26 +0000112 f, t = test_support.run_doctest(test_doctest2)
113 if t != EXPECTED:
114 raise test_support.TestFailed("expected %d tests to run, not %d" %
115 (EXPECTED, t))
116
117# Pollute the namespace with a bunch of imported functions and classes,
118# to make sure they don't get tested.
119from doctest import *
120
121if __name__ == '__main__':
122 test_main()