Skip to content

Commit b2a7c2f

Browse files
marco-buttuberkerpeksag
authored andcommitted
bpo-27200: fix configparser, copyreg and ctypes doctests (#240)
1 parent 6a9122c commit b2a7c2f

File tree

3 files changed

+22
-15
lines changed

3 files changed

+22
-15
lines changed

Doc/library/configparser.rst

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ can be customized by end users easily.
4242
be used for this purpose.
4343

4444

45+
.. testsetup::
46+
47+
import configparser
48+
49+
4550
Quick Start
4651
-----------
4752

@@ -95,7 +100,6 @@ back and explore the data it holds.
95100

96101
.. doctest::
97102

98-
>>> import configparser
99103
>>> config = configparser.ConfigParser()
100104
>>> config.sections()
101105
[]
@@ -116,8 +120,8 @@ back and explore the data it holds.
116120
'no'
117121
>>> topsecret['Port']
118122
'50022'
119-
>>> for key in config['bitbucket.org']: print(key)
120-
...
123+
>>> for key in config['bitbucket.org']: # doctest: +SKIP
124+
... print(key)
121125
user
122126
compressionlevel
123127
serveraliveinterval
@@ -469,9 +473,9 @@ the :meth:`__init__` options:
469473
... 'bar': 'y',
470474
... 'baz': 'z'}
471475
... })
472-
>>> parser.sections()
476+
>>> parser.sections() # doctest: +SKIP
473477
['section3', 'section2', 'section1']
474-
>>> [option for option in parser['section3']]
478+
>>> [option for option in parser['section3']] # doctest: +SKIP
475479
['baz', 'foo', 'bar']
476480

477481
In these operations you need to use an ordered dictionary as well:
@@ -498,11 +502,11 @@ the :meth:`__init__` options:
498502
... ),
499503
... ))
500504
... )
501-
>>> parser.sections()
505+
>>> parser.sections() # doctest: +SKIP
502506
['s1', 's2']
503-
>>> [option for option in parser['s1']]
507+
>>> [option for option in parser['s1']] # doctest: +SKIP
504508
['1', '3', '5']
505-
>>> [option for option in parser['s2'].values()]
509+
>>> [option for option in parser['s2'].values()] # doctest: +SKIP
506510
['b', 'd', 'f']
507511

508512
* *allow_no_value*, default value: ``False``
@@ -597,11 +601,11 @@ the :meth:`__init__` options:
597601
... line #3
598602
... """)
599603
>>> print(parser['hashes']['shebang'])
600-
604+
<BLANKLINE>
601605
#!/usr/bin/env python
602606
# -*- coding: utf-8 -*-
603607
>>> print(parser['hashes']['extensions'])
604-
608+
<BLANKLINE>
605609
enabled_extension
606610
another_extension
607611
yet_another_extension
@@ -755,18 +759,19 @@ be overridden by subclasses or by attribute assignment.
755759

756760
.. doctest::
757761

762+
>>> import re
758763
>>> config = """
759764
... [Section 1]
760765
... option = value
761766
...
762767
... [ Section 2 ]
763768
... another = val
764769
... """
765-
>>> typical = ConfigParser()
770+
>>> typical = configparser.ConfigParser()
766771
>>> typical.read_string(config)
767772
>>> typical.sections()
768773
['Section 1', ' Section 2 ']
769-
>>> custom = ConfigParser()
774+
>>> custom = configparser.ConfigParser()
770775
>>> custom.SECTCRE = re.compile(r"\[ *(?P<header>[^]]+?) *\]")
771776
>>> custom.read_string(config)
772777
>>> custom.sections()

Doc/library/copyreg.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ it will be used:
5959
...
6060
>>> copyreg.pickle(C, pickle_c)
6161
>>> c = C(1)
62-
>>> d = copy.copy(c)
62+
>>> d = copy.copy(c) # doctest: +SKIP
6363
pickling a C instance...
64-
>>> p = pickle.dumps(c)
64+
>>> p = pickle.dumps(c) # doctest: +SKIP
6565
pickling a C instance...

Doc/library/ctypes.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1406,8 +1406,10 @@ Instances of these classes have no public methods. Functions exported by the
14061406
shared library can be accessed as attributes or by index. Please note that
14071407
accessing the function through an attribute caches the result and therefore
14081408
accessing it repeatedly returns the same object each time. On the other hand,
1409-
accessing it through an index returns a new object each time:
1409+
accessing it through an index returns a new object each time::
14101410

1411+
>>> from ctypes import CDLL
1412+
>>> libc = CDLL("libc.so.6") # On Linux
14111413
>>> libc.time == libc.time
14121414
True
14131415
>>> libc['time'] == libc['time']

0 commit comments

Comments
 (0)