Interfaces for Python
Project description
To create an Interface, pass it an interface name and a list of method names. A class will be created which raises NotImplementedError for each of the specified method names:
AnInterface = Interface('AnInterface', [
'some',
'methods',
'the',
'interface',
'should',
'have'
])
To use this interface, simply inherit from it:
class AClass(AnInterface):
pass
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)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file interface-mixins-0.0.3.tar.gz.
File metadata
- Download URL: interface-mixins-0.0.3.tar.gz
- Upload date:
- Size: 2.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
98356a0a7323cf5064c0cc3f024f6cd6f85ae7739db6d6d4ce988db1a94a761f
|
|
| MD5 |
427b456755902e3b34b024677f9e8ed6
|
|
| BLAKE2b-256 |
53ab86443e65081ea3a0d661a643688aa9ba65d2e5c37c84bf0722f3ae484b26
|