<commit_before>"""pytest unittests"""
import sys
import pytest

from implements import Interface, implements


py36 = pytest.mark.skipif(sys.version_info < (3, 6), reason='requires py3.6')


def test_empty():
    class FooInterface(Interface):
        pass

    @implements(FooInterface)
    class FooImplementation:
        pass


def test_with_args_kwargs():
    class FooInterface(Interface):
        def foo(self, a, b=1, *args, **kwargs):
            pass

    with pytest.raises(NotImplementedError):
        @implements(FooInterface)
        class FooImplementationFail:
            def foo(self, a, b=7, *args):
                pass

    @implements(FooInterface)
    class FooImplementationPass:
        def foo(self, a, b=1, *args, **kwargs):
            pass


def test_with_kwarg_only():
    class FooInterface(Interface):
        def foo(self, a, *, b):
            pass

    with pytest.raises(NotImplementedError):
        @implements(FooInterface)
        class FooImplementationFail:
            def foo(self, a, b):
                pass

    @implements(FooInterface)
    class FooImplementationPass:
        def foo(self, a, *, b):
            pass


def test_property():
    class FooInterface(Interface):
        @property
        def foo(self):
            pass

    with pytest.raises(NotImplementedError):
        @implements(FooInterface)
        class FooImplementationFail:
            def foo(self):
                pass

    @implements(FooInterface)
    class FooImplementationPass:
        @property
        def foo(self):
            pass


def test_setters():
    class FooInterface(Interface):
        @property
        def foo(self):
            pass

        @foo.setter
        def foo(self, val):
            pass

    with pytest.raises(NotImplementedError):
        @implements(FooInterface)
        class FooImplementationFail:
            @property
            def foo(self):
                pass

    @implements(FooInterface)
    class FooImplementationPass:
        @property
        def foo(self):
            pass

        @foo.setter
        def foo(self, val):
            pass


def test_deleters():
    class FooInterface(Interface):
        @property
        def foo(self):
            pass

        @foo.deleter
        def foo(self, val):
            pass

    with pytest.raises(NotImplementedError):
        @implements(FooInterface)
        class FooImplementationFail:
            @property
            def foo(self):
                pass

    @implements(FooInterface)
    class FooImplementationPass:
        @property
        def foo(self):
            pass

        @foo.deleter
        def foo(self, val):
            pass


def test_missing_method():
    class FooInterface(Interface):
        def foo(self):
            pass

    with pytest.raises(NotImplementedError):
        @implements(FooInterface)
        class FooImplementationFail:
            pass

    @implements(FooInterface)
    class FooImplementationPass:
        def foo(self):
            pass


def test_missing_argument():
    class FooInterface(Interface):
        def foo(self, arg):
            pass

    with pytest.raises(NotImplementedError):
        @implements(FooInterface)
        class FooImplementationFail:
            def foo(self):
                pass

    @implements(FooInterface)
    class FooImplementationPass:
        def foo(self, arg):
            pass


def test_renamed_argument():
    class FooInterface(Interface):
        def foo(self, arg):
            pass

    with pytest.raises(NotImplementedError):
        @implements(FooInterface)
        class FooImplementationFail:
            def foo(self, arrrrg):
                pass

    @implements(FooInterface)
    class FooImplementationPass:
        def foo(self, arg):
            pass


def test_extra_argument():
    class FooInterface(Interface):
        def foo(self, arg):
            pass

    with pytest.raises(NotImplementedError):
        @implements(FooInterface)
        class FooImplementationFail:
            def foo(self, arg, ument):
                pass

    @implements(FooInterface)
    class FooImplementationPass:
        def foo(self, arg):
            pass


def test_different_defaults():
    class FooInterface(Interface):
        def foo(self, arg=7):
            pass

    with pytest.raises(NotImplementedError):
        @implements(FooInterface)
        class FooImplementationFail:
            def foo(self, arg=8):
                pass

    @implements(FooInterface)
    class FooImplementationPass:
        def foo(self, arg=7):
            pass


def test_different_order():
    class FooInterface(Interface):
        def foo(self, a, b):
            pass

    with pytest.raises(NotImplementedError):
        @implements(FooInterface)
        class FooImplementationFail:
            def foo(self, b, a):
                pass

    @implements(FooInterface)
    class FooImplementationPass:
        def foo(self, a, b):
            pass


def test_missing_kwargs():
    class FooInterface(Interface):
        def foo(self, **kwargs):
            pass

    with pytest.raises(NotImplementedError):
        @implements(FooInterface)
        class FooImplementationFail:
            def foo(self):
                pass

    @implements(FooInterface)
    class FooImplementationPass:
        def foo(self, **kwargs):
            pass


