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