Skip to main content
Archived

This project has been archived by its maintainers, and is no longer receiving any updates.

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)

Download files

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

Source Distribution

interface_mixins-0.0.4.tar.gz (3.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

interface_mixins-0.0.4-py3-none-any.whl (3.7 kB view details)

Uploaded Python 3

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

Hashes for interface_mixins-0.0.4.tar.gz
Algorithm Hash digest
SHA256 50bb34c077ee91c9361169d63ca1791a2b300d5481d13133032e0a7eca37163a
MD5 0925c7bea618a0ca8a19bc49e30a0393
BLAKE2b-256 edcf85a3f7df00e4a4a175cb4478540dfcedb36f6b88c96dde377916c7679a7f

See more details on using hashes here.

File details

Details for the file interface_mixins-0.0.4-py3-none-any.whl.

File metadata

File hashes

Hashes for interface_mixins-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 b2301850e8c7e40b11f64fb82d08cd4ab27c2836e92e5bd4f53549a7e23c77b4
MD5 c5777e4cfec3931025a762294386c77e
BLAKE2b-256 cd800e2a5ba7704f7fef6320b2c1c2199033976941d218d2a1755209d09505b1

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.0.4 This release

2 files

0.0.3

1 file

0.0.2

1 file

0.0.1

1 file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page