def test_missing_property():
    class FooInterface(Interface):
        @property
        def foo(self):
            pass

    with pytest.raises(NotImplementedError):    # missing method
        @implements(FooInterface)
        class FooImplementationFail:
            pass

    with pytest.raises(NotImplementedError):    # missing property decorator
        @implements(FooInterface)
        class FooImplementationFail:
            def foo(self):
                pass

    @implements(FooInterface)
    class FooImplementationPass:
        @property
        def foo(self):
            pass


def test_bad_constructor():
    class FooInterface(Interface):
        def __init__(self, a):
            pass

    with pytest.raises(NotImplementedError):
        @implements(FooInterface)
        class FooImplementationFail:
            def __init__(self):
                pass

    @implements(FooInterface)
    class FooImplementationPass:
        def __init__(self, a):
            pass


def test_static():
    class FooInterface(Interface):
        @staticmethod
        def foo():
            pass

    with pytest.raises(NotImplementedError):
        @implements(FooInterface)
        class FooImplementation:
            pass


def test_kwargs_only():
    class FooInterface(Interface):
        def foo(self, *, a):
            pass

    with pytest.raises(NotImplementedError):
        @implements(FooInterface)
        class FooImplementation:
            def foo(self, a):
                pass


def test_multiple_interfaces():
    class FooInterface(Interface):
        def foo(self):
            pass

    class BarInterface(Interface):
        def bar(self):
            pass

    with pytest.raises(NotImplementedError):
        @implements(BarInterface)
        @implements(FooInterface)
        class FooImplementationNoBar:
            def foo(self, a):
                pass

    with pytest.raises(NotImplementedError):
        @implements(BarInterface)
        @implements(FooInterface)
        class FooImplementationNoFoo:
            def bar(self, a):
                pass

    @implements(BarInterface)
    @implements(FooInterface)
    class FooImplementation:
        def foo(self):
            pass

        def bar(self):
            pass


def test_interface_name_collision():
    class Foo1Interface(Interface):
        def foo(self):
            pass

    class Foo2Interface(Interface):
        def foo(self):
            pass

    @implements(Foo2Interface)
    @implements(Foo1Interface)
    class FooImplementation:
        def foo(self):
            pass


def test_interface_name_and_signature_collision():
    class Foo1Interface(Interface):
        def foo(self):
            pass

    class Foo2Interface(Interface):
        def foo(self) -> str:
            return 'foo'

    # Two interfaces with different signatures for a given method will
    # always result in failure for the implementing class, as the
    # implemented method's signature can only satisfy one of the interfaces.

    with pytest.raises(NotImplementedError):
        @implements(Foo2Interface)
        @implements(Foo1Interface)
        class FooImplementationFail:
            def foo(self):
                pass


def test_interface_inheritance():
    class BaseInterface(Interface):
        def bar(self):
            pass

    class FooInterface(BaseInterface):
        def foo(self):
            pass

    with pytest.raises(NotImplementedError):
        @implements(FooInterface)
        class FooImplementationFail:
            def foo(self):
                pass

    @implements(FooInterface)
    class FooImplementationPass(object):
        def foo(self):
            pass
        def bar(self):
            pass


def test_class_inheritance():
    # TODO
    class FooInterface(Interface):
        def foo(self):
            pass

    @implements(FooInterface)
    class ParentImplementation:
        def foo(self):
            pass

    @implements(FooInterface)
    class ChildImplementation(ParentImplementation):
        pass


def test_rtn_type_annotation():
    class FooInterface(Interface):
        def foo(self) -> str:
            pass

    with pytest.raises(NotImplementedError):
        @implements(FooInterface)
        class FooImplementationFail:
            def foo(self) -> int:
                pass<commit_msg>Added a test for inheritance of interface classes and mixin of implementation<commit_after>"""pytest unittests"""
import sys
import pytest

from implements import Interface, implements


py36 = pytest.mark.skipif(sys.version_info < (3, 6), reason='requires py3.6')


def test_empty():
    class FooInterface(Interface):
        pass

    @implements(FooInterface)
    class FooImplementation:
        pass


def test_with_args_kwargs():
    class FooInterface(Interface):
        def foo(self, a, b=1, *args, **kwargs):
            pass

    with pytest.raises(NotImplementedError):
        @implements(FooInterface)
        class FooImplementationFail:
            def foo(self, a, b=7, *args):
                pass

    @implements(FooInterface)
    class FooImplementationPass:
        def foo(self, a, b=1, *args, **kwargs):
            pass


