check if class really implements api?

Terry Hancock hancock at anansispaceworks.com
Wed Jan 4 07:25:46 CET 2006


On 3 Jan 2006 12:56:58 -0800
"Karsten W." <DonQuixoteVonLaMancha at gmx.net> wrote:
> with the zope.interface module I can query if my class
> claims to implement my API. This
> is what the method implementedBy is for.
> 
> However, I find myself constantly changing the API and I
> am looking for a more reliable way
> to check my implementation classes. Is there a way to
> check if at least all function
> names of the API are defined by the class and if their
> parameter lists fit the API? A way
> to test this would save me a lot of time..

You want:

Zope 2.5.1:
Interface.verify.verify_class_implementation

or

Zope 3.x:
zope.interface.verify

You'll want to read the source modules for documentation and
usage, as I don't think these are particularly well
documented anywhere else.

They are somewhat different in API between the two interface
implementations, but both do essentially the same thing --
they check the class against the interface object.  This
will only tell you whether the methods are there and have
the same calling profile -- it obviously can't tell you
whether they do what you expect (or indeed do anything at
all).

But I had the same problem you're having, and I found them
useful.

Cheers,
Terry

-- 
Terry Hancock (hancock at AnansiSpaceworks.com)
Anansi Spaceworks http://www.AnansiSpaceworks.com




More information about the Python-list mailing list