[Python-checkins] cpython (3.5): Issue #27207: Fix doctests in Doc/whatsnew/3.2.rst

zach.ware python-checkins at python.org
Wed Aug 10 01:31:43 EDT 2016


https://hg.python.org/cpython/rev/cee3074233e6
changeset:   102593:cee3074233e6
branch:      3.5
parent:      102591:8b7efeeefa50
user:        Zachary Ware <zachary.ware at gmail.com>
date:        Wed Aug 10 00:30:41 2016 -0500
summary:
  Issue #27207: Fix doctests in Doc/whatsnew/3.2.rst

Initial patch by Jelle Zijlstra.

files:
  Doc/whatsnew/3.2.rst |  51 ++++++++++++++++++++-----------
  1 files changed, 32 insertions(+), 19 deletions(-)


diff --git a/Doc/whatsnew/3.2.rst b/Doc/whatsnew/3.2.rst
--- a/Doc/whatsnew/3.2.rst
+++ b/Doc/whatsnew/3.2.rst
@@ -313,14 +313,14 @@
   of the actual file that was imported:
 
    >>> import collections
-   >>> collections.__cached__
+   >>> collections.__cached__ # doctest: +SKIP
    'c:/py32/lib/__pycache__/collections.cpython-32.pyc'
 
 * The tag that is unique to each interpreter is accessible from the :mod:`imp`
   module:
 
    >>> import imp
-   >>> imp.get_tag()
+   >>> imp.get_tag() # doctest: +SKIP
    'cpython-32'
 
 * Scripts that try to deduce source filename from the imported file now need to
@@ -329,7 +329,7 @@
 
   >>> imp.source_from_cache('c:/py32/lib/__pycache__/collections.cpython-32.pyc')
   'c:/py32/lib/collections.py'
-  >>> imp.cache_from_source('c:/py32/lib/collections.py')
+  >>> imp.cache_from_source('c:/py32/lib/collections.py') # doctest: +SKIP
   'c:/py32/lib/__pycache__/collections.cpython-32.pyc'
 
 * The :mod:`py_compile` and :mod:`compileall` modules have been updated to
@@ -532,7 +532,7 @@
   original object.
 
   >>> with memoryview(b'abcdefgh') as v:
-          print(v.tolist())
+  ...     print(v.tolist())
   [97, 98, 99, 100, 101, 102, 103, 104]
 
   (Added by Antoine Pitrou; :issue:`9757`.)
@@ -568,9 +568,10 @@
   expect a tuple as an argument.  This is a big step forward in making the C
   structures as flexible as their pure Python counterparts:
 
+  >>> import sys
   >>> isinstance(sys.version_info, tuple)
   True
