Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / devtools / amd64 / lib / python2.4 / test / test_doctest2.py
CommitLineData
920dae64
AT
1# -*- coding: utf-8 -*-
2u"""A module to test whether doctest recognizes some 2.2 features,
3like static and class methods.
4
5>>> print 'yup' # 1
6yup
7
8We include some (random) encoded (utf-8) text in the text surrounding
9the example. It should be ignored:
10
11ЉЊЈЁЂ
12
13"""
14
15from test import test_support
16
17class C(object):
18 u"""Class C.
19
20 >>> print C() # 2
21 42
22
23
24 We include some (random) encoded (utf-8) text in the text surrounding
25 the example. It should be ignored:
26
27 ЉЊЈЁЂ
28
29 """
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
45 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
102 >>> print C().clsm(23) # 19
103 23
104 """
105 return val
106
107 clsm = classmethod(clsm)
108
109def test_main():
110 from test import test_doctest2
111 EXPECTED = 19
112 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()