home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2011 June / maximum-cd-2011-06.iso / DiscContents / LibO_3.3.1_Win_x86_install_multi.exe / libreoffice1.cab / test_doctest2.py < prev    next >
Encoding:
Python Source  |  2011-02-15  |  2.2 KB  |  121 lines

  1. # -*- coding: utf-8 -*-
  2. u"""A module to test whether doctest recognizes some 2.2 features,
  3. like static and class methods.
  4.  
  5. >>> print 'yup'  # 1
  6. yup
  7.  
  8. We include some (random) encoded (utf-8) text in the text surrounding
  9. the example.  It should be ignored:
  10.  
  11. ЉЊЈЁЂ
  12.  
  13. """
  14.  
  15. from test import test_support
  16.  
  17. class 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.     @staticmethod
  84.     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.  
  95.     @classmethod
  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. 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))
  114.  
  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 *
  118.  
  119. if __name__ == '__main__':
  120.     test_main()
  121.