testing is easier in python

Michael Hudson mwh at python.net
Mon Feb 3 10:58:40 EST 2003


Geoff Gerrietts <geoff at gerrietts.net> writes:

> Quoting Michael Hudson (mwh at python.net):
> > Subject: Re: Python Success Stories or Nightmares
> [...]
> > Geoff Gerrietts <geoff at gerrietts.net> writes:
> > 
> > > Good stuff:
> > [...]
> > > - Unit tests are amazingly easy to write, since you can "stub in"
> > >   dependencies in lots of different ways.
> > 
> > I recently got smacked in the face (in a good way) by this one, so I
> > thought I'd quote it in isolation to make sure everyone read it.
> > 
> 
> I think it's worth explaining, too, but I'm not sure this is the
> thread to do it in, so I'm changing the subject line. It's worth
> explaining because I've seen the topic of unit tests come up in other
> threads, and I saw someone make the claim that testing is
> a language-neutral solution. I don't believe that. Here's why.

The situation where it made testing easier -- or rather possible --
was my pyrepl command line library.  

I didn't think that it would be *at all* possible to test this -- I
mean it's doing all kinds of syscalls and mucking about with terminal
settings and so on.  But (largely to keep myself sane) a while ago I
split the terminal grubbing stuff into a separate class which the
Reader class interacts with through a defined interface (mainly
'get_event()' and 'refresh()' which do much what you'd expect).

So this lets me write a TestConsole class that serves up a bunch of
events and check that the results on the screen are what I'd expect.
I'm not totally happy with the testing framework as I have it (I think
it's probably a bit too dependent on library internals) but it's a
damn sight better than what I had before (no tests at all).

>From AMK's quote file:

    The way to build large Python applications is to componentize and
    loosely-couple the hell out of everything.
                                            -- Aahz Maruch, 6 Jan 2000

Cheers,
M.

-- 
  There's an aura of unholy black magic about CLISP.  It works, but
  I have no idea how it does it.  I suspect there's a goat involved
  somewhere.                     -- Johann Hibschman, comp.lang.scheme




More information about the Python-list mailing list