Skip to main content

Interfaces for Python

Project description

To create an Interface, pass it an interface name and a list of method names:

AnInterface = Interface('AnInterface', [
    'some',
    'methods',
    'the',
    'interface',
    'should',
    'have'
])

We also provide a way to create abstract test cases to help test objects against the interface:

AbstractTestAnInterface = AbstractInterfaceTest('AbstractTestAnInterface', [
    'some',
    'methods',
    'the',
    'interface',
    'should',
    'have'
])

These tests can be used by creating TestCases which inherit from from the abstract test. This makes sure each method is implemented in AClass:

from unittest import TestCase

class TestAClass(AbstractTestAnInterface, TestCase):
    def setUp(self):
        self.obj = AClass()

It is also possible to create both the Interface and the AbstractInterfaceTest at the same time. Also, you can create multiple interfaces using the following idiom [1]:

interfaces = {
    'AnInterface': [
        'some',
        'methods',
        'the',
        'interface',
        'should',
        'have'
    ],
    'AnotherInterface': [
        'different',
        'methods'
    ]
}

for interface_name, methods in interfaces.iteritems():
    interface_name += 'Interface'
    globals()[interface_name] = Interface(interface_name, methods)
    test_name = 'AbstractTest' + interface_name
    globals()[test_name] = AbstractInterfaceTest(test_name, methods)
[1]This isn’t very idiomatic Python. The use globals is ugly. This is just an idiom for using this library. I’m not sure I like it.

Project details


Release history Release notifications

History Node

0.0.3

History Node

0.0.2

This version
History Node

0.0.1

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
interface-mixins-0.0.1.tar.gz (2.2 kB) Copy SHA256 hash SHA256 Source None Feb 2, 2014

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging CloudAMQP CloudAMQP RabbitMQ AWS AWS Cloud computing Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page