blob: 865a32e6f250de81239232320876988d671d0b03 [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
Guido van Rossum5a8a0372005-01-16 00:25:31 +000083 @staticmethod
Tim Peters17111f32001-10-03 04:08:26 +000084 def statm():
85 """
86 A static method.
87
88 >>> print C.statm() # 16
89 666
90 >>> print C().statm() # 17
91 666
92 """
93 return 666
94
Guido van Rossum5a8a0372005-01-16 00:25:31 +000095 @classmethod
Tim Peters17111f32001-10-03 04:08:26 +000096 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
Tim Peters17111f32001-10-03 04:08:26 +0000107def test_main():
Barry Warsaw408b6d32002-07-30 23:27:12 +0000108 from test import test_doctest2
Tim Peters2f93e282001-10-04 05:27:00 +0000109 EXPECTED = 19
Tim Peters17111f32001-10-03 04:08:26 +0000110 f, t = test_support.run_doctest(test_doctest2)
111 if t != EXPECTED:
112 raise test_support.TestFailed("expected %d tests to run, not %d" %
113 (EXPECTED, t))
114
115# Pollute the namespace with a bunch of imported functions and classes,
116# to make sure they don't get tested.
117from doctest import *
118
119if __name__ == '__main__':
120 test_main()