0001 # -*- coding: utf-8 -*- 0002 u"""A module to test whether doctest recognizes some 2.2 features, 0003 like static and class methods. 0004 0005 >>> print 'yup' # 1 0006 yup 0007 0008 We include some (random) encoded (utf-8) text in the text surrounding 0009 the example. It should be ignored: 0010 0011 ЉЊЈЁЂ 0012 0013 """ 0014 0015 from test import test_support 0016 0017 class C(object): 0018 u"""Class C. 0019 0020 >>> print C() # 2 0021 42 0022 0023 0024 We include some (random) encoded (utf-8) text in the text surrounding 0025 the example. It should be ignored: 0026 0027 ЉЊЈЁЂ 0028 0029 """ 0030 0031 def __init__(self): 0032 """C.__init__. 0033 0034 >>> print C() # 3 0035 42 0036 """ 0037 0038 def __str__(self): 0039 """ 0040 >>> print C() # 4 0041 42 0042 """ 0043 return "42" 0044 0045 class D(object): 0046 """A nested D class. 0047 0048 >>> print "In D!" # 5 0049 In D! 0050 """ 0051 0052 def nested(self): 0053 """ 0054 >>> print 3 # 6 0055 3 0056 """ 0057 0058 def getx(self): 0059 """ 0060 >>> c = C() # 7 0061 >>> c.x = 12 # 8 0062 >>> print c.x # 9 0063 -12 0064 """ 0065 return -self._x 0066 0067 def setx(self, value): 0068 """ 0069 >>> c = C() # 10 0070 >>> c.x = 12 # 11 0071 >>> print c.x # 12 0072 -12 0073 """ 0074 self._x = value 0075 0076 x = property(getx, setx, doc="""\ 0077 >>> c = C() # 13 0078 >>> c.x = 12 # 14 0079 >>> print c.x # 15 0080 -12 0081 """) 0082 0083 def statm(): 0084 """ 0085 A static method. 0086 0087 >>> print C.statm() # 16 0088 666 0089 >>> print C().statm() # 17 0090 666 0091 """ 0092 return 666 0093 0094 statm = staticmethod(statm) 0095 0096 def clsm(cls, val): 0097 """ 0098 A class method. 0099 0100 >>> print C.clsm(22) # 18 0101 22 0102 >>> print C().clsm(23) # 19 0103 23 0104 """ 0105 return val 0106 0107 clsm = classmethod(clsm) 0108 0109 def test_main(): 0110 from test import test_doctest2 0111 EXPECTED = 19 0112 f, t = test_support.run_doctest(test_doctest2) 0113 if t != EXPECTED: 0114 raise test_support.TestFailed("expected %d tests to run, not %d" % 0115 (EXPECTED, t)) 0116 0117 # Pollute the namespace with a bunch of imported functions and classes, 0118 # to make sure they don't get tested. 0119 from doctest import * 0120 0121 if __name__ == '__main__': 0122 test_main() 0123
Generated by PyXR 0.9.4