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