Show More
@@ -0,0 +1,75 b'' | |||||
|
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 | ||||
|
21 | def doctest_multiline1(): | |||
|
22 | """The ipdoctest machinery must handle multiline examples gracefully. | |||
|
23 | ||||
|
24 | In [2]: for i in range(10): | |||
|
25 | ...: print i, | |||
|
26 | ...: | |||
|
27 | 0 1 2 3 4 5 6 7 8 9 | |||
|
28 | """ | |||
|
29 | ||||
|
30 | ||||
|
31 | def doctest_multiline2(): | |||
|
32 | """Multiline examples that define functions and print output. | |||
|
33 | ||||
|
34 | In [7]: def f(x): | |||
|
35 | ...: return x+1 | |||
|
36 | ...: | |||
|
37 | ||||
|
38 | In [8]: f(1) | |||
|
39 | Out[8]: 2 | |||
|
40 | ||||
|
41 | In [9]: def g(x): | |||
|
42 | ...: print 'x is:',x | |||
|
43 | ...: | |||
|
44 | ||||
|
45 | In [10]: g(1) | |||
|
46 | x is: 1 | |||
|
47 | ||||
|
48 | In [11]: g('hello') | |||
|
49 | x is: hello | |||
|
50 | """ | |||
|
51 | ||||
|
52 | ||||
|
53 | def doctest_multiline3(): | |||
|
54 | """Multiline examples with blank lines. | |||
|
55 | ||||
|
56 | In [12]: def h(x): | |||
|
57 | ....: if x>1: | |||
|
58 | ....: return x**2 | |||
|
59 | ....: # To leave a blank line in the input, you must mark it | |||
|
60 | ....: # with a comment character: | |||
|
61 | ....: # | |||
|
62 | ....: # otherwise the doctest parser gets confused. | |||
|
63 | ....: else: | |||
|
64 | ....: return -1 | |||
|
65 | ....: | |||
|
66 | ||||
|
67 | In [13]: h(5) | |||
|
68 | Out[13]: 25 | |||
|
69 | ||||
|
70 | In [14]: h(1) | |||
|
71 | Out[14]: -1 | |||
|
72 | ||||
|
73 | In [15]: h(0) | |||
|
74 | Out[15]: -1 | |||
|
75 | """ |
General Comments 0
You need to be logged in to leave comments.
Login now