Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import pytest
from pyecore.ecore import *
from pyecore.notification import EObserver, Kind
class ObserverCounter(EObserver):
def __init__(self, notifier=None):
super().__init__(notifier=notifier)
self.calls = 0
def notifyChanged(self, notification):
self.calls += 1
self.kind = notification.kind
self.feature = notification.feature
def test_notification_add_onecall():
root = EPackage(name='test')
A = EClass('A')
o1 = ObserverCounter(root)
o2 = ObserverCounter(A)
root.eClassifiers.append(A)
import pytest
import library as lib
from pyecore.notification import EObserver, Kind
class LastNotification(EObserver):
def __init__(self, notifier=None):
super().__init__(notifier=notifier)
self.notification = None
def notifyChanged(self, notification):
self.notification = notification
def test_notification_static_set():
library = lib.Library()
o = LastNotification(library)
library.name = 'SuperLib'
notif = o.notification
assert notif.kind is Kind.SET
assert notif.new == 'SuperLib'
assert notif.old is None
def test_notification_dummy(lib):
root = lib.Root()
a1 = lib.A()
observer = EObserver()
observer.observe(root)
root.namedElements.append(a1)
def test_notification_print(lib):
root = lib.Root()
a1 = lib.A()
observer = EObserver()
observer.observe(root)
observer.notify = lambda x: print(x)
root.namedElements.append(a1)
import pytest
from pyecore.ecore import *
from pyecore.commands import *
from pyecore.resources import URI, ResourceSet
from pyecore.utils import DynamicEPackage
from pyecore.notification import EObserver, Kind
from os import path
class LastObserver(EObserver):
def __init__(self, notifier=None):
super().__init__(notifier=notifier)
self.last = None
def notifyChanged(self, notification):
self.last = notification
@pytest.fixture(scope='module')
def mm():
Root = EClass('Root')
A = EClass('A')
B = EClass('B')
Root.eStructuralFeatures.append(EReference('a_s', A, upper=-1,
containment=True))
Root.eStructuralFeatures.append(EReference('bs', B, upper=-1,
o1.notifyChanged = lambda x: assert_wrap(x.kind is Kind.SET
and x.old is 'test'
and x.new is 'test2'
and x.feature.name == 'name'
and x.notifier is a1)
a1.name = 'test2'
o1.notifyChanged = lambda x: assert_wrap(x.kind is Kind.UNSET
and x.old is 'test2'
and x.new is None
and x.feature.name == 'name'
and x.notifier is a1)
a1.name = None
class ObserverCounter(EObserver):
def __init__(self, notifier=None):
super().__init__(notifier=notifier)
self.calls = 0
def notifyChanged(self, notification):
self.repr = notification.__repr__()
self.calls += 1
self.kind = notification.kind
self.value = notification.new
def test_notification_add_many(lib):
root = lib.Root()
a1 = lib.A()
a2 = lib.A()
o = ObserverCounter(root)
root.namedElements.extend([a1, a2])
def test_notification_eopposite(lib):
a1 = lib.A()
b1 = lib.B()
notify = lambda x: assert_wrap(x.kind is Kind.ADD
and x.new is a1
and x.feature.name == 'inner'
and x.notifier is b1)
o1 = EObserver(b1, notifyChanged=notify)
notify = lambda x: assert_wrap(x.kind is Kind.SET
and x.new is b1
and x.feature.name == 'parent'
and x.notifier is a1)
o2 = EObserver(a1, notifyChanged=notify)
import typing
import pyecore.ecore as Ecore
from functools import lru_cache, wraps
from pyecore.notification import EObserver
class ResultObserver(EObserver):
def notifyChanged(self, notif):
print(notif)
class EObjectProxy(object):
def __init__(self, instance):
object.__setattr__(self, 'wrapped', instance)
object.__setattr__(self, 'wrapped_eClass', instance.eClass)
def __getattribute__(self, name):
wrapped = object.__getattribute__(self, 'wrapped')
eClass = object.__getattribute__(self, 'wrapped_eClass')
result = getattr(wrapped, name)
if eClass.findEStructuralFeature(name):
print('access', name, ':', result, 'for', wrapped)
return result
import typing
import pyecore.ecore as Ecore
from pyecore.resources import ResourceSet, URI, Resource
import functools
from pyecore.notification import EObserver
import inspect
import TransformationTrace as trace
class ResultObserver(EObserver):
def notifyChanged(self, notif):
print(notif)
class EObjectProxy(object):
def __init__(self, instance):
object.__setattr__(self, 'wrapped', instance)
object.__setattr__(self, 'wrapped_eClass', instance.eClass)
def __getattribute__(self, name):
wrapped = object.__getattribute__(self, 'wrapped')
eClass = object.__getattribute__(self, 'wrapped_eClass')
result = getattr(wrapped, name)
if eClass.findEStructuralFeature(name):
print('access', name, ':', result, 'for', wrapped)
return result
"""
This module gathers utility classes and functions that can ease metamodel and
model manipulation.
"""
from .ecore import EPackage, EObject, BadValueError, EClass
from .notification import EObserver, Kind
from functools import singledispatch, update_wrapper
from inspect import ismodule
class DynamicEPackage(EObserver):
"""A DynamicEPackage gives the ability to directly handle metaclasses
from a metamodel as if it were a statically generated EPackage.
Usage from an existing dynamic EPackage named 'myroot' that defines two
EClass: 'A' and 'B'
>>> from pyecore.utils import DynamicEPackage
>>> MyAPI = DynamicEPackage(myroot)
>>> MyAPI.A
>>> a = MyAPI.A()
>>> a
"""
def __init__(self, package):
if not isinstance(package, EPackage):