Skip to content

Commit e65fcde

Browse files
marco-buttuberkerpeksag
authored andcommitted
bpo-27200: Fix several doctests (GH-604)
1 parent 6fde770 commit e65fcde

File tree

7 files changed

+39
-24
lines changed

7 files changed

+39
-24
lines changed

Doc/library/email.compat32-message.rst

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -660,10 +660,14 @@ Here are the methods of the :class:`Message` class:
660660

661661
.. testsetup::
662662

663-
>>> from email import message_from_binary_file
664-
>>> with open('Lib/test/test_email/data/msg_16.txt', 'rb') as f:
665-
... msg = message_from_binary_file(f)
666-
>>> from email.iterators import _structure
663+
import email
664+
from email import message_from_binary_file
665+
from os.path import join, dirname
666+
lib_dir = dirname(dirname(email.__file__))
667+
file_path = join(lib_dir, 'test/test_email/data/msg_16.txt')
668+
with open(file_path, 'rb') as f:
669+
msg = message_from_binary_file(f)
670+
from email.iterators import _structure
667671

668672
.. doctest::
669673

@@ -686,7 +690,7 @@ Here are the methods of the :class:`Message` class:
686690
.. doctest::
687691

688692
>>> for part in msg.walk():
689-
... print(part.get_content_maintype() == 'multipart'),
693+
... print(part.get_content_maintype() == 'multipart',
690694
... part.is_multipart())
691695
True True
692696
False False
@@ -698,11 +702,11 @@ Here are the methods of the :class:`Message` class:
698702
>>> _structure(msg)
699703
multipart/report
700704
text/plain
701-
message/delivery-status
702-
text/plain
703-
text/plain
704-
message/rfc822
705-
text/plain
705+
message/delivery-status
706+
text/plain
707+
text/plain
708+
message/rfc822
709+
text/plain
706710

707711
Here the ``message`` parts are not ``multiparts``, but they do contain
708712
subparts. ``is_multipart()`` returns ``True`` and ``walk`` descends

Doc/library/functions.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ are always available. They are listed here in alphabetical order.
331331
The resulting list is sorted alphabetically. For example:
332332

333333
>>> import struct
334-
>>> dir() # show the names in the module namespace
334+
>>> dir() # show the names in the module namespace # doctest: +SKIP
335335
['__builtins__', '__name__', 'struct']
336336
>>> dir(struct) # show the names in the struct module # doctest: +SKIP
337337
['Struct', '__all__', '__builtins__', '__cached__', '__doc__', '__file__',

Doc/library/ipaddress.rst

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,11 @@ This is the full module API reference—for an overview and introduction, see
2525
.. versionadded:: 3.3
2626

2727
.. testsetup::
28-
>>> import ipaddress
29-
>>> from ipaddress import (ip_network, IPv4Address, IPv4Interface,
30-
... IPv4Network)
28+
29+
import ipaddress
30+
from ipaddress import (
31+
ip_network, IPv4Address, IPv4Interface, IPv4Network,
32+
)
3133

3234
Convenience factory functions
3335
-----------------------------

Doc/library/reprlib.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ string instead.
4848
same thread. If a recursive call is made, the *fillvalue* is returned,
4949
otherwise, the usual :meth:`__repr__` call is made. For example:
5050

51+
>>> from reprlib import recursive_repr
5152
>>> class MyList(list):
5253
... @recursive_repr()
5354
... def __repr__(self):

Doc/library/shlex.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,16 @@ The :mod:`shlex` module defines the following functions:
4343
string that can safely be used as one token in a shell command line, for
4444
cases where you cannot use a list.
4545

46-
This idiom would be unsafe::
46+
This idiom would be unsafe:
4747

4848
>>> filename = 'somefile; rm -rf ~'
4949
>>> command = 'ls -l {}'.format(filename)
5050
>>> print(command) # executed by a shell: boom!
5151
ls -l somefile; rm -rf ~
5252

53-
:func:`quote` lets you plug the security hole::
53+
:func:`quote` lets you plug the security hole:
5454

55+
>>> from shlex import quote
5556
>>> command = 'ls -l {}'.format(quote(filename))
5657
>>> print(command)
5758
ls -l 'somefile; rm -rf ~'
@@ -61,6 +62,7 @@ The :mod:`shlex` module defines the following functions:
6162

6263
The quoting is compatible with UNIX shells and with :func:`split`:
6364

65+
>>> from shlex import split
6466
>>> remote_command = split(remote_command)
6567
>>> remote_command
6668
['ssh', 'home', "ls -l 'somefile; rm -rf ~'"]

Doc/library/urllib.parse.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ or on combining URL components into a URL string.
6464
input is presumed to be a relative URL and thus to start with
6565
a path component.
6666

67+
.. doctest::
68+
:options: +NORMALIZE_WHITESPACE
69+
6770
>>> from urllib.parse import urlparse
6871
>>> urlparse('//www.cwi.nl:80/%7Eguido/Python.html')
6972
ParseResult(scheme='', netloc='www.cwi.nl:80', path='/%7Eguido/Python.html',

Doc/whatsnew/3.2.rst

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,13 +1062,16 @@ The :func:`~math.erf` function computes a probability integral or `Gaussian
10621062
error function <https://en.wikipedia.org/wiki/Error_function>`_. The
10631063
complementary error function, :func:`~math.erfc`, is ``1 - erf(x)``:
10641064

1065-
>>> from math import erf, erfc, sqrt
1066-
>>> erf(1.0/sqrt(2.0)) # portion of normal distribution within 1 standard deviation
1067-
0.682689492137086
1068-
>>> erfc(1.0/sqrt(2.0)) # portion of normal distribution outside 1 standard deviation
1069-
0.31731050786291404
1070-
>>> erf(1.0/sqrt(2.0)) + erfc(1.0/sqrt(2.0))
1071-
1.0
1065+
.. doctest::
1066+
:options: +SKIP
1067+
1068+
>>> from math import erf, erfc, sqrt
1069+
>>> erf(1.0/sqrt(2.0)) # portion of normal distribution within 1 standard deviation
1070+
0.682689492137086
1071+
>>> erfc(1.0/sqrt(2.0)) # portion of normal distribution outside 1 standard deviation
1072+
0.31731050786291404
1073+
>>> erf(1.0/sqrt(2.0)) + erfc(1.0/sqrt(2.0))
1074+
1.0
10721075

10731076
The :func:`~math.gamma` function is a continuous extension of the factorial
10741077
function. See https://en.wikipedia.org/wiki/Gamma_function for details. Because
@@ -1384,7 +1387,7 @@ guaranteed not to block when :func:`select.select` says a pipe is ready
13841387
for writing.
13851388

13861389
>>> import select
1387-
>>> select.PIPE_BUF
1390+
>>> select.PIPE_BUF # doctest: +SKIP
13881391
512
13891392

13901393
(Available on Unix systems. Patch by Sébastien Sablé in :issue:`9862`)

0 commit comments

Comments
 (0)