##// END OF EJS Templates
Update test_ipdoctest.py
Matthias Bussonnier -
Show More
@@ -1,77 +1,76 b''
1 """Tests for the ipdoctest machinery itself.
1 """Tests for the ipdoctest machinery itself.
2
2
3 Note: in a file named test_X, functions whose only test is their docstring (as
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
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
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
6 empty function call is counted as a test, which just inflates tests numbers
7 artificially).
7 artificially).
8 """
8 """
9 from IPython.utils.py3compat import doctest_refactor_print
10
9
11 def doctest_simple():
10 def doctest_simple():
12 """ipdoctest must handle simple inputs
11 """ipdoctest must handle simple inputs
13
12
14 In [1]: 1
13 In [1]: 1
15 Out[1]: 1
14 Out[1]: 1
16
15
17 In [2]: print(1)
16 In [2]: print(1)
18 1
17 1
19 """
18 """
20
19
21 def doctest_multiline1():
20 def doctest_multiline1():
22 """The ipdoctest machinery must handle multiline examples gracefully.
21 """The ipdoctest machinery must handle multiline examples gracefully.
23
22
24 In [2]: for i in range(4):
23 In [2]: for i in range(4):
25 ...: print(i)
24 ...: print(i)
26 ...:
25 ...:
27 0
26 0
28 1
27 1
29 2
28 2
30 3
29 3
31 """
30 """
32
31
33 def doctest_multiline2():
32 def doctest_multiline2():
34 """Multiline examples that define functions and print output.
33 """Multiline examples that define functions and print output.
35
34
36 In [7]: def f(x):
35 In [7]: def f(x):
37 ...: return x+1
36 ...: return x+1
38 ...:
37 ...:
39
38
40 In [8]: f(1)
39 In [8]: f(1)
41 Out[8]: 2
40 Out[8]: 2
42
41
43 In [9]: def g(x):
42 In [9]: def g(x):
44 ...: print('x is:',x)
43 ...: print('x is:',x)
45 ...:
44 ...:
46
45
47 In [10]: g(1)
46 In [10]: g(1)
48 x is: 1
47 x is: 1
49
48
50 In [11]: g('hello')
49 In [11]: g('hello')
51 x is: hello
50 x is: hello
52 """
51 """
53
52
54
53
55 def doctest_multiline3():
54 def doctest_multiline3():
56 """Multiline examples with blank lines.
55 """Multiline examples with blank lines.
57
56
58 In [12]: def h(x):
57 In [12]: def h(x):
59 ....: if x>1:
58 ....: if x>1:
60 ....: return x**2
59 ....: return x**2
61 ....: # To leave a blank line in the input, you must mark it
60 ....: # To leave a blank line in the input, you must mark it
62 ....: # with a comment character:
61 ....: # with a comment character:
63 ....: #
62 ....: #
64 ....: # otherwise the doctest parser gets confused.
63 ....: # otherwise the doctest parser gets confused.
65 ....: else:
64 ....: else:
66 ....: return -1
65 ....: return -1
67 ....:
66 ....:
68
67
69 In [13]: h(5)
68 In [13]: h(5)
70 Out[13]: 25
69 Out[13]: 25
71
70
72 In [14]: h(1)
71 In [14]: h(1)
73 Out[14]: -1
72 Out[14]: -1
74
73
75 In [15]: h(0)
74 In [15]: h(0)
76 Out[15]: -1
75 Out[15]: -1
77 """
76 """
General Comments 0
You need to be logged in to leave comments. Login now