[pygtk] Functional/Acceptance Testing Using guitest

Chris Lambacher chris at kateandchris.net
Thu May 25 21:46:34 WST 2006


On Thu, May 25, 2006 at 03:28:32PM +0200, Lawrence Oluyede wrote:
> On 5/25/06, baiju m <baiju.m.mail at gmail.com> wrote:
> >On 5/25/06, Lawrence Oluyede <l.oluyede at gmail.com> wrote:
> >> - assert type(button) == gtk.Button is not really pythonic and it's
> >> quite deprecated because it does not support inheritance. Use assert
> >> isinstance(button, gtk.Button)
> >
> >I often hear isinstance considered harmful, see this
> >http://www.canonical.org/~kragen/isinstance/
> 
> AFAIK the article is 4 years old and refers 2.1 version of Python. Lot
> of things have changed since 2.2 and the introduction of new style
> classes. Anyway it doesn't really matter for your example.

The article is still relevant.  However it is often quoted to support
something that I think the author did not intend.  The true point point of the
article is that if you use isinstance you can't use duck typing.
Unfortunately checking for a supported interface is often difficult in python
because there is no standard way for an object to say "I support interface x".
That leaves people doing a lot of isinstance because it is easy.  More often
we just care that an object supports a couple of method calls an has one or
two attributes or properties.  Python gives us the means to test for that, but
it is certainly not as easy as using is instance.

As for the particular bit of code up for debate:
assert type(button) == gtk.Button 

This will work for Baiju's purposes but isinstance would also allow him to
accept anything that inherits from gtk.Button (currently that means
gtk.ColorButton, gtk.FontButton, gtk.ToggleButton, gtk.CheckButton,
gtk.RadioButton).  It is up to Baiju, or whoever adapts his testing technique,
to decide if that makes sense or not.

-Chris


More information about the pygtk mailing list