##// END OF EJS Templates
Add builtins._ doctest...
Nikita Kniazev -
Show More
@@ -1,76 +1,92 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
9
10 def doctest_simple():
10 def doctest_simple():
11 """ipdoctest must handle simple inputs
11 """ipdoctest must handle simple inputs
12
12
13 In [1]: 1
13 In [1]: 1
14 Out[1]: 1
14 Out[1]: 1
15
15
16 In [2]: print(1)
16 In [2]: print(1)
17 1
17 1
18 """
18 """
19
19
20 def doctest_multiline1():
20 def doctest_multiline1():
21 """The ipdoctest machinery must handle multiline examples gracefully.
21 """The ipdoctest machinery must handle multiline examples gracefully.
22
22
23 In [2]: for i in range(4):
23 In [2]: for i in range(4):
24 ...: print(i)
24 ...: print(i)
25 ...:
25 ...:
26 0
26 0
27 1
27 1
28 2
28 2
29 3
29 3
30 """
30 """
31
31
32 def doctest_multiline2():
32 def doctest_multiline2():
33 """Multiline examples that define functions and print output.
33 """Multiline examples that define functions and print output.
34
34
35 In [7]: def f(x):
35 In [7]: def f(x):
36 ...: return x+1
36 ...: return x+1
37 ...:
37 ...:
38
38
39 In [8]: f(1)
39 In [8]: f(1)
40 Out[8]: 2
40 Out[8]: 2
41
41
42 In [9]: def g(x):
42 In [9]: def g(x):
43 ...: print('x is:',x)
43 ...: print('x is:',x)
44 ...:
44 ...:
45
45
46 In [10]: g(1)
46 In [10]: g(1)
47 x is: 1
47 x is: 1
48
48
49 In [11]: g('hello')
49 In [11]: g('hello')
50 x is: hello
50 x is: hello
51 """
51 """
52
52
53
53
54 def doctest_multiline3():
54 def doctest_multiline3():
55 """Multiline examples with blank lines.
55 """Multiline examples with blank lines.
56
56
57 In [12]: def h(x):
57 In [12]: def h(x):
58 ....: if x>1:
58 ....: if x>1:
59 ....: return x**2
59 ....: return x**2
60 ....: # 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
61 ....: # with a comment character:
61 ....: # with a comment character:
62 ....: #
62 ....: #
63 ....: # otherwise the doctest parser gets confused.
63 ....: # otherwise the doctest parser gets confused.
64 ....: else:
64 ....: else:
65 ....: return -1
65 ....: return -1
66 ....:
66 ....:
67
67
68 In [13]: h(5)
68 In [13]: h(5)
69 Out[13]: 25
69 Out[13]: 25
70
70
71 In [14]: h(1)
71 In [14]: h(1)
72 Out[14]: -1
72 Out[14]: -1
73
73
74 In [15]: h(0)
74 In [15]: h(0)
75 Out[15]: -1
75 Out[15]: -1
76 """
76 """
77
78
79 def doctest_builtin_underscore():
80 """Defining builtins._ should not break anything outside the doctest
81 while also should be working as expected inside the doctest.
82
83 In [1]: import builtins
84
85 In [2]: builtins._ = 42
86
87 In [3]: builtins._
88 Out[3]: 42
89
90 In [4]: _
91 Out[4]: 42
92 """
General Comments 0
You need to be logged in to leave comments. Login now