Issue #5788: `datetime.timedelta` objects get a new `total_seconds()` method returning
[python.git] / Lib / test / test_doctest2.py
blob865a32e6f250de81239232320876988d671d0b03
1 # -*- coding: utf-8 -*-
2 u"""A module to test whether doctest recognizes some 2.2 features,
3 like static and class methods.
5 >>> print 'yup' # 1
6 yup
8 We include some (random) encoded (utf-8) text in the text surrounding
9 the example. It should be ignored:
11 ЉЊЈЁЂ
13 """
15 from test import test_support
17 class C(object):
18 u"""Class C.
20 >>> print C() # 2
24 We include some (random) encoded (utf-8) text in the text surrounding
25 the example. It should be ignored:
27 ЉЊЈЁЂ
29 """
31 def __init__(self):
32 """C.__init__.
34 >>> print C() # 3
36 """
38 def __str__(self):
39 """
40 >>> print C() # 4
42 """
43 return "42"
45 class D(object):
46 """A nested D class.
48 >>> print "In D!" # 5
49 In D!
50 """
52 def nested(self):
53 """
54 >>> print 3 # 6
56 """
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
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
76 x = property(getx, setx, doc="""\
77 >>> c = C() # 13
78 >>> c.x = 12 # 14
79 >>> print c.x # 15
80 -12
81 """)
83 @staticmethod
84 def statm():
85 """
86 A static method.
88 >>> print C.statm() # 16
89 666
90 >>> print C().statm() # 17
91 666
92 """
93 return 666
95 @classmethod
96 def clsm(cls, val):
97 """
98 A class method.
100 >>> print C.clsm(22) # 18
102 >>> print C().clsm(23) # 19
105 return val
107 def test_main():
108 from test import test_doctest2
109 EXPECTED = 19
110 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))
115 # Pollute the namespace with a bunch of imported functions and classes,
116 # to make sure they don't get tested.
117 from doctest import *
119 if __name__ == '__main__':
120 test_main()