A class with built-in doctest feature ?

R

Runsun Pan

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 "customization 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
reStructuredText.

--
~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~
Runsun Pan, PhD
(e-mail address removed)
Nat'l Center for Macromolecular Imaging
http://ncmi.bcm.tmc.edu/ncmi/
~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~
 
B

bearophileHUGS

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,283
Messages
2,571,405
Members
48,098
Latest member
inno vation

Latest Threads

Top