Interfaces for Python
This project has been archived.
The maintainers of this project have marked this project as archived. No new releases are expected.
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
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file interface_mixins-0.0.4.tar.gz.
File metadata
- Download URL: interface_mixins-0.0.4.tar.gz
- Upload date:
- Size: 3.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
50bb34c077ee91c9361169d63ca1791a2b300d5481d13133032e0a7eca37163a
|
|
| MD5 |
0925c7bea618a0ca8a19bc49e30a0393
|
|
| BLAKE2b-256 |
edcf85a3f7df00e4a4a175cb4478540dfcedb36f6b88c96dde377916c7679a7f
|
File details
Details for the file interface_mixins-0.0.4-py3-none-any.whl.
File metadata
- Download URL: interface_mixins-0.0.4-py3-none-any.whl
- Upload date:
- Size: 3.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b2301850e8c7e40b11f64fb82d08cd4ab27c2836e92e5bd4f53549a7e23c77b4
|
|
| MD5 |
c5777e4cfec3931025a762294386c77e
|
|
| BLAKE2b-256 |
cd800e2a5ba7704f7fef6320b2c1c2199033976941d218d2a1755209d09505b1
|