1 """Tests for the ipdoctest machinery itself. 2 3 Note: in a file named test_X, functions whose only test is their docstring (as 4 a doctest) and which have no test functionality of their own, should be called 5 'doctest_foo' instead of 'test_foo', otherwise they get double-counted (the 6 empty function call is counted as a test, which just inflates tests numbers 7 artificially). 8 """ 9 10 def doctest_simple(): 11 """ipdoctest must handle simple inputs 12 13 In [1]: 1 14 Out[1]: 1 15 16 In [2]: print(1) 17 1 18 """ 19 20 def doctest_multiline1(): 21 """The ipdoctest machinery must handle multiline examples gracefully. 22 23 In [2]: for i in range(4): 24 ...: print(i) 25 ...: 26 0 27 1 28 2 29 3 30 """ 31 32 def doctest_multiline2(): 33 """Multiline examples that define functions and print output. 34 35 In [7]: def f(x): 36 ...: return x+1 37 ...: 38 39 In [8]: f(1) 40 Out[8]: 2 41 42 In [9]: def g(x): 43 ...: print('x is:',x) 44 ...: 45 46 In [10]: g(1) 47 x is: 1 48 49 In [11]: g('hello') 50 x is: hello 51 """ 52 53 54 def doctest_multiline3(): 55 """Multiline examples with blank lines. 56 57 In [12]: def h(x): 58 ....: if x>1: 59 ....: return x**2 60 ....: # To leave a blank line in the input, you must mark it 61 ....: # with a comment character: 62 ....: # 63 ....: # otherwise the doctest parser gets confused. 64 ....: else: 65 ....: return -1 66 ....: 67 68 In [13]: h(5) 69 Out[13]: 25 70 71 In [14]: h(1) 72 Out[14]: -1 73 74 In [15]: h(0) 75 Out[15]: -1 76 """ 77 78 79 def doctest_builtin_underscore(): 80 """Defining builtins._ should not break anything outside the doctest 81 while also should be working as expected inside the doctest. 82 83 In [1]: import builtins 84 85 In [2]: builtins._ = 42 86 87 In [3]: builtins._ 88 Out[3]: 42 89 90 In [4]: _ 91 Out[4]: 42 92 """ 93