From 110ff1c8109351b33793b2459822221e346deddf Mon Sep 17 00:00:00 2001 From: Marco Buttu Date: Wed, 22 Feb 2017 21:30:00 +0100 Subject: [PATCH 1/3] bpo-27200: fix configparser, copyreg and ctypes doctests --- Doc/library/configparser.rst | 29 +++++++++++++++++------------ Doc/library/copyreg.rst | 4 ++-- Doc/library/ctypes.rst | 4 ++++ 3 files changed, 23 insertions(+), 14 deletions(-) diff --git a/Doc/library/configparser.rst b/Doc/library/configparser.rst index e09562dc9046c7..32c658e8dff690 100644 --- a/Doc/library/configparser.rst +++ b/Doc/library/configparser.rst @@ -42,6 +42,11 @@ can be customized by end users easily. be used for this purpose. +.. testsetup:: + + import configparser + + Quick Start ----------- @@ -95,7 +100,6 @@ back and explore the data it holds. .. doctest:: - >>> import configparser >>> config = configparser.ConfigParser() >>> config.sections() [] @@ -116,8 +120,8 @@ back and explore the data it holds. 'no' >>> topsecret['Port'] '50022' - >>> for key in config['bitbucket.org']: print(key) - ... + >>> for key in config['bitbucket.org']: # doctest: +SKIP + ... print(key) user compressionlevel serveraliveinterval @@ -469,9 +473,9 @@ the :meth:`__init__` options: ... 'bar': 'y', ... 'baz': 'z'} ... }) - >>> parser.sections() + >>> parser.sections() # doctest: +SKIP ['section3', 'section2', 'section1'] - >>> [option for option in parser['section3']] + >>> [option for option in parser['section3']] # doctest: +SKIP ['baz', 'foo', 'bar'] In these operations you need to use an ordered dictionary as well: @@ -498,11 +502,11 @@ the :meth:`__init__` options: ... ), ... )) ... ) - >>> parser.sections() + >>> parser.sections() # doctest: +SKIP ['s1', 's2'] - >>> [option for option in parser['s1']] + >>> [option for option in parser['s1']] # doctest: +SKIP ['1', '3', '5'] - >>> [option for option in parser['s2'].values()] + >>> [option for option in parser['s2'].values()] # doctest: +SKIP ['b', 'd', 'f'] * *allow_no_value*, default value: ``False`` @@ -597,11 +601,11 @@ the :meth:`__init__` options: ... line #3 ... """) >>> print(parser['hashes']['shebang']) - + #!/usr/bin/env python # -*- coding: utf-8 -*- >>> print(parser['hashes']['extensions']) - + enabled_extension another_extension yet_another_extension @@ -755,6 +759,7 @@ be overridden by subclasses or by attribute assignment. .. doctest:: + >>> import re >>> config = """ ... [Section 1] ... option = value @@ -762,11 +767,11 @@ be overridden by subclasses or by attribute assignment. ... [ Section 2 ] ... another = val ... """ - >>> typical = ConfigParser() + >>> typical = configparser.ConfigParser() >>> typical.read_string(config) >>> typical.sections() ['Section 1', ' Section 2 '] - >>> custom = ConfigParser() + >>> custom = configparser.ConfigParser() >>> custom.SECTCRE = re.compile(r"\[ *(?P
[^]]+?) *\]") >>> custom.read_string(config) >>> custom.sections() diff --git a/Doc/library/copyreg.rst b/Doc/library/copyreg.rst index eeabb4c6580cd6..40fca56d8029e9 100644 --- a/Doc/library/copyreg.rst +++ b/Doc/library/copyreg.rst @@ -59,7 +59,7 @@ it will be used: ... >>> copyreg.pickle(C, pickle_c) >>> c = C(1) - >>> d = copy.copy(c) + >>> d = copy.copy(c) # doctest: +SKIP pickling a C instance... - >>> p = pickle.dumps(c) + >>> p = pickle.dumps(c) # doctest: +SKIP pickling a C instance... diff --git a/Doc/library/ctypes.rst b/Doc/library/ctypes.rst index 3840935ce04eb6..e157cc70d32e6f 100644 --- a/Doc/library/ctypes.rst +++ b/Doc/library/ctypes.rst @@ -1408,6 +1408,10 @@ accessing the function through an attribute caches the result and therefore accessing it repeatedly returns the same object each time. On the other hand, accessing it through an index returns a new object each time: +.. doctest:: + + >>> from ctypes import CDLL + >>> libc = CDLL("libc.so.6") # On Linux >>> libc.time == libc.time True >>> libc['time'] == libc['time'] From 27e105b96f9396efd7b10d523a33450b708f695d Mon Sep 17 00:00:00 2001 From: Marco Buttu Date: Mon, 27 Feb 2017 15:47:40 +0100 Subject: [PATCH 2/3] bpo-27200: remove unnecessary doctest directive, fix indentation --- Doc/library/configparser.rst | 2 +- Doc/library/ctypes.rst | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/Doc/library/configparser.rst b/Doc/library/configparser.rst index 32c658e8dff690..c0ffded7bc38e8 100644 --- a/Doc/library/configparser.rst +++ b/Doc/library/configparser.rst @@ -44,7 +44,7 @@ can be customized by end users easily. .. testsetup:: - import configparser + import configparser Quick Start diff --git a/Doc/library/ctypes.rst b/Doc/library/ctypes.rst index e157cc70d32e6f..7e96a9a93c5654 100644 --- a/Doc/library/ctypes.rst +++ b/Doc/library/ctypes.rst @@ -1408,8 +1408,6 @@ accessing the function through an attribute caches the result and therefore accessing it repeatedly returns the same object each time. On the other hand, accessing it through an index returns a new object each time: -.. doctest:: - >>> from ctypes import CDLL >>> libc = CDLL("libc.so.6") # On Linux >>> libc.time == libc.time From 6a8025f37819084d23b09fea190d222eba52582f Mon Sep 17 00:00:00 2001 From: Marco Buttu Date: Mon, 27 Feb 2017 19:32:48 +0100 Subject: [PATCH 3/3] bpo-27200: Change : to :: --- Doc/library/ctypes.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/ctypes.rst b/Doc/library/ctypes.rst index 7e96a9a93c5654..4ab8535f0a07bf 100644 --- a/Doc/library/ctypes.rst +++ b/Doc/library/ctypes.rst @@ -1406,7 +1406,7 @@ Instances of these classes have no public methods. Functions exported by the shared library can be accessed as attributes or by index. Please note that accessing the function through an attribute caches the result and therefore accessing it repeatedly returns the same object each time. On the other hand, -accessing it through an index returns a new object each time: +accessing it through an index returns a new object each time:: >>> from ctypes import CDLL >>> libc = CDLL("libc.so.6") # On Linux