-  >>> 'Version %d.%d.%d %s(%d)' % sys.version_info
+  >>> 'Version %d.%d.%d %s(%d)' % sys.version_info # doctest: +SKIP
   'Version 3.2.0 final(0)'
 
   (Suggested by Arfrever Frehtes Taifersar Arahesis and implemented
@@ -757,18 +758,18 @@
 
   >>> import functools
   >>> @functools.lru_cache(maxsize=300)
-  >>> def get_phone_number(name):
-          c = conn.cursor()
-          c.execute('SELECT phonenumber FROM phonelist WHERE name=?', (name,))
-          return c.fetchone()[0]
-
-  >>> for name in user_requests:
-          get_phone_number(name)        # cached lookup
+  ... def get_phone_number(name):
+  ...     c = conn.cursor()
+  ...     c.execute('SELECT phonenumber FROM phonelist WHERE name=?', (name,))
+  ...     return c.fetchone()[0]
+
+  >>> for name in user_requests:        # doctest: +SKIP
+  ...     get_phone_number(name)        # cached lookup
 
   To help with choosing an effective cache size, the wrapped function is
   instrumented for tracking cache statistics:
 
-  >>> get_phone_number.cache_info()
+  >>> get_phone_number.cache_info()     # doctest: +SKIP
   CacheInfo(hits=4805, misses=980, maxsize=300, currsize=300)
 
   If the phonelist table gets updated, the outdated contents of the cache can be
@@ -823,7 +824,7 @@
   modern :term:`key function`:
 
   >>> # locale-aware sort order
-  >>> sorted(iterable, key=cmp_to_key(locale.strcoll))
+  >>> sorted(iterable, key=cmp_to_key(locale.strcoll)) # doctest: +SKIP
 
   For sorting examples and a brief sorting tutorial, see the `Sorting HowTo
   <https://wiki.python.org/moin/HowTo/Sorting/>`_ tutorial.
@@ -861,7 +862,8 @@
   which only have positive counts, and the latter is more suitable for use cases
   that allow negative counts:
 
-  >>> tally = Counter(dogs=5, cat=3)
+  >>> from collections import Counter
+  >>> tally = Counter(dogs=5, cats=3)
   >>> tally -= Counter(dogs=2, cats=8)    # saturating subtraction
   >>> tally
   Counter({'dogs': 3})
@@ -884,6 +886,7 @@
   an ordered dictionary can be used to track order of access by aging entries
   from the oldest to the most recently accessed.
 
+  >>> from collections import OrderedDict
   >>> d = OrderedDict.fromkeys(['a', 'b', 'X', 'd', 'e'])
   >>> list(d)
   ['a', 'b', 'X', 'd', 'e']
@@ -897,6 +900,7 @@
   :meth:`~collections.deque.count` and :meth:`~collections.deque.reverse` that
   make them more substitutable for :class:`list` objects:
 
+  >>> from collections import deque
   >>> d = deque('simsalabim')
   >>> d.count('s')
   2
@@ -1042,6 +1046,7 @@
 special values.  It returns *True* for regular numbers and *False* for *Nan* or
 *Infinity*:
 
+>>> from math import isfinite
 >>> [isfinite(x) for x in (123, 4.56, float('Nan'), float('Inf'))]
 [True, True, False, False]
 
@@ -1049,6 +1054,7 @@
 without incurring the loss of precision that usually accompanies the subtraction
 of nearly equal quantities:
 
+>>> from math import expm1
 >>> expm1(0.013671875)   # more accurate way to compute e**x-1 for a small x
 0.013765762467652909
 
@@ -1056,6 +1062,7 @@
 error function <https://en.wikipedia.org/wiki/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
@@ -1069,6 +1076,7 @@
 *x*, so there is also a :func:`~math.lgamma` function for computing the natural
 logarithm of the gamma function:
 
+>>> from math import gamma, lgamma
 >>> gamma(7.0)           # six factorial
 720.0
 >>> lgamma(801.0)        # log(800 factorial)
@@ -1287,7 +1295,7 @@
 prime modulus, the hash values for *infinity* and *nan*, and the multiplier
 used for the imaginary part of a number:
 
->>> sys.hash_info
+>>> sys.hash_info # doctest: +SKIP
 sys.hash_info(width=64, modulus=2305843009213693951, inf=314159, nan=0, imag=1000003)
 
 An early decision to limit the inter-operability of various numeric types has
@@ -1310,6 +1318,8 @@
 :meth:`~fractions.Fraction.from_float()` and :meth:`~fractions.Fraction.from_decimal`
 methods are no longer needed (:issue:`8294`):
 
+>>> from decimal import Decimal
+>>> from fractions import Fraction
 >>> Decimal(1.1)
 Decimal('1.100000000000000088817841970012523233890533447265625')
 >>> Fraction(1.1)
@@ -1392,6 +1402,7 @@
 decompression.  Keep in mind that text needs to be encoded as :class:`bytes`
 before compressing and decompressing:
 
+>>> import gzip
 >>> s = 'Three shall be the number thou shalt count, '
 >>> s += 'and the number of the counting shall be three'
 >>> b = s.encode()                        # convert to utf-8
@@ -1401,7 +1412,7 @@
 >>> len(c)
 77
 >>> gzip.decompress(c).decode()[:42]      # decompress and convert to text
-'Three shall be the number thou shalt count,'
+'Three shall be the number thou shalt count'
 
 (Contributed by Anand B. Pillai in :issue:`3488`; and by Antoine Pitrou, Nir
 Aides and Brian Curtin in :issue:`9962`, :issue:`1675951`, :issue:`7471` and
@@ -1503,6 +1514,7 @@
 :func:`~os.fsencode` and :func:`~os.fsdecode`, for encoding and decoding
 filenames:
 
+>>> import os
 >>> filename = 'Sehenswürdigkeiten'
 >>> os.fsencode(filename)
 b'Sehensw\xc3\xbcrdigkeiten'
@@ -1740,6 +1752,7 @@
   :class:`unittest.case.TestCase` class can now be instantiated without
   arguments:
 
+  >>> from unittest import TestCase
   >>> TestCase().assertEqual(pow(2, 3), 8)
 
   (Contributed by Michael Foord.)
@@ -2201,7 +2214,7 @@
 <https://en.wikipedia.org/wiki/IPv6>`_ addresses as described in :rfc:`2732`:
 
     >>> import urllib.parse
-    >>> urllib.parse.urlparse('http://[dead:beef:cafe:5417:affe:8FA3:deaf:feed]/foo/')
+    >>> urllib.parse.urlparse('http://[dead:beef:cafe:5417:affe:8FA3:deaf:feed]/foo/') # doctest: +NORMALIZE_WHITESPACE
     ParseResult(scheme='http',
                 netloc='[dead:beef:cafe:5417:affe:8FA3:deaf:feed]',
                 path='/foo/',
@@ -2235,7 +2248,7 @@
 not mixed with regular strings.  If ASCII-encoded byte strings are given as
 parameters, the return types will also be an ASCII-encoded byte strings:
 
-    >>> urllib.parse.urlparse(b'http://www.python.org:80/about/')
+    >>> urllib.parse.urlparse(b'http://www.python.org:80/about/') # doctest: +NORMALIZE_WHITESPACE
     ParseResultBytes(scheme=b'http', netloc=b'www.python.org:80',
                      path=b'/about/', params=b'', query=b'', fragment=b'')
 

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list