# Path: pyecore/utils.py
# def dispatch(func):
#     dispatcher = singledispatch(func)
# 
#     def wrapper(*args, **kw):
#         return dispatcher.dispatch(args[1].__class__)(*args, **kw)
# 
#     def register(cls, func=None):
#         if isinstance(cls, EObject):
#             return dispatcher.register(cls.python_class)
#         return dispatcher.register(cls)
#     wrapper.register = register
#     update_wrapper(wrapper, func)
#     return wrapper


import pytest
from pyecore.ecore import *
from pyecore.utils import dispatch
            self.b += 1

    switch = InheritanceSwitch()
    for x in [A(), B(), A(), B(), C(), A()]:
        switch.do_switch(x)

    assert switch.a == 3
    assert switch.b == 3
    assert switch.default == 0


def test_dispatch_default_static():
    @EMetaclass
    class A(object):
        pass

    @EMetaclass
    class B(A):
        pass

    @EMetaclass
    class C(object):
        pass

    class InheritanceSwitch(object):
        def __init__(self):
            self.a = 0
            self.b = 0
            self.default = 0


# Path: pyecore/utils.py
# def dispatch(func):
#     dispatcher = singledispatch(func)
# 
#     def wrapper(*args, **kw):
#         return dispatcher.dispatch(args[1].__class__)(*args, **kw)
# 
#     def register(cls, func=None):
#         if isinstance(cls, EObject):
#             return dispatcher.register(cls.python_class)
#         return dispatcher.register(cls)
#     wrapper.register = register
#     update_wrapper(wrapper, func)
#     return wrapper


# Path: tests/test_dispatch.py
import pytest
from pyecore.ecore import *
from pyecore.utils import dispatch

            self.b += 1

    switch = InheritanceSwitch()
    for x in [A(), B(), A(), B(), C(), A()]:
        switch.do_switch(x)

    assert switch.a == 3
    assert switch.b == 3
    assert switch.default == 0


def test_dispatch_default_static():
    @EMetaclass
    class A(object):
        pass

    @EMetaclass
    class B(A):
        pass

    @EMetaclass
    class C(object):
        pass

    class InheritanceSwitch(object):
        def __init__(self):
            self.a = 0
            self.b = 0
            self.default = 0


        @dispatch