From 45d0735a31f2e5336960863fa7d51bbf3a0a6d74 Mon Sep 17 00:00:00 2001 From: Marco Buttu Date: Fri, 10 Mar 2017 19:29:05 +0100 Subject: [PATCH 01/13] bpo-27200: fix email.compat32-message.rst doctests --- Doc/library/email.compat32-message.rst | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/Doc/library/email.compat32-message.rst b/Doc/library/email.compat32-message.rst index b0707646e64ac65..9428e0489870dd6 100644 --- a/Doc/library/email.compat32-message.rst +++ b/Doc/library/email.compat32-message.rst @@ -660,10 +660,10 @@ Here are the methods of the :class:`Message` class: .. testsetup:: - >>> from email import message_from_binary_file - >>> with open('Lib/test/test_email/data/msg_16.txt', 'rb') as f: - ... msg = message_from_binary_file(f) - >>> from email.iterators import _structure + from email import message_from_binary_file + with open('../Lib/test/test_email/data/msg_16.txt', 'rb') as f: + msg = message_from_binary_file(f) + from email.iterators import _structure .. doctest:: @@ -686,7 +686,7 @@ Here are the methods of the :class:`Message` class: .. doctest:: >>> for part in msg.walk(): - ... print(part.get_content_maintype() == 'multipart'), + ... print(part.get_content_maintype() == 'multipart', ... part.is_multipart()) True True False False @@ -698,11 +698,11 @@ Here are the methods of the :class:`Message` class: >>> _structure(msg) multipart/report text/plain - message/delivery-status - text/plain - text/plain - message/rfc822 - text/plain + message/delivery-status + text/plain + text/plain + message/rfc822 + text/plain Here the ``message`` parts are not ``multiparts``, but they do contain subparts. ``is_multipart()`` returns ``True`` and ``walk`` descends From 165a43907c72d4363d65415d03eb49ccf87658c8 Mon Sep 17 00:00:00 2001 From: Marco Buttu Date: Fri, 10 Mar 2017 19:33:06 +0100 Subject: [PATCH 02/13] bpo-27200: fix functions.rst doctests --- Doc/library/functions.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/functions.rst b/Doc/library/functions.rst index c26037bd9eef192..dc84f2ed76ab0f7 100644 --- a/Doc/library/functions.rst +++ b/Doc/library/functions.rst @@ -328,7 +328,7 @@ are always available. They are listed here in alphabetical order. The resulting list is sorted alphabetically. For example: >>> import struct - >>> dir() # show the names in the module namespace + >>> dir() # show the names in the module namespace # doctest: +SKIP ['__builtins__', '__name__', 'struct'] >>> dir(struct) # show the names in the struct module # doctest: +SKIP ['Struct', '__all__', '__builtins__', '__cached__', '__doc__', '__file__', From ba6efbc4861b9d44039bd55d103f95447cdb3f6a Mon Sep 17 00:00:00 2001 From: Marco Buttu Date: Fri, 10 Mar 2017 19:39:44 +0100 Subject: [PATCH 03/13] bpo-27200: fix ipaddress.rst doctests --- Doc/library/ipaddress.rst | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Doc/library/ipaddress.rst b/Doc/library/ipaddress.rst index 50fb778dfbad892..e788327fc088f0c 100644 --- a/Doc/library/ipaddress.rst +++ b/Doc/library/ipaddress.rst @@ -25,9 +25,10 @@ This is the full module API reference—for an overview and introduction, see .. versionadded:: 3.3 .. testsetup:: - >>> import ipaddress - >>> from ipaddress import (ip_network, IPv4Address, IPv4Interface, - ... IPv4Network) + + import ipaddress + from ipaddress import (ip_network, IPv4Address, IPv4Interface, + IPv4Network) Convenience factory functions ----------------------------- From 38e42a0c308280fb0aba16e0c432c6fd07131199 Mon Sep 17 00:00:00 2001 From: Marco Buttu Date: Fri, 10 Mar 2017 19:47:40 +0100 Subject: [PATCH 04/13] bpo-27200: fix reprlib.rst doctests --- Doc/library/reprlib.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/Doc/library/reprlib.rst b/Doc/library/reprlib.rst index 0905b982cd830a2..5149bcf10f662a4 100644 --- a/Doc/library/reprlib.rst +++ b/Doc/library/reprlib.rst @@ -48,6 +48,7 @@ string instead. same thread. If a recursive call is made, the *fillvalue* is returned, otherwise, the usual :meth:`__repr__` call is made. For example: + >>> from reprlib import recursive_repr >>> class MyList(list): ... @recursive_repr() ... def __repr__(self): From 446db4519c8424ad89cd03ed3036321049f57d91 Mon Sep 17 00:00:00 2001 From: Marco Buttu Date: Fri, 10 Mar 2017 20:22:29 +0100 Subject: [PATCH 05/13] bpo-27200: fix whatsnew/3.2.rst doctests --- Doc/whatsnew/3.2.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/whatsnew/3.2.rst b/Doc/whatsnew/3.2.rst index b900e7733f0f3e6..72a8a8ba4c97e1b 100644 --- a/Doc/whatsnew/3.2.rst +++ b/Doc/whatsnew/3.2.rst @@ -1384,7 +1384,7 @@ guaranteed not to block when :func:`select.select` says a pipe is ready for writing. >>> import select ->>> select.PIPE_BUF +>>> select.PIPE_BUF # doctest: +SKIP 512 (Available on Unix systems. Patch by Sébastien Sablé in :issue:`9862`) From f47f49e9277b77068b9d79a338b46fc8f1827813 Mon Sep 17 00:00:00 2001 From: Marco Buttu Date: Fri, 10 Mar 2017 20:36:03 +0100 Subject: [PATCH 06/13] bpo-27200: fix urllib.parse.rst doctests --- Doc/library/urllib.parse.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Doc/library/urllib.parse.rst b/Doc/library/urllib.parse.rst index 7a5b56f5da69b1e..6754e263878b72a 100644 --- a/Doc/library/urllib.parse.rst +++ b/Doc/library/urllib.parse.rst @@ -64,6 +64,9 @@ or on combining URL components into a URL string. input is presumed to be a relative URL and thus to start with a path component. + .. doctest:: + :options: +NORMALIZE_WHITESPACE + >>> from urllib.parse import urlparse >>> urlparse('//www.cwi.nl:80/%7Eguido/Python.html') ParseResult(scheme='', netloc='www.cwi.nl:80', path='/%7Eguido/Python.html', From 5ad6d1b3a17663685928d0e02d8513b738ea34b1 Mon Sep 17 00:00:00 2001 From: Marco Buttu Date: Fri, 10 Mar 2017 20:42:01 +0100 Subject: [PATCH 07/13] bpo-27200: fix shlex.rst doctests --- Doc/library/shlex.rst | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Doc/library/shlex.rst b/Doc/library/shlex.rst index 55012f80e8f923f..fb335c690068165 100644 --- a/Doc/library/shlex.rst +++ b/Doc/library/shlex.rst @@ -43,15 +43,16 @@ The :mod:`shlex` module defines the following functions: string that can safely be used as one token in a shell command line, for cases where you cannot use a list. - This idiom would be unsafe:: + This idiom would be unsafe: >>> filename = 'somefile; rm -rf ~' >>> command = 'ls -l {}'.format(filename) >>> print(command) # executed by a shell: boom! ls -l somefile; rm -rf ~ - :func:`quote` lets you plug the security hole:: + :func:`quote` lets you plug the security hole: + >>> from shlex import quote >>> command = 'ls -l {}'.format(quote(filename)) >>> print(command) ls -l 'somefile; rm -rf ~' @@ -61,6 +62,7 @@ The :mod:`shlex` module defines the following functions: The quoting is compatible with UNIX shells and with :func:`split`: + >>> from shlex import split >>> remote_command = split(remote_command) >>> remote_command ['ssh', 'home', "ls -l 'somefile; rm -rf ~'"] From 73aacd4926b38108831b7422975db1e10eb6eac9 Mon Sep 17 00:00:00 2001 From: Marco Buttu Date: Sat, 11 Mar 2017 08:43:35 +0100 Subject: [PATCH 08/13] bpo-27200: get the absolute file path in testsetup --- Doc/library/email.compat32-message.rst | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Doc/library/email.compat32-message.rst b/Doc/library/email.compat32-message.rst index 9428e0489870dd6..094b840160e814f 100644 --- a/Doc/library/email.compat32-message.rst +++ b/Doc/library/email.compat32-message.rst @@ -660,8 +660,12 @@ Here are the methods of the :class:`Message` class: .. testsetup:: + import email from email import message_from_binary_file - with open('../Lib/test/test_email/data/msg_16.txt', 'rb') as f: + from os.path import join, dirname + lib_dir = dirname(email.__file__).rstrip('/email') + file_path = join(lib_dir, 'test/test_email/data/msg_16.txt') + with open(file_path, 'rb') as f: msg = message_from_binary_file(f) from email.iterators import _structure From b94e3081b36e299dab1f4072e60118fd1c750b53 Mon Sep 17 00:00:00 2001 From: Marco Buttu Date: Wed, 22 Mar 2017 13:03:33 +0100 Subject: [PATCH 09/13] bpo-27200: use hanging indentation in ipaddress.rst --- Doc/library/ipaddress.rst | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Doc/library/ipaddress.rst b/Doc/library/ipaddress.rst index e788327fc088f0c..d07cf2e55bdd5d7 100644 --- a/Doc/library/ipaddress.rst +++ b/Doc/library/ipaddress.rst @@ -27,8 +27,9 @@ This is the full module API reference—for an overview and introduction, see .. testsetup:: import ipaddress - from ipaddress import (ip_network, IPv4Address, IPv4Interface, - IPv4Network) + from ipaddress import ( + ip_network, IPv4Address, IPv4Interface, IPv4Network, + ) Convenience factory functions ----------------------------- From 5c38137e649bd573510054733baddccfdb1d4175 Mon Sep 17 00:00:00 2001 From: Marco Buttu Date: Wed, 22 Mar 2017 13:04:24 +0100 Subject: [PATCH 10/13] bpo-27200: skipped a test that can fail. --- Doc/whatsnew/3.2.rst | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/Doc/whatsnew/3.2.rst b/Doc/whatsnew/3.2.rst index 72a8a8ba4c97e1b..f870f3127ac22b4 100644 --- a/Doc/whatsnew/3.2.rst +++ b/Doc/whatsnew/3.2.rst @@ -1060,15 +1060,15 @@ of nearly equal quantities: The :func:`~math.erf` function computes a probability integral or `Gaussian error function `_. The -complementary error function, :func:`~math.erfc`, is ``1 - erf(x)``: - ->>> from math import erf, erfc, sqrt ->>> erf(1.0/sqrt(2.0)) # portion of normal distribution within 1 standard deviation -0.682689492137086 ->>> erfc(1.0/sqrt(2.0)) # portion of normal distribution outside 1 standard deviation -0.31731050786291404 ->>> erf(1.0/sqrt(2.0)) + erfc(1.0/sqrt(2.0)) -1.0 +complementary error function, :func:`~math.erfc`, is ``1 - erf(x)``:: + + >>> from math import erf, erfc, sqrt + >>> erf(1.0/sqrt(2.0)) # portion of normal distribution within 1 standard deviation + 0.682689492137086 + >>> erfc(1.0/sqrt(2.0)) # portion of normal distribution outside 1 standard deviation + 0.31731050786291404 + >>> erf(1.0/sqrt(2.0)) + erfc(1.0/sqrt(2.0)) + 1.0 The :func:`~math.gamma` function is a continuous extension of the factorial function. See https://en.wikipedia.org/wiki/Gamma_function for details. Because From fbae43f2ce3bbe411554fcd320b97516be26c129 Mon Sep 17 00:00:00 2001 From: Marco Buttu Date: Thu, 13 Apr 2017 17:21:40 +0200 Subject: [PATCH 11/13] bpo-27200: use doctest SKIP option instead of :: --- Doc/whatsnew/3.2.rst | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/Doc/whatsnew/3.2.rst b/Doc/whatsnew/3.2.rst index f870f3127ac22b4..a70a50177312750 100644 --- a/Doc/whatsnew/3.2.rst +++ b/Doc/whatsnew/3.2.rst @@ -1060,15 +1060,18 @@ of nearly equal quantities: The :func:`~math.erf` function computes a probability integral or `Gaussian error function `_. The -complementary error function, :func:`~math.erfc`, is ``1 - erf(x)``:: - - >>> from math import erf, erfc, sqrt - >>> erf(1.0/sqrt(2.0)) # portion of normal distribution within 1 standard deviation - 0.682689492137086 - >>> erfc(1.0/sqrt(2.0)) # portion of normal distribution outside 1 standard deviation - 0.31731050786291404 - >>> erf(1.0/sqrt(2.0)) + erfc(1.0/sqrt(2.0)) - 1.0 +complementary error function, :func:`~math.erfc`, is ``1 - erf(x)``: + +.. doctest: + :options: +SKIP + + >>> from math import erf, erfc, sqrt + >>> erf(1.0/sqrt(2.0)) # portion of normal distribution within 1 standard deviation + 0.682689492137086 + >>> erfc(1.0/sqrt(2.0)) # portion of normal distribution outside 1 standard deviation + 0.31731050786291404 + >>> erf(1.0/sqrt(2.0)) + erfc(1.0/sqrt(2.0)) + 1.0 The :func:`~math.gamma` function is a continuous extension of the factorial function. See https://en.wikipedia.org/wiki/Gamma_function for details. Because From 2aab0c41a5df10e82dce4e487a9efc062a2492ad Mon Sep 17 00:00:00 2001 From: Marco Buttu Date: Mon, 24 Apr 2017 11:20:28 +0200 Subject: [PATCH 12/13] bpo-27200: fix wrong doctest directive syntax --- Doc/whatsnew/3.2.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/whatsnew/3.2.rst b/Doc/whatsnew/3.2.rst index a70a50177312750..78d3105a5a410b1 100644 --- a/Doc/whatsnew/3.2.rst +++ b/Doc/whatsnew/3.2.rst @@ -1062,7 +1062,7 @@ The :func:`~math.erf` function computes a probability integral or `Gaussian error function `_. The complementary error function, :func:`~math.erfc`, is ``1 - erf(x)``: -.. doctest: +.. doctest:: :options: +SKIP >>> from math import erf, erfc, sqrt From 2cd4aec4c95f93576eff23bd1818b56a64f49ba4 Mon Sep 17 00:00:00 2001 From: Marco Buttu Date: Thu, 27 Apr 2017 11:18:58 +0200 Subject: [PATCH 13/13] bpo-27200: fix bug in testsetup --- Doc/library/email.compat32-message.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/email.compat32-message.rst b/Doc/library/email.compat32-message.rst index 094b840160e814f..2394e4d7077b4c4 100644 --- a/Doc/library/email.compat32-message.rst +++ b/Doc/library/email.compat32-message.rst @@ -663,7 +663,7 @@ Here are the methods of the :class:`Message` class: import email from email import message_from_binary_file from os.path import join, dirname - lib_dir = dirname(email.__file__).rstrip('/email') + lib_dir = dirname(dirname(email.__file__)) file_path = join(lib_dir, 'test/test_email/data/msg_16.txt') with open(file_path, 'rb') as f: msg = message_from_binary_file(f)