def test_with_kwarg_only():
    class FooInterface(Interface):
        def foo(self, a, *, b):
            pass

    with pytest.raises(NotImplementedError):
        @implements(FooInterface)
        class FooImplementationFail:
            def foo(self, a, b):
                pass

    @implements(FooInterface)
    class FooImplementationPass:
        def foo(self, a, *, b):
            pass


def test_property():
    class FooInterface(Interface):
        @property
        def foo(self):
            pass

    with pytest.raises(NotImplementedError):
        @implements(FooInterface)
        class FooImplementationFail:
            def foo(self):
                pass

    @implements(FooInterface)
    class FooImplementationPass:
        @property
        def foo(self):
            pass


def test_setters():
    class FooInterface(Interface):
        @property
        def foo(self):
            pass

        @foo.setter
        def foo(self, val):
            pass

    with pytest.raises(NotImplementedError):
        @implements(FooInterface)
        class FooImplementationFail:
            @property
            def foo(self):
                pass

    @implements(FooInterface)
    class FooImplementationPass:
        @property
        def foo(self):
            pass

        @foo.setter
        def foo(self, val):
            pass


def test_deleters():
    class FooInterface(Interface):
        @property
        def foo(self):
            pass

        @foo.deleter
        def foo(self, val):
            pass

    with pytest.raises(NotImplementedError):
        @implements(FooInterface)
        class FooImplementationFail:
            @property
            def foo(self):
                pass

    @implements(FooInterface)
    class FooImplementationPass:
        @property
        def foo(self):
            pass

        @foo.deleter
        def foo(self, val):
            pass


def test_missing_method():
    class FooInterface(Interface):
        def foo(self):
            pass

    with pytest.raises(NotImplementedError):
        @implements(FooInterface)
        class FooImplementationFail:
            pass

    @implements(FooInterface)
    class FooImplementationPass:
        def foo(self):
            pass


def test_missing_argument():
    class FooInterface(Interface):
        def foo(self, arg):
            pass

    with pytest.raises(NotImplementedError):
        @implements(FooInterface)
        class FooImplementationFail:
            def foo(self):
                pass

    @implements(FooInterface)
    class FooImplementationPass:
        def foo(self, arg):
            pass


def test_renamed_argument():
    class FooInterface(Interface):
        def foo(self, arg):
            pass

    with pytest.raises(NotImplementedError):
        @implements(FooInterface)
        class FooImplementationFail:
            def foo(self, arrrrg):
                pass

    @implements(FooInterface)
    class FooImplementationPass:
        def foo(self, arg):
            pass


def test_extra_argument():
    class FooInterface(Interface):
        def foo(self, arg):
            pass

    with pytest.raises(NotImplementedError):
        @implements(FooInterface)
        class FooImplementationFail:
            def foo(self, arg, ument):
                pass

    @implements(FooInterface)
    class FooImplementationPass:
        def foo(self, arg):
            pass


def test_different_defaults():
    class FooInterface(Interface):
        def foo(self, arg=7):
            pass

    with pytest.raises(NotImplementedError):
        @implements(FooInterface)
        class FooImplementationFail:
            def foo(self, arg=8):
                pass

    @implements(FooInterface)
    class FooImplementationPass:
        def foo(self, arg=7):
            pass


def test_different_order():
    class FooInterface(Interface):
        def foo(self, a, b):
            pass

    with pytest.raises(NotImplementedError):
        @implements(FooInterface)
        class FooImplementationFail:
            def foo(self, b, a):
                pass

    @implements(FooInterface)
    class FooImplementationPass:
        def foo(self, a, b):
            pass


def test_missing_kwargs():
    class FooInterface(Interface):
        def foo(self, **kwargs):
            pass

    with pytest.raises(NotImplementedError):
        @implements(FooInterface)
        class FooImplementationFail:
            def foo(self):
                pass

    @implements(FooInterface)
    class FooImplementationPass:
        def foo(self, **kwargs):
            pass


def test_missing_property():
    class FooInterface(Interface):
        @property
        def foo(self):
            pass

    with pytest.raises(NotImplementedError):    # missing method
        @implements(FooInterface)
        class FooImplementationFail:
            pass

    with pytest.raises(NotImplementedError):    # missing property decorator
        @implements(FooInterface)
        class FooImplementationFail:
            def foo(self):
                pass

    @implements(FooInterface)
    class FooImplementationPass:
        @property
        def foo(self):
            pass


