Format: application/x-python-code
1 o
2
3 ��hi � @ sT d Z ddlZdd� Zdd� Zdd� Zejd ke_d
4 d� Zdd
5 � Zdd� Z dd� Z
6 dS )z�Simple example using doctests.
7
8 This file just contains doctests both using plain python and IPython prompts.
9 All tests should be loaded by nose.
10 � Nc C � dS )z�Some pure python tests...
11
12 >>> pyfunc()
13 'pyfunc'
14
15 >>> import os
16
17 >>> 2+3
18 5
19
20 >>> for i in range(3):
21 ... print(i, end=' ')
22 ... print(i+1, end=' ')
23 ...
24 0 1 1 2 2 3
25 �pyfunc� r r r �Vc:\Users\shubh\Videos\agent\nova\Lib\site-packages\IPython/testing/plugin/dtexample.pyr
26 s r c C r )a6 Some ipython tests...
27
28 In [1]: import os
29
30 In [3]: 2+3
31 Out[3]: 5
32
33 In [26]: for i in range(3):
34 ....: print(i, end=' ')
35 ....: print(i+1, end=' ')
36 ....:
37 0 1 1 2 2 3
38
39
40 It's OK to use '_' for the last result, but do NOT try to use IPython's
41 numbered history of _NN outputs, since those won't exist under the
42 doctest environment:
43
44 In [7]: 'hi'
45 Out[7]: 'hi'
46
47 In [8]: print(repr(_))
48 'hi'
49
50 In [7]: 3+4
51 Out[7]: 7
52
53 In [8]: _+3
54 Out[8]: 10
55
56 In [9]: ipfunc()
57 Out[9]: 'ipfunc'
58 �ipfuncr r r r r r s "r c C r )z�Examples that access the operating system work:
59
60 In [1]: !echo hello
61 hello
62
63 In [2]: !echo hello > /tmp/foo_iptest
64
65 In [3]: !cat /tmp/foo_iptest
66 hello
67
68 In [4]: rm -f /tmp/foo_iptest
69 Nr r r r r �iposB s
70 r �ntc C r )a< A function with some random output.
71
72 Normal examples are verified as usual:
73 >>> 1+3
74 4
75
76 But if you put '# random' in the output, it is ignored:
77 >>> 1+3
78 junk goes here... # random
79
80 >>> 1+2
81 again, anything goes #random
82 if multiline, the random mark is only needed once.
83
84 >>> 1+2
85 You can also put the random marker at the end:
86 # random
87
88 >>> 1+2
89 # random
90 .. or at the beginning.
91
92 More correct input is properly verified:
93 >>> ranfunc()
94 'ranfunc'
95 �ranfuncr r r r r r U s r c C r )a� A function where we ignore the output of ALL examples.
96
97 Examples:
98
99 # all-random
100
101 This mark tells the testing machinery that all subsequent examples should
102 be treated as random (ignoring their output). They are still executed,
103 so if a they raise an error, it will be detected as such, but their
104 output is completely ignored.
105
106 >>> 1+3
107 junk goes here...
108
109 >>> 1+3
110 klasdfj;
111
112 >>> 1+2
113 again, anything goes
114 blah...
115 Nr r r r r �
116 random_alls s r
117 c C r )z�Some ipython tests with random output.
118
119 In [7]: 3+4
120 Out[7]: 7
121
122 In [8]: print('hello')
123 world # random
124
125 In [9]: iprand()
126 Out[9]: 'iprand'
127 �iprandr r r r r r � s r c C r )z�Some ipython tests with fully random output.
128
129 # all-random
130
131 In [7]: 1
132 Out[7]: 99
133
134 In [8]: print('hello')
135 world
136
137 In [9]: iprand_all()
138 Out[9]: 'junk'
139 �
140 iprand_allr r r r r r � s r )�__doc__�osr r r �nameZ__skip_doctest__r r
141 r r r r r r �<module> s %