| 
									
										
										
										
											2007-05-02 19:09:54 +00:00
										 |  |  | """A module to test whether doctest recognizes some 2.2 features,
 | 
					
						
							| 
									
										
										
										
											2001-10-03 04:08:26 +00:00
										 |  |  | like static and class methods. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-02-09 20:13:25 +00:00
										 |  |  | >>> print('yup')  # 1 | 
					
						
							| 
									
										
										
										
											2001-10-03 04:08:26 +00:00
										 |  |  | yup | 
					
						
							| 
									
										
										
										
											2004-10-13 14:15:32 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | We include some (random) encoded (utf-8) text in the text surrounding | 
					
						
							|  |  |  | the example.  It should be ignored: | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ЉЊЈЁЂ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-10-03 04:08:26 +00:00
										 |  |  | """
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-02-24 01:46:21 +00:00
										 |  |  | import sys | 
					
						
							|  |  |  | import unittest | 
					
						
							| 
									
										
										
										
											2008-05-20 21:35:26 +00:00
										 |  |  | from test import support | 
					
						
							| 
									
										
										
										
											2010-02-24 01:46:21 +00:00
										 |  |  | if sys.flags.optimize >= 2: | 
					
						
							|  |  |  |     raise unittest.SkipTest("Cannot test docstrings with -O2") | 
					
						
							| 
									
										
										
										
											2001-10-03 04:08:26 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | class C(object): | 
					
						
							| 
									
										
										
										
											2007-05-02 19:09:54 +00:00
										 |  |  |     """Class C.
 | 
					
						
							| 
									
										
										
										
											2001-10-03 04:08:26 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-02-09 20:13:25 +00:00
										 |  |  |     >>> print(C())  # 2 | 
					
						
							| 
									
										
										
										
											2001-10-03 04:08:26 +00:00
										 |  |  |     42 | 
					
						
							| 
									
										
										
										
											2004-10-13 14:15:32 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     We include some (random) encoded (utf-8) text in the text surrounding | 
					
						
							|  |  |  |     the example.  It should be ignored: | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         ЉЊЈЁЂ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-10-03 04:08:26 +00:00
										 |  |  |     """
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def __init__(self): | 
					
						
							|  |  |  |         """C.__init__.
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-02-09 20:13:25 +00:00
										 |  |  |         >>> print(C()) # 3 | 
					
						
							| 
									
										
										
										
											2001-10-03 04:08:26 +00:00
										 |  |  |         42 | 
					
						
							|  |  |  |         """
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def __str__(self): | 
					
						
							|  |  |  |         """
 | 
					
						
							| 
									
										
										
										
											2007-02-09 20:13:25 +00:00
										 |  |  |         >>> print(C()) # 4 | 
					
						
							| 
									
										
										
										
											2001-10-03 04:08:26 +00:00
										 |  |  |         42 | 
					
						
							|  |  |  |         """
 | 
					
						
							|  |  |  |         return "42" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     class D(object): | 
					
						
							|  |  |  |         """A nested D class.
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-02-09 20:13:25 +00:00
										 |  |  |         >>> print("In D!")   # 5 | 
					
						
							| 
									
										
										
										
											2001-10-03 04:08:26 +00:00
										 |  |  |         In D! | 
					
						
							|  |  |  |         """
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         def nested(self): | 
					
						
							|  |  |  |             """
 | 
					
						
							| 
									
										
										
										
											2007-02-09 20:13:25 +00:00
										 |  |  |             >>> print(3) # 6 | 
					
						
							| 
									
										
										
										
											2001-10-03 04:08:26 +00:00
										 |  |  |             3 | 
					
						
							|  |  |  |             """
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def getx(self): | 
					
						
							|  |  |  |         """
 | 
					
						
							|  |  |  |         >>> c = C()    # 7 | 
					
						
							|  |  |  |         >>> c.x = 12   # 8 | 
					
						
							| 
									
										
										
										
											2007-02-09 20:13:25 +00:00
										 |  |  |         >>> print(c.x)  # 9 | 
					
						
							| 
									
										
										
										
											2001-10-03 04:08:26 +00:00
										 |  |  |         -12 | 
					
						
							|  |  |  |         """
 | 
					
						
							|  |  |  |         return -self._x | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def setx(self, value): | 
					
						
							|  |  |  |         """
 | 
					
						
							|  |  |  |         >>> c = C()     # 10 | 
					
						
							|  |  |  |         >>> c.x = 12    # 11 | 
					
						
							| 
									
										
										
										
											2007-02-09 20:13:25 +00:00
										 |  |  |         >>> print(c.x)   # 12 | 
					
						
							| 
									
										
										
										
											2001-10-03 04:08:26 +00:00
										 |  |  |         -12 | 
					
						
							|  |  |  |         """
 | 
					
						
							|  |  |  |         self._x = value | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     x = property(getx, setx, doc="""\
 | 
					
						
							|  |  |  |         >>> c = C()    # 13 | 
					
						
							|  |  |  |         >>> c.x = 12   # 14 | 
					
						
							| 
									
										
										
										
											2007-02-09 20:13:25 +00:00
										 |  |  |         >>> print(c.x)  # 15 | 
					
						
							| 
									
										
										
										
											2001-10-03 04:08:26 +00:00
										 |  |  |         -12 | 
					
						
							|  |  |  |         """)
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-01-16 00:25:31 +00:00
										 |  |  |     @staticmethod | 
					
						
							| 
									
										
										
										
											2001-10-03 04:08:26 +00:00
										 |  |  |     def statm(): | 
					
						
							|  |  |  |         """
 | 
					
						
							|  |  |  |         A static method. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-02-09 20:13:25 +00:00
										 |  |  |         >>> print(C.statm())    # 16 | 
					
						
							| 
									
										
										
										
											2001-10-03 04:08:26 +00:00
										 |  |  |         666 | 
					
						
							| 
									
										
										
										
											2007-02-09 20:13:25 +00:00
										 |  |  |         >>> print(C().statm())  # 17 | 
					
						
							| 
									
										
										
										
											2001-10-03 04:08:26 +00:00
										 |  |  |         666 | 
					
						
							|  |  |  |         """
 | 
					
						
							|  |  |  |         return 666 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-01-16 00:25:31 +00:00
										 |  |  |     @classmethod | 
					
						
							| 
									
										
										
										
											2001-10-03 04:08:26 +00:00
										 |  |  |     def clsm(cls, val): | 
					
						
							|  |  |  |         """
 | 
					
						
							|  |  |  |         A class method. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-02-09 20:13:25 +00:00
										 |  |  |         >>> print(C.clsm(22))    # 18 | 
					
						
							| 
									
										
										
										
											2001-10-03 04:08:26 +00:00
										 |  |  |         22 | 
					
						
							| 
									
										
										
										
											2007-02-09 20:13:25 +00:00
										 |  |  |         >>> print(C().clsm(23))  # 19 | 
					
						
							| 
									
										
										
										
											2001-10-03 04:15:28 +00:00
										 |  |  |         23 | 
					
						
							| 
									
										
										
										
											2001-10-03 04:08:26 +00:00
										 |  |  |         """
 | 
					
						
							| 
									
										
										
										
											2001-10-03 04:15:28 +00:00
										 |  |  |         return val | 
					
						
							| 
									
										
										
										
											2001-10-03 04:08:26 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | def test_main(): | 
					
						
							| 
									
										
										
										
											2002-07-30 23:27:12 +00:00
										 |  |  |     from test import test_doctest2 | 
					
						
							| 
									
										
										
										
											2001-10-04 05:27:00 +00:00
										 |  |  |     EXPECTED = 19 | 
					
						
							| 
									
										
										
										
											2008-05-20 21:35:26 +00:00
										 |  |  |     f, t = support.run_doctest(test_doctest2) | 
					
						
							| 
									
										
										
										
											2001-10-03 04:08:26 +00:00
										 |  |  |     if t != EXPECTED: | 
					
						
							| 
									
										
										
										
											2008-05-20 21:35:26 +00:00
										 |  |  |         raise support.TestFailed("expected %d tests to run, not %d" % | 
					
						
							| 
									
										
										
										
											2001-10-03 04:08:26 +00:00
										 |  |  |                                       (EXPECTED, t)) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # Pollute the namespace with a bunch of imported functions and classes, | 
					
						
							|  |  |  | # to make sure they don't get tested. | 
					
						
							|  |  |  | from doctest import * | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | if __name__ == '__main__': | 
					
						
							|  |  |  |     test_main() |