def test_bad_constructor():
    class FooInterface(Interface):
        def __init__(self, a):
            pass

    with pytest.raises(NotImplementedError):
        @implements(FooInterface)
        class FooImplementationFail:
            def __init__(self):
                pass

    @implements(FooInterface)
    class FooImplementationPass:
        def __init__(self, a):
            pass


def test_static():
    class FooInterface(Interface):
        @staticmethod
        def foo():
            pass

    with pytest.raises(NotImplementedError):
        @implements(FooInterface)
        class FooImplementation:
            pass


def test_kwargs_only():
    class FooInterface(Interface):
        def foo(self, *, a):
            pass

    with pytest.raises(NotImplementedError):
        @implements(FooInterface)
        class FooImplementation:
            def foo(self, a):
                pass


def test_multiple_interfaces():
    class FooInterface(Interface):
        def foo(self):
            pass

    class BarInterface(Interface):
        def bar(self):
            pass

    with pytest.raises(NotImplementedError):
        @implements(BarInterface)
        @implements(FooInterface)
        class FooImplementationNoBar:
            def foo(self, a):
                pass

    with pytest.raises(NotImplementedError):
        @implements(BarInterface)
        @implements(FooInterface)
        class FooImplementationNoFoo:
            def bar(self, a):
                pass

    @implements(BarInterface)
    @implements(FooInterface)
    class FooImplementation:
        def foo(self):
            pass

        def bar(self):
            pass


def test_interface_name_collision():
    class Foo1Interface(Interface):
        def foo(self):
            pass

    class Foo2Interface(Interface):
        def foo(self):
            pass

    @implements(Foo2Interface)
    @implements(Foo1Interface)
    class FooImplementation:
        def foo(self):
            pass


def test_interface_name_and_signature_collision():
    class Foo1Interface(Interface):
        def foo(self):
            pass

    class Foo2Interface(Interface):
        def foo(self) -> str:
            return 'foo'

    # Two interfaces with different signatures for a given method will
    # always result in failure for the implementing class, as the
    # implemented method's signature can only satisfy one of the interfaces.

    with pytest.raises(NotImplementedError):
        @implements(Foo2Interface)
        @implements(Foo1Interface)
        class FooImplementationFail:
            def foo(self):
                pass


def test_interface_inheritance():
    class BaseInterface(Interface):
        def bar(self):
            pass

    class FooInterface(BaseInterface):
        def foo(self):
            pass

    with pytest.raises(NotImplementedError):
        @implements(FooInterface)
        class FooImplementationFail:
            def foo(self):
                pass

    @implements(FooInterface)
    class FooImplementationPass(object):
        def foo(self):
            pass
        def bar(self):
            pass


def test_class_inheritance():
    class FooInterface(Interface):
        def foo(self):
            pass

    @implements(FooInterface)
    class ParentImplementation:
        def foo(self):
            pass

    @implements(FooInterface)
    class ChildImplementation(ParentImplementation):
        pass


def test_class_multiple_inheritance():
    # --------- INTERFACES -----------------------------------------------
    #
    class FooInterface(Interface):
        def foo(self, final):
            pass

    class BarInterface(Interface):
        def bar(self, final):
            pass

    class FooBarInterface(FooInterface, BarInterface):
        pass

    # --------- IMPLEMENTATION -------------------------------------------
    #
    class BaseFooImplementation(object):        # must get overridden
        def foo(self, override, my, args):
            pass

    @implements(FooInterface)
    class FooImplementation(BaseFooImplementation):
        def foo(self, final):
            pass

    @implements(BarInterface)
    class BarImplementation(object):
        def bar(self, final):
            pass

    with pytest.raises(NotImplementedError):
        @implements(FooBarInterface)
        class SubFooImplementation(FooImplementation):  # foo, no bar
            pass

    @implements(FooInterface)
    @implements(BarInterface)
    @implements(FooBarInterface)
    class FooBarImplementation(FooImplementation, BarImplementation):
        pass


def test_rtn_type_annotation():
    class FooInterface(Interface):
        def foo(self) -> str:
            pass

    with pytest.raises(NotImplementedError):
        @implements(FooInterface)
        class FooImplementationFail:
            def foo(self) -> int:
                pass
{'fraction_non_alphanumeric': 0.08278161697192288, 'fraction_numerical': 0.0019330208282994248, 'mean_word_length': 2.0039192916243285, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2663428', 'n_tokens_mistral': 5840, 'n_tokens_neox': 5434, 'n_words': 1284}