# 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
        @dispatch
        def do_switch(self, o):
            self.default += 1
            assert o.__class__.__name__ not in ('A', 'B')

        @do_switch.register(A)
        def _(self, o):
            self.a += 1
            assert o.__class__.__name__ == 'A'

        @do_switch.register(B)
        def _(self, o):
            self.b += 1
            assert o.__class__.__name__ == 'B'

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

    assert switch.a == 3
    assert switch.b == 2
    assert switch.default == 1


def test_dispatch_default_dynamic():
    A = EClass('A')
    B = EClass('B', superclass=(A,))
    C = EClass('C')

    class InheritanceSwitch(object):

# 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

        @dispatch
        def do_switch(self, o):
            self.default += 1
            assert o.__class__.__name__ not in ('A', 'B')

        @do_switch.register(A)
        def _(self, o):
            self.a += 1
            assert o.__class__.__name__ == 'A'

        @do_switch.register(B)
        def _(self, o):
            self.b += 1
            assert o.__class__.__name__ == 'B'

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

    assert switch.a == 3
    assert switch.b == 2
    assert switch.default == 1


def test_dispatch_default_dynamic():
    A = EClass('A')
    B = EClass('B', superclass=(A,))
    C = EClass('C')

    class InheritanceSwitch(object):

        def __init__(self):