Smart dummy objects

Jonathan Fine jfine at pytex.org
Sun Nov 14 07:30:40 EST 2004


I'd appreciate comments on what I'm doing.

Please be kind, I'm a new kid on the block.


Here's my application.

I'm writing some test code.

(I'm a recent convert to unit testing.)


I want to test a series of changes to an object.

The change methods return self, so I can form chains.

Like so:
    x = obj.this().that(12).other(x=3, y=12)
    assert x is obj


A Dummy class (easily coded) allows:
    d = Dummy()
    y = d.this().that(12).other(x=3, y=12)
    assert y is d
to execute without errors.

Function calls (and getting attributes) do not change d.

And these operations return self.


I'm looking for a SmartDummy class.

So that:
    sd = SmartDummy()
    sd.this.that(12).other(x=3, y=12)
    assert z is sd
always executes without errors (it's a Dummy) ...


... and because it's a SmartDummy,
    magic = sd.special_method_name(obj)
is equivalent to
    magic = obj.this().that(12).other(x=3, y=12)
even to the raising of exceptions.


This allows a chain of changes to be stored in a SmartDummy.

And then applied to a succession of real objects.


Before writing much code, I did a google for "SmartDummy" and "smart
dummy" in this newsgroup.

I got no hits, which discouraged me.

I then searched all newsgroups.  Got 24 and 39,200 hits resp.

http://groups.google.com/groups?hl=en&lr=&q=SmartDummy
http://groups.google.com/groups?hl=en&lr=&q=Smart+Dummy&btnG=Search&meta=

The 24 were not helpful, the 39,200 too many.


A search of the web for SmartDummy was not helpful.
http://www.google.com/search?hl=en&lr=&q=SmartDummy


But "Smart Dummy" was.
http://www.google.com/search?q=Smart%20Dummy&hl=en&lr=&sa=N&tab=gw

The very first hit was:
http://www.tc.gc.ca/mediaroom/releases/nat/2004/04-h082e.htm

It announced the Canadian debut of:
===
WorldSID (World Side Impact Dummy) was born out of a need to have a
world harmonized crash test dummy that would better simulate the motions
of a human in side impact crash testing.
===


This encouraged me. Smart Dummies are important.  They can save lives.

Maybe they are a good idea.  Let's try to make a Python SmartDummy.

So I went ahead and spend the morning coding up my SmartDummy class.


Much of it is now working, but it's not yet ready for its Python debut.

Hope this of interest.


BTW, I'm a bit of a Python newbie, particularly regarding culture.

This is my first post to comp.lang.python. (I was a lurker.)

However, I am a regular on comp.text.tex.


As I said, I'd appreciate your comments on this.


Jonathan




More information about the Python-list mailing list