blob: bcc1010a5b67a7be3950d66b51c7c7ace594e09b [file] [log] [blame]
Alex Gaynorf6d8ccc2014-10-21 11:03:31 -07001# Licensed under the Apache License, Version 2.0 (the "License");
2# you may not use this file except in compliance with the License.
3# You may obtain a copy of the License at
4#
5# http://www.apache.org/licenses/LICENSE-2.0
6#
7# Unless required by applicable law or agreed to in writing, software
8# distributed under the License is distributed on an "AS IS" BASIS,
9# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
10# implied.
11# See the License for the specific language governing permissions and
12# limitations under the License.
13
Alex Gaynor87112402014-10-21 10:56:33 -070014import abc
15
16import pytest
17
18import six
19
20from cryptography.utils import (
21 InterfaceNotImplemented, register_interface, verify_interface
22)
23
24
25class TestVerifyInterface(object):
26 def test_verify_missing_method(self):
27 @six.add_metaclass(abc.ABCMeta)
28 class SimpleInterface(object):
29 @abc.abstractmethod
30 def method(self):
31 pass
32
33 @register_interface(SimpleInterface)
34 class NonImplementer(object):
35 pass
36
37 with pytest.raises(InterfaceNotImplemented):
38 verify_interface(SimpleInterface, NonImplementer)
39
40 def test_different_arguments(self):
41 @six.add_metaclass(abc.ABCMeta)
42 class SimpleInterface(object):
43 @abc.abstractmethod
44 def method(self, a):
45 pass
46
47 @register_interface(SimpleInterface)
48 class NonImplementer(object):
49 def method(self):
50 pass
51
52 with pytest.raises(InterfaceNotImplemented):
53 verify_interface(SimpleInterface, NonImplementer)