aboutsummaryrefslogtreecommitdiffstats
path: root/tests/test_interfaces.py
blob: e8e97022840b8b0d6bb4ec8f15fa162be8468937 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import abc

import pytest

import six

from cryptography.utils import (
    InterfaceNotImplemented, register_interface, verify_interface
)


class TestVerifyInterface(object):
    def test_verify_missing_method(self):
        @six.add_metaclass(abc.ABCMeta)
        class SimpleInterface(object):
            @abc.abstractmethod
            def method(self):
                pass

        @register_interface(SimpleInterface)
        class NonImplementer(object):
            pass

        with pytest.raises(InterfaceNotImplemented):
            verify_interface(SimpleInterface, NonImplementer)

    def test_different_arguments(self):
        @six.add_metaclass(abc.ABCMeta)
        class SimpleInterface(object):
            @abc.abstractmethod
            def method(self, a):
                pass

        @register_interface(SimpleInterface)
        class NonImplementer(object):
            def method(self):
                pass

        with pytest.raises(InterfaceNotImplemented):
            verify_interface(SimpleInterface, NonImplementer)