classification
Title: ipaddress doctest examples have some errors
Type: behavior Stage: resolved
Components: Documentation Versions: Python 3.3
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: chris.jerdonek Nosy List: chris.jerdonek, docs@python, eli.bendersky, ezio.melotti, ncoghlan, pmoody, python-dev
Priority: normal Keywords: easy, patch

Created on 2012-09-09 11:32 by chris.jerdonek, last changed 2012-10-07 14:25 by eli.bendersky. This issue is now closed.

Files
File name Uploaded Description Edit
issue-15888-1.patch chris.jerdonek, 2012-09-10 07:27 review
issue-15888-2.patch chris.jerdonek, 2012-09-19 23:48 review
Messages (10)
msg170097 - (view) Author: Chris Jerdonek (chris.jerdonek) * (Python committer) Date: 2012-09-09 11:32
The ipaddress HOWTO seems to have some errors in its interactive doctest examples.  Below are the errors after running the doctests for it using the regrtest patch posted to issue 15629.  (This is the first doc file for which I have used the modified script to open an issue.)

The errors seem valid to me on casual inspection.

Note that you need to add an initial ">>> import ipaddress" at the beginning of the first doctest example to have these actually run.


----------------------------------------------------------------------
File "Doc/howto/ipaddress.rst", line 146, in ipaddress.rst
Failed example:
    ipaddress.ip_network('2001:db8::1/96')
Exception raised:
    Traceback (most recent call last):
      File "Lib/doctest.py", line 1287, in __run
        compileflags, 1), test.globs)
      File "<doctest ipaddress.rst[15]>", line 1, in <module>
        ipaddress.ip_network('2001:db8::1/96')
      File "Lib/ipaddress.py", line 79, in ip_network
        return IPv6Network(address, strict)
      File "Lib/ipaddress.py", line 2056, in __init__
        raise ValueError('%s has host bits set' % self)
    ValueError: 2001:db8::1/96 has host bits set
----------------------------------------------------------------------
File "Doc/howto/ipaddress.rst", line 181, in ipaddress.rst
Failed example:
    net4.numhosts
Exception raised:
    Traceback (most recent call last):
      File "Lib/doctest.py", line 1287, in __run
        compileflags, 1), test.globs)
      File "<doctest ipaddress.rst[25]>", line 1, in <module>
        net4.numhosts
    AttributeError: 'IPv4Network' object has no attribute 'numhosts'
----------------------------------------------------------------------
File "Doc/howto/ipaddress.rst", line 184, in ipaddress.rst
Failed example:
    net6.numhosts
Exception raised:
    Traceback (most recent call last):
      File "Lib/doctest.py", line 1287, in __run
        compileflags, 1), test.globs)
      File "<doctest ipaddress.rst[27]>", line 1, in <module>
        net6.numhosts
    AttributeError: 'IPv6Network' object has no attribute 'numhosts'
----------------------------------------------------------------------
File "Doc/howto/ipaddress.rst", line 190, in ipaddress.rst
Failed example:
    for x in net4.hosts():
Exception raised:
    Traceback (most recent call last):
      File "Lib/doctest.py", line 1287, in __run
        compileflags, 1), test.globs)
      File "<doctest ipaddress.rst[29]>", line 1
        for x in net4.hosts():
                             ^
    SyntaxError: unexpected EOF while parsing
----------------------------------------------------------------------
File "Doc/howto/ipaddress.rst", line 219, in ipaddress.rst
Failed example:
    addr6.exploded
Expected:
    '2001:0db8:0000:0000:0000:0000:0000:0000'
Got:
    '2001:0db8:0000:0000:0000:0000:0000:0001'
----------------------------------------------------------------------
File "Doc/howto/ipaddress.rst", line 221, in ipaddress.rst
Failed example:
    addr6.compressed
Expected:
    '2001:db8::'
Got:
    '2001:db8::1'
----------------------------------------------------------------------
File "Doc/howto/ipaddress.rst", line 244, in ipaddress.rst
Failed example:
    net6[1]
Expected:
    IPv6Address('2001::1')
Got:
    IPv6Address('2001:db8::1')
----------------------------------------------------------------------
File "Doc/howto/ipaddress.rst", line 246, in ipaddress.rst
Failed example:
    net6[-1]
