[docs] Fixed all the doctest failures in Doc/library/configparser.rst (issue 28860)

marco.buttu at gmail.com marco.buttu at gmail.com
Mon Dec 5 07:20:11 EST 2016


Reviewers: berkerpeksag,


http://bugs.python.org/review/28860/diff/19350/Doc/library/configparser.rst
File Doc/library/configparser.rst (left):

http://bugs.python.org/review/28860/diff/19350/Doc/library/configparser.rst#oldcode73
Doc/library/configparser.rst:73: >>> import configparser
On 2016/12/05 12:27:28, berkerpeksag wrote:
> Can this be removed now? (since we've already import it in testsetup?)

I think it is really important to keep it at the beginning, because the
code we show to the reader has to be working code. The user has to
import configparser in the shell before executing manually the example.
The import in the testsetup has just the purpose to avoid the same
import in all the examples, when they belong to the same session.

http://bugs.python.org/review/28860/diff/19350/Doc/library/configparser.rst
File Doc/library/configparser.rst (right):

http://bugs.python.org/review/28860/diff/19350/Doc/library/configparser.rst#newcode476
Doc/library/configparser.rst:476: >>> sorted(parser.sections())
On 2016/12/05 12:27:28, berkerpeksag wrote:
> I'd skip this one like you did in your first patch.
> 
> As a reader, I find using sorted() here less readable and more
confusing.
> 
> +1 for using sorted() in the iteration examples (but I'd skip them too
since
> they may have already tested in Lib/test/test_configparser.py)


I agree with you, it is less readable and more confusing. Sometimes we
need a treadoff, and when the API is enough stable that the test result,
in all likelihood, will not change in future Python versions, we can
take the risk to skip the test.



Please review this at http://bugs.python.org/review/28860/

Affected files:
  Doc/library/configparser.rst


diff -r 16350c1f81a1 Doc/library/configparser.rst
--- a/Doc/library/configparser.rst	Sun Dec 04 10:22:36 2016 +0200
+++ b/Doc/library/configparser.rst	Sun Dec 04 10:12:10 2016 +0100
@@ -68,6 +68,10 @@
 :mod:`configparser` classes can read and write such files.  Let's start by
 creating the above configuration file programmatically.
 
+.. testsetup::
+
+   import configparser
+
 .. doctest::
 
    >>> import configparser
@@ -116,13 +120,13 @@
    'no'
    >>> topsecret['Port']
    '50022'
-   >>> for key in config['bitbucket.org']: print(key)
-   ...
+   >>> for key in sorted(config['bitbucket.org']): 
+   ...     print(key)
+   compression
+   compressionlevel
+   forwardx11
+   serveraliveinterval
    user
-   compressionlevel
-   serveraliveinterval
-   compression
-   forwardx11
    >>> config['bitbucket.org']['ForwardX11']
    'yes'
 
@@ -469,10 +473,10 @@
      ...                                'bar': 'y',
      ...                                'baz': 'z'}
      ... })
-     >>> parser.sections()
-     ['section3', 'section2', 'section1']
-     >>> [option for option in parser['section3']]
-     ['baz', 'foo', 'bar']
+     >>> sorted(parser.sections())
+     ['section1', 'section2', 'section3']
+     >>> sorted(option for option in parser['section3'])
+     ['bar', 'baz', 'foo']
 
   In these operations you need to use an ordered dictionary as well:
 
@@ -514,8 +518,6 @@
 
   .. doctest::
 
-     >>> import configparser
-
      >>> sample_config = """
      ... [mysqld]
      ...   user = mysql
@@ -571,7 +573,9 @@
   values with characters used as comment prefixes.  When in doubt, avoid
   setting *inline_comment_prefixes*.  In any circumstances, the only way of
   storing comment prefix characters at the beginning of a line in multiline
-  values is to interpolate the prefix, for example::
+  values is to interpolate the prefix, for example:
+
+  .. doctest::
 
     >>> from configparser import ConfigParser, ExtendedInterpolation
     >>> parser = ConfigParser(interpolation=ExtendedInterpolation())
@@ -597,11 +601,11 @@
     ...   line #3
     ... """)
     >>> print(parser['hashes']['shebang'])
-
+    <BLANKLINE>
     #!/usr/bin/env python
     # -*- coding: utf-8 -*-
     >>> print(parser['hashes']['extensions'])
-
+    <BLANKLINE>
     enabled_extension
     another_extension
     yet_another_extension
@@ -755,6 +759,7 @@
 
   .. doctest::
 
+     >>> import re
      >>> config = """
      ... [Section 1]
      ... option = value
@@ -762,11 +767,11 @@
      ... [  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<header>[^]]+?) *\]")
      >>> custom.read_string(config)
      >>> custom.sections()




More information about the docs mailing list