# Path: pyecore/notification.py
# class EObserver(object):
#     def __init__(self, notifier=None, notifyChanged=None):
#         if notifier:
#             notifier.listeners.append(self)
#         if notifyChanged:
#             self.notifyChanged = notifyChanged
# 
#     def observe(self, notifier):
#         notifier.listeners.append(self)
# 
#     def notifyChanged(self, notification):
#         pass
# 
# class Kind(Enum):
#     ADD = 0
#     ADD_MANY = 1
#     MOVE = 2
#     REMOVE = 3
#     REMOVE_MANY = 4
#     SET = 5
#     UNSET = 6


import pytest
from pyecore.ecore import *
from pyecore.notification import EObserver, Kind
    from pyecore.resources import Resource
    @EMetaclass
    class A(object):
        tob = EReference()

    @EMetaclass
    class B(object):
        toa = EReference(eType=A, upper=-1, eOpposite=A.tob)

    A.tob.eType = B

    a = A()
    b = B()
    o1 = ObserverCounter(notifier=a)

    a.tob = b
    assert o1.calls == 1


def test_notification_add_resource():
    root = EPackage(name='test')

    resource = Resource()

    o1 = ObserverCounter(resource)
    resource.append(root)
    assert o1.calls == 0  # does not trigger any notification

    A = EClass('A')
    root.eClassifiers.append(A)
    assert o1.calls == 2

# Path: pyecore/notification.py
# class EObserver(object):
#     def __init__(self, notifier=None, notifyChanged=None):
#         if notifier:
#             notifier.listeners.append(self)
#         if notifyChanged:
#             self.notifyChanged = notifyChanged
# 
#     def observe(self, notifier):
#         notifier.listeners.append(self)
# 
#     def notifyChanged(self, notification):
#         pass
# 
# class Kind(Enum):
#     ADD = 0
#     ADD_MANY = 1
#     MOVE = 2
#     REMOVE = 3
#     REMOVE_MANY = 4
#     SET = 5
#     UNSET = 6


# Path: tests/test_notifications.py
import pytest
from pyecore.ecore import *
from pyecore.notification import EObserver, Kind
    from pyecore.resources import Resource

    @EMetaclass
    class A(object):
        tob = EReference()

    @EMetaclass
    class B(object):
        toa = EReference(eType=A, upper=-1, eOpposite=A.tob)

    A.tob.eType = B

    a = A()
    b = B()
    o1 = ObserverCounter(notifier=a)

    a.tob = b
    assert o1.calls == 1


def test_notification_add_resource():
    root = EPackage(name='test')

    resource = Resource()

    o1 = ObserverCounter(resource)
    resource.append(root)
    assert o1.calls == 0  # does not trigger any notification

    A = EClass('A')
    root.eClassifiers.append(A)
    assert o1.calls == 2

    assert o1.kind == Kind.ADD