Welcome, guest | Sign In | My Account | Store | Cart

Notice! PyPM is being replaced with the ActiveState Platform, which enhances PyPM’s build and deploy capabilities. Create your free Platform account to download ActivePython or customize Python with the packages you require and get automatic updates.

Download
ActivePython
INSTALL>
pypm install affinitic.verifyinterface

How to install affinitic.verifyinterface

  1. Download and install ActivePython
  2. Open Command Prompt
  3. Type pypm install affinitic.verifyinterface
 Python 2.7Python 3.2Python 3.3
Windows (32-bit)
0.1 Available View build log
Windows (64-bit)
0.1 Available View build log
Mac OS X (10.5+)
0.1 Available View build log
Linux (32-bit)
0.1 Available View build log
Linux (64-bit)
0.1 Available View build log
 
Author
License
GPL
Lastest release
version 0.1 on Jan 5th, 2011

Introduction

What's the use to declare an interface if your class doesn't implement correctly the interface ?

Of course you should verify that in a test but if you don't want to write a test to check that all your code really implements the promised interfaces use this package.

It's a simple patch that calls zope.interface.verify.verifyClass once you declare implementing an interface and print the BrokenImplementation or BrokenMethodImplementation as a warning (if any).

Simple example in testrunner:

By default the egg enable interface contract verification for zope.interface.implements and zope.interface.classImplements that are present in all your packages:

>>> write('buildout.cfg',

System Message: ERROR/3 (<string>, line 18)

Inconsistent literal block quoting.

... """ ... [buildout] ... parts = ... test ... ... [test] ... recipe = zc.recipe.testrunner ... eggs = affinitic.verifyinterface ... zope.exceptions ... defaults = ['-m', 'module'] ... """)

>>> print system(buildout)
Installing test.
...
>>> from os.path import join
>>> print system(join('bin', 'test')),
<class 'affinitic.verifyinterface.tests.test_module1.Foo'> failed implementing <InterfaceClass affinitic.verifyinterface.tests.test_module1.IFoo>: An object has failed to implement interface <InterfaceClass affinitic.verifyinterface.tests.test_module1.IFoo>
<BLANKLINE>
The bla attribute was not provided.
<BLANKLINE>
<class 'affinitic.verifyinterface.tests.test_module2.Bar'> failed implementing <InterfaceClass affinitic.verifyinterface.tests.test_module2.IBar>: An object has failed to implement interface <InterfaceClass affinitic.verifyinterface.tests.test_module2.IBar>
<BLANKLINE>
The bla attribute was not provided.
<BLANKLINE>
Running zope.testing.testrunner.layer.UnitTests tests:
Set up zope.testing.testrunner.layer.UnitTests in 0.000 seconds.
Ran 2 tests with 0 failures and 0 errors in 0.000 seconds.
Tearing down left over layers:
Tear down zope.testing.testrunner.layer.UnitTests in 0.000 seconds.
Limit verifications

But you can limit the package where this verification needs to be done (sometimes you don't care that a package you depend on didn't implement correctly an interface).

This is done by adding an environment variable verifyinterface where you specify what packages/modules (separated by n as usual) you accept to verify interfaces.

Here is a simple example where I only want to have warning for bad implementation of interfaces used by module1:

>>> write('buildout.cfg',

System Message: ERROR/3 (<string>, line 62)

Inconsistent literal block quoting.

... """ ... [buildout] ... parts = ... test ... ... [test] ... recipe = zc.recipe.testrunner ... eggs = affinitic.verifyinterface ... zope.exceptions ... defaults = ['-m', 'module'] ... environment = testenv ... ... [testenv] ... verifyinterface = affinitic.verifyinterface.tests.test_module1 ... """)

>>> print system(buildout)
Uninstalling test.
Installing test.
...
>>> from os.path import join
>>> print system(join('bin', 'test'))
<class 'affinitic.verifyinterface.tests.test_module1.Foo'> failed implementing <InterfaceClass affinitic.verifyinterface.tests.test_module1.IFoo>: An object has failed to implement interface <InterfaceClass affinitic.verifyinterface.tests.test_module1.IFoo>
<BLANKLINE>
The bla attribute was not provided.
<BLANKLINE>
Running zope.testing.testrunner.layer.UnitTests tests:
Set up zope.testing.testrunner.layer.UnitTests in 0.000 seconds.
Ran 2 tests with 0 failures and 0 errors in 0.000 seconds.
Tearing down left over layers:
Tear down zope.testing.testrunner.layer.UnitTests in 0.000 seconds.

Changelog

0.1 (2009-12-18)
  • Initial release

Subscribe to package updates

Last updated Jan 5th, 2011

Download Stats

Last month:1

What does the lock icon mean?

Builds marked with a lock icon are only available via PyPM to users with a current ActivePython Business Edition subscription.

Need custom builds or support?

ActivePython Enterprise Edition guarantees priority access to technical support, indemnification, expert consulting and quality-assured language builds.

Plan on re-distributing ActivePython?

Get re-distribution rights and eliminate legal risks with ActivePython OEM Edition.