A class with built-in doctest feature ?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Runsun Pan

    #1

    A class with built-in doctest feature ?

    I intend to use the doctect heavily. For this I am thinking of
    coding a class that comes with a built-in doctest functionality.
    I'd like to seek for input before I start.

    The idea is to have a class MyObj from where all my other
    classes will subclass.

    lets say:

    class C(MyObj):
    ''' This C
    (some doctest here) ---- doctest.1
    '''
    def func1(self):
    ''' This is C.func1
    (some doctest here) --- doctest.2
    '''
    blah blah blah
    return blah

    Now, after the above class defintion, I can just do:

    C( ).doctest( )

    and it will go through doctest.1 and doctest.2 and report the
    test results

    What is the better way to make such a MyObj ?

    The applications of this sort of built-ins are not limited to
    a doctest. Similar to the built-in __doc__ that offers some sort
    of documentation, a mechnism like what I am proposing can
    provide "customizat ion on the fly" feature to allow manipulations
    of the doctext at run-time. For example,

    C( ).toHtml( )

    to convert the __doc__ to a webpage by converting it throu
    reStructuredTex t.

    --
    ~*~*~*~*~*~*~*~ *~*~*~*~*~*~*~* ~*~*~
    Runsun Pan, PhD
    python.pan@gmai l.com
    Nat'l Center for Macromolecular Imaging

    ~*~*~*~*~*~*~*~ *~*~*~*~*~*~*~* ~*~*~
  • bearophileHUGS@lycos.com

    #2
    Re: A class with built-in doctest feature ?

    The idea looks interesting, but you can also design a couple of
    functions that scan the docstrings of a given class and its methods to
    produce what you need:

    doctestAll(C)
    toHtml(C)

    This is probably simpler and gives similar results.

    Bye,
    bearophile

    Comment

    Working...