Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 32497c8

Browse files
authored
Merge pull request #13213 from Kojoley/fix-bunch-of-doctests
Fix bunch of doctests
2 parents 967787c + fda2ebe commit 32497c8

7 files changed

Lines changed: 47 additions & 37 deletions

File tree

IPython/lib/display.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -69,31 +69,33 @@ class Audio(DisplayObject):
6969
Generate a sound
7070
7171
>>> import numpy as np
72-
... framerate = 44100
73-
... t = np.linspace(0,5,framerate*5)
74-
... data = np.sin(2*np.pi*220*t) + np.sin(2*np.pi*224*t)
75-
... Audio(data, rate=framerate)
72+
>>> framerate = 44100
73+
>>> t = np.linspace(0,5,framerate*5)
74+
>>> data = np.sin(2*np.pi*220*t) + np.sin(2*np.pi*224*t)
75+
>>> Audio(data, rate=framerate)
76+
<IPython.lib.display.Audio object>
7677
7778
Can also do stereo or more channels
7879
7980
>>> dataleft = np.sin(2*np.pi*220*t)
80-
... dataright = np.sin(2*np.pi*224*t)
81-
... Audio([dataleft, dataright], rate=framerate)
81+
>>> dataright = np.sin(2*np.pi*224*t)
82+
>>> Audio([dataleft, dataright], rate=framerate)
83+
<IPython.lib.display.Audio object>
8284
8385
From URL:
8486
85-
>>> Audio("http://www.nch.com.au/acm/8k16bitpcm.wav")
86-
>>> Audio(url="http://www.w3schools.com/html/horse.ogg")
87+
>>> Audio("http://www.nch.com.au/acm/8k16bitpcm.wav") # doctest: +SKIP
88+
>>> Audio(url="http://www.w3schools.com/html/horse.ogg") # doctest: +SKIP
8789
8890
From a File:
8991
90-
>>> Audio('/path/to/sound.wav')
91-
>>> Audio(filename='/path/to/sound.ogg')
92+
>>> Audio('/path/to/sound.wav') # doctest: +SKIP
93+
>>> Audio(filename='/path/to/sound.ogg') # doctest: +SKIP
9294
9395
From Bytes:
9496
95-
>>> Audio(b'RAW_WAV_DATA..')
96-
>>> Audio(data=b'RAW_WAV_DATA..')
97+
>>> Audio(b'RAW_WAV_DATA..') # doctest: +SKIP
98+
>>> Audio(data=b'RAW_WAV_DATA..') # doctest: +SKIP
9799
98100
See Also
99101
--------

IPython/lib/lexers.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -221,11 +221,9 @@ class IPythonConsoleLexer(Lexer):
221221
In [2]: a
222222
Out[2]: 'foo'
223223
224-
In [3]: print a
224+
In [3]: print(a)
225225
foo
226226
227-
In [4]: 1 / 0
228-
229227
230228
Support is also provided for IPython exceptions:
231229
@@ -234,13 +232,9 @@ class IPythonConsoleLexer(Lexer):
234232
.. code-block:: ipythonconsole
235233
236234
In [1]: raise Exception
237-
238-
---------------------------------------------------------------------------
239-
Exception Traceback (most recent call last)
240-
<ipython-input-1-fca2ab0ca76b> in <module>
241-
----> 1 raise Exception
242-
243-
Exception:
235+
Traceback (most recent call last):
236+
...
237+
Exception
244238
245239
"""
246240
name = 'IPython console session'

IPython/lib/security.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def passwd(passphrase=None, algorithm='sha1'):
4848
Examples
4949
--------
5050
>>> passwd('mypassword')
51-
'sha1:7cf3:b7d6da294ea9592a9480c8f52e63cd42cfb9dd12'
51+
'sha1:7cf3:b7d6da294ea9592a9480c8f52e63cd42cfb9dd12' # random
5252
5353
"""
5454
if passphrase is None:

IPython/testing/plugin/dtexample.py

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
All tests should be loaded by nose.
55
"""
66

7+
import os
8+
9+
710
def pyfunc():
811
"""Some pure python tests...
912
@@ -38,18 +41,6 @@ def ipfunc():
3841
0 1 1 2 2 3
3942
4043
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-
5344
It's OK to use '_' for the last result, but do NOT try to use IPython's
5445
numbered history of _NN outputs, since those won't exist under the
5546
doctest environment:
@@ -72,6 +63,25 @@ def ipfunc():
7263
return 'ipfunc'
7364

7465

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+
7585
def ranfunc():
7686
"""A function with some random output.
7787

IPython/testing/plugin/test_exampleip.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Another example::
2121

2222
Just like in IPython docstrings, you can use all IPython syntax and features::
2323

24-
In [9]: !echo "hello"
24+
In [9]: !echo hello
2525
hello
2626

2727
In [10]: a='hi'

IPython/testing/tests/test_decorators.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
# Our own
1313
from IPython.testing import decorators as dec
14+
from IPython.testing.skipdoctest import skip_doctest
1415

1516
#-----------------------------------------------------------------------------
1617
# Utilities
@@ -59,6 +60,7 @@ def test_deliberately_broken2():
5960

6061
# Verify that we can correctly skip the doctest for a function at will, but
6162
# that the docstring itself is NOT destroyed by the decorator.
63+
@skip_doctest
6264
def doctest_bad(x,y=1,**k):
6365
"""A function whose doctest we need to skip.
6466
@@ -106,6 +108,7 @@ class FooClass(object):
106108
2
107109
"""
108110

111+
@skip_doctest
109112
def __init__(self,x):
110113
"""Make a FooClass.
111114
@@ -117,6 +120,7 @@ def __init__(self,x):
117120
print('Making a FooClass.')
118121
self.x = x
119122

123+
@skip_doctest
120124
def bar(self,y):
121125
"""Example:
122126

IPython/utils/path.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def _get_long_path_name(path):
3333
Examples
3434
--------
3535
36-
>>> get_long_path_name('c:\\docume~1')
36+
>>> get_long_path_name('c:\\\\docume~1')
3737
'c:\\\\Documents and Settings'
3838
3939
"""

0 commit comments

Comments
 (0)