How to detect typos in Python programs

Manish Jethani manish.j at gmx.net
Fri Jul 25 16:24:48 EDT 2003


Peter Hansen wrote:

> Manish Jethani wrote:
> 
>>Is there a way to detect typos in a Python program, before
>>actually having to run it.  Let's say I have a function like this:
>>
>>  def server_closed_connection():
>>    session.abost()
>>
>>Here, abort() is actually misspelt.  The only time my program
>>follows this path is when the server disconnects from its
>>end--and that's like once in 100 sessions.  So sometimes I
>>release the program, people start using it, and then someone
>>reports this typo after 4-5 days of the release (though it's
>>trivial to fix manually at the user's end, or I can give a patch).
>>
>>How can we detect these kinds of errors at development time?
>>It's not practical for me to have a test script that can make
>>the program go through all (most) the possible code paths.
> 
> 
> You have no good alternative.  Why do you say it's impractical
> to actually test your software before it's shipped?  Isn't it
> more impractical to rely on your users to test the software,
> thinking it should work?

I get your point.  But my program is basically open source, so I
release early and often, and I expect users to report bugs.  BTW
a lot of big software houses I know of also do the same thing,
but their marketing departments like to put things in a
different way ("time to market", "beta release", and stuff like
that :-) ).

Call my release an alpha, beta or whatever.  But I expect users
to report "real bugs", not typos.  So I thought there should be
a better way to catch these things (I saw pylint and pychecker,
and they look good).

> Unit testing in Python is *really* easy.  I can't think of any
> reason not to do it as the best way of catching problems like you
> show above.  If you resist :-), however, you might find PyChecker
> will help.  I'm not sure if it can do anything in the above case
> yet, however.

Actually I am writing a client app for a proprietary service.
The server is not under my control, so I can't make it behave in
a way that will cause every part of my client code to be tested.
As I mentioned, for example, I have a function to handle a
server-disconnect.  But the server rarely ever disconnects of
its own, so the function never gets called in reality.  Can I
unit test this function easily?

FYI:  The program in question is msnp.py.
<URL:http://msnp.sf.net/>

thanks,
-Manish

-- 
Manish Jethani (manish.j at gmx.net)
phone (work) +91-80-51073488





More information about the Python-list mailing list