Message11134

Author onealj
Recipients onealj, stefan.richthofer
Date 2017-02-27.08:32:27
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1488184348.61.0.424581793569.issue2545@psf.upfronthosting.co.za>
In-reply-to
Content
This looks like an easy enough bug for a first-time contributor.

https://hg.python.org/jython/file/tip/src/org/python/modules/_imp.java#l27
    public static PyString __doc__ = new PyString(
        "This module provides the components needed to build your own\n"+
        "__import__ function.  Undocumented functions are obsolete.\n"
    );

https://hg.python.org/jython/file/tip/src/org/python/modules/_weakref/WeakrefModule.java#l15

    public static final PyString __doc__ = new PyString("Weak-reference support module.");

A strategy to write a unit test for this:
* Monkey-patch the pager target, pydoc.pager, so that we can capture the text that is sent to the pager (pipe to less/more or stdout). Pass text through pydoc.plain to strip bold markup bytes to make unit tests more readable.

# Back up global variables so they can be restored at the exit of the unit test
# Assume this unit test is executed atomically or wrap it in a lock.
@BeforeClass {
    import pydoc
    defaultpager = pydoc.pager
}

# Monkey-patch the pager target
# Basically the same as pydoc.plainpager, but capturing the output to StringIO rather than stdout)
@Before {
    out = StringIO.StringIO()
    stringiopager = lambda text: out.write(pydoc.plain(text))
    pydoc.pager = stringiopager
}

# Run the unit test
    help('_imp')

# Compare the output
    assertEquals(expectedText, out.getvalue())
    # We expect out.getvalue() to contain the text from _imp.__doc__ if we ignore whitespace. This currently fails.

# Cleanup and undo the monkey-patching
@After {
    out.close()
}
@AfterClass {
    pydoc.pager = defaultpager
}
History
Date User Action Args
2017-02-27 08:32:28onealjsetmessageid: <1488184348.61.0.424581793569.issue2545@psf.upfronthosting.co.za>
2017-02-27 08:32:28onealjsetrecipients: + onealj, stefan.richthofer
2017-02-27 08:32:28onealjlinkissue2545 messages
2017-02-27 08:32:27onealjcreate