Expected:
    IPv6Address('2001::ffff:ffff')
Got:
    IPv6Address('2001:db8::ffff:ffff')
msg170101 - (view) Author: Chris Jerdonek (chris.jerdonek) * (Python committer) Date: 2012-09-09 14:11
While we are here, the corresponding Python file also has a couple errors in one of its doctest examples.

File "Lib/ipaddress.py", line 209, in ipaddress.summarize_address_range
Failed example:
    summarize_address_range(IPv4Address('192.0.2.0'),
Exception raised:
    Traceback (most recent call last):
      File "Lib/doctest.py", line 1287, in __run
        compileflags, 1), test.globs)
      File "<doctest ipaddress.summarize_address_range[0]>", line 1
        summarize_address_range(IPv4Address('192.0.2.0'),
                                                        ^
    SyntaxError: unexpected EOF while parsing
msg170103 - (view) Author: Chris Jerdonek (chris.jerdonek) * (Python committer) Date: 2012-09-09 14:30
And also the main doc file Lib/ipaddress.rst (along with some formatting issues, and after adding needed imports):

File "Doc/library/ipaddress.rst", line 115, in ipaddress.rst
Failed example:
    ipaddress.IPv4Address(3221225985)
Expected:
    IPv4Address('192.168.0.1')
Got:
    IPv4Address('192.0.2.1')
msg170117 - (view) Author: Chris Jerdonek (chris.jerdonek) * (Python committer) Date: 2012-09-09 16:51
I will prepare a patch for these three files.
msg170163 - (view) Author: Chris Jerdonek (chris.jerdonek) * (Python committer) Date: 2012-09-10 07:27
Attaching patch.

The doctests for these three files now all pass (using a newer version of the patch I uploaded to issue 15629).
msg170288 - (view) Author: Chris Jerdonek (chris.jerdonek) * (Python committer) Date: 2012-09-11 10:57
Adding Eli to this because he did some work on the HOWTO for this module in issue 14814.
msg170777 - (view) Author: Chris Jerdonek (chris.jerdonek) * (Python committer) Date: 2012-09-19 23:48
Attaching an updated patch that does not render the import statements in the final HTML, so that it renders the same as before.
msg172300 - (view) Author: Eli Bendersky (eli.bendersky) * (Python committer) Date: 2012-10-07 13:26
Thanks, Chris. I'll take a look
msg172303 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2012-10-07 14:24
New changeset 81ad910d75a9 by Eli Bendersky in branch '3.3':
Issue #15888: fixing problems in ipaddress doctests. Patch by Chris Jerdonek
http://hg.python.org/cpython/rev/81ad910d75a9
msg172305 - (view) Author: Eli Bendersky (eli.bendersky) * (Python committer) Date: 2012-10-07 14:25
Pushed to 3.3 and 3.4
Thanks for the report and patch
History
Date User Action Args
2012-10-07 14:25:32eli.benderskysetstatus: open -> closed
resolution: fixed
messages: + msg172305

stage: patch review -> resolved
2012-10-07 14:24:32python-devsetnosy: + python-dev
messages: + msg172303
2012-10-07 13:26:58eli.benderskysetmessages: + msg172300
2012-10-02 15:28:59chris.jerdoneksetassignee: docs@python -> chris.jerdonek
2012-09-19 23:48:27chris.jerdoneksetfiles: + issue-15888-2.patch

messages: + msg170777
2012-09-15 06:04:08ezio.melottisetnosy: + ezio.melotti

stage: needs patch -> patch review
2012-09-11 10:57:16chris.jerdoneksetnosy: + eli.bendersky
messages: + msg170288
2012-09-10 07:27:07chris.jerdoneksetfiles: + issue-15888-1.patch
keywords: + patch
messages: + msg170163
2012-09-09 16:51:55chris.jerdoneksetmessages: + msg170117
2012-09-09 14:30:06chris.jerdoneksetmessages: + msg170103
title: ipaddress HOWTO examples have some errors -> ipaddress doctest examples have some errors
2012-09-09 14:11:28chris.jerdoneksetmessages: + msg170101
2012-09-09 11:32:29chris.jerdonekcreate