##// END OF EJS Templates
more unique filename for test...
Paul Ivanov -
Show More
@@ -1,164 +1,164 b''
1 """Simple example using doctests.
1 """Simple example using doctests.
2
2
3 This file just contains doctests both using plain python and IPython prompts.
3 This file just contains doctests both using plain python and IPython prompts.
4 All tests should be loaded by nose.
4 All tests should be loaded by nose.
5 """
5 """
6 from IPython.utils.py3compat import doctest_refactor_print
6 from IPython.utils.py3compat import doctest_refactor_print
7
7
8 def pyfunc():
8 def pyfunc():
9 """Some pure python tests...
9 """Some pure python tests...
10
10
11 >>> pyfunc()
11 >>> pyfunc()
12 'pyfunc'
12 'pyfunc'
13
13
14 >>> import os
14 >>> import os
15
15
16 >>> 2+3
16 >>> 2+3
17 5
17 5
18
18
19 >>> for i in range(3):
19 >>> for i in range(3):
20 ... print i,
20 ... print i,
21 ... print i+1,
21 ... print i+1,
22 ...
22 ...
23 0 1 1 2 2 3
23 0 1 1 2 2 3
24 """
24 """
25 return 'pyfunc'
25 return 'pyfunc'
26
26
27 @doctest_refactor_print
27 @doctest_refactor_print
28 def ipfunc():
28 def ipfunc():
29 """Some ipython tests...
29 """Some ipython tests...
30
30
31 In [1]: import os
31 In [1]: import os
32
32
33 In [3]: 2+3
33 In [3]: 2+3
34 Out[3]: 5
34 Out[3]: 5
35
35
36 In [26]: for i in range(3):
36 In [26]: for i in range(3):
37 ....: print i,
37 ....: print i,
38 ....: print i+1,
38 ....: print i+1,
39 ....:
39 ....:
40 0 1 1 2 2 3
40 0 1 1 2 2 3
41
41
42
42
43 Examples that access the operating system work:
43 Examples that access the operating system work:
44
44
45 In [1]: !echo hello
45 In [1]: !echo hello
46 hello
46 hello
47
47
48 In [2]: !echo hello > /tmp/foo
48 In [2]: !echo hello > /tmp/foo_iptest
49
49
50 In [3]: !cat /tmp/foo
50 In [3]: !cat /tmp/foo_iptest
51 hello
51 hello
52
52
53 In [4]: rm -f /tmp/foo
53 In [4]: rm -f /tmp/foo_iptest
54
54
55 It's OK to use '_' for the last result, but do NOT try to use IPython's
55 It's OK to use '_' for the last result, but do NOT try to use IPython's
56 numbered history of _NN outputs, since those won't exist under the
56 numbered history of _NN outputs, since those won't exist under the
57 doctest environment:
57 doctest environment:
58
58
59 In [7]: 'hi'
59 In [7]: 'hi'
60 Out[7]: 'hi'
60 Out[7]: 'hi'
61
61
62 In [8]: print repr(_)
62 In [8]: print repr(_)
63 'hi'
63 'hi'
64
64
65 In [7]: 3+4
65 In [7]: 3+4
66 Out[7]: 7
66 Out[7]: 7
67
67
68 In [8]: _+3
68 In [8]: _+3
69 Out[8]: 10
69 Out[8]: 10
70
70
71 In [9]: ipfunc()
71 In [9]: ipfunc()
72 Out[9]: 'ipfunc'
72 Out[9]: 'ipfunc'
73 """
73 """
74 return 'ipfunc'
74 return 'ipfunc'
75
75
76
76
77 def ranfunc():
77 def ranfunc():
78 """A function with some random output.
78 """A function with some random output.
79
79
80 Normal examples are verified as usual:
80 Normal examples are verified as usual:
81 >>> 1+3
81 >>> 1+3
82 4
82 4
83
83
84 But if you put '# random' in the output, it is ignored:
84 But if you put '# random' in the output, it is ignored:
85 >>> 1+3
85 >>> 1+3
86 junk goes here... # random
86 junk goes here... # random
87
87
88 >>> 1+2
88 >>> 1+2
89 again, anything goes #random
89 again, anything goes #random
90 if multiline, the random mark is only needed once.
90 if multiline, the random mark is only needed once.
91
91
92 >>> 1+2
92 >>> 1+2
93 You can also put the random marker at the end:
93 You can also put the random marker at the end:
94 # random
94 # random
95
95
96 >>> 1+2
96 >>> 1+2
97 # random
97 # random
98 .. or at the beginning.
98 .. or at the beginning.
99
99
100 More correct input is properly verified:
100 More correct input is properly verified:
101 >>> ranfunc()
101 >>> ranfunc()
102 'ranfunc'
102 'ranfunc'
103 """
103 """
104 return 'ranfunc'
104 return 'ranfunc'
105
105
106
106
107 def random_all():
107 def random_all():
108 """A function where we ignore the output of ALL examples.
108 """A function where we ignore the output of ALL examples.
109
109
110 Examples:
110 Examples:
111
111
112 # all-random
112 # all-random
113
113
114 This mark tells the testing machinery that all subsequent examples should
114 This mark tells the testing machinery that all subsequent examples should
115 be treated as random (ignoring their output). They are still executed,
115 be treated as random (ignoring their output). They are still executed,
116 so if a they raise an error, it will be detected as such, but their
116 so if a they raise an error, it will be detected as such, but their
117 output is completely ignored.
117 output is completely ignored.
118
118
119 >>> 1+3
119 >>> 1+3
120 junk goes here...
120 junk goes here...
121
121
122 >>> 1+3
122 >>> 1+3
123 klasdfj;
123 klasdfj;
124
124
125 >>> 1+2
125 >>> 1+2
126 again, anything goes
126 again, anything goes
127 blah...
127 blah...
128 """
128 """
129 pass
129 pass
130
130
131 @doctest_refactor_print
131 @doctest_refactor_print
132 def iprand():
132 def iprand():
133 """Some ipython tests with random output.
133 """Some ipython tests with random output.
134
134
135 In [7]: 3+4
135 In [7]: 3+4
136 Out[7]: 7
136 Out[7]: 7
137
137
138 In [8]: print 'hello'
138 In [8]: print 'hello'
139 world # random
139 world # random
140
140
141 In [9]: iprand()
141 In [9]: iprand()
142 Out[9]: 'iprand'
142 Out[9]: 'iprand'
143 """
143 """
144 return 'iprand'
144 return 'iprand'
145
145
146 @doctest_refactor_print
146 @doctest_refactor_print
147 def iprand_all():
147 def iprand_all():
148 """Some ipython tests with fully random output.
148 """Some ipython tests with fully random output.
149
149
150 # all-random
150 # all-random
151
151
152 In [7]: 1
152 In [7]: 1
153 Out[7]: 99
153 Out[7]: 99
154
154
155 In [8]: print 'hello'
155 In [8]: print 'hello'
156 world
156 world
157
157
158 In [9]: iprand_all()
158 In [9]: iprand_all()
159 Out[9]: 'junk'
159 Out[9]: 'junk'
160 """
160 """
161 return 'iprand_all'
161 return 'iprand_all'
162
162
163
163
164
164
General Comments 0
You need to be logged in to leave comments. Login now