Alex Gaynor | 8711240 | 2014-10-21 10:56:33 -0700 | [diff] [blame^] | 1 | import abc |
| 2 | |
| 3 | import pytest |
| 4 | |
| 5 | import six |
| 6 | |
| 7 | from cryptography.utils import ( |
| 8 | InterfaceNotImplemented, register_interface, verify_interface |
| 9 | ) |
| 10 | |
| 11 | |
| 12 | class TestVerifyInterface(object): |
| 13 | def test_verify_missing_method(self): |
| 14 | @six.add_metaclass(abc.ABCMeta) |
| 15 | class SimpleInterface(object): |
| 16 | @abc.abstractmethod |
| 17 | def method(self): |
| 18 | pass |
| 19 | |
| 20 | @register_interface(SimpleInterface) |
| 21 | class NonImplementer(object): |
| 22 | pass |
| 23 | |
| 24 | with pytest.raises(InterfaceNotImplemented): |
| 25 | verify_interface(SimpleInterface, NonImplementer) |
| 26 | |
| 27 | def test_different_arguments(self): |
| 28 | @six.add_metaclass(abc.ABCMeta) |
| 29 | class SimpleInterface(object): |
| 30 | @abc.abstractmethod |
| 31 | def method(self, a): |
| 32 | pass |
| 33 | |
| 34 | @register_interface(SimpleInterface) |
| 35 | class NonImplementer(object): |
| 36 | def method(self): |
| 37 | pass |
| 38 | |
| 39 | with pytest.raises(InterfaceNotImplemented): |
| 40 | verify_interface(SimpleInterface, NonImplementer) |