Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_user_module_derived_from_mixin_(pygen_output_dir):
rootpkg = EPackage('derived_from_mixin')
c1 = EClass('MyClass')
c1.eOperations.append(EOperation('do_it'))
c1.eStructuralFeatures.append(EAttribute('any', EString, derived=True))
rootpkg.eClassifiers.append(c1)
c2 = EClass('MyOtherClass')
c2.eStructuralFeatures.append(EAttribute('other', EString, derived=True))
c2.eStructuralFeatures.append(EReference('toc', c1, derived=True))
c2.eSuperTypes.append(c1)
rootpkg.eClassifiers.append(c2)
mm = generate_meta_model(rootpkg, pygen_output_dir, user_module='user_provided.module')
c = mm.MyOtherClass(any='any', other='other')
assert isinstance(c, MyClassMixin)
assert isinstance(c, MyOtherClassMixin)
assert isinstance(c, mm.MyClass)
assert c.any == 'any'
c.mock_other.assert_called_once_with('other')
assert not c.do_it.called
c.do_it()
def lib():
package = Ecore.EPackage('mypackage')
package.nsURI = 'http://simplemetamodel/1.0'
package.nsPrefix = 'simplemm'
AbsA = Ecore.EClass('AbsA', abstract=True)
A = Ecore.EClass('A', superclass=(AbsA,))
SubA = Ecore.EClass('SubA', superclass=(A,))
MyRoot = Ecore.EClass('MyRoot')
MyRoot.a_container = Ecore.EReference('a_container', eType=AbsA, upper=-1,
containment=True)
MyRoot.eStructuralFeatures.append(MyRoot.a_container)
MyRoot.eStructuralFeatures.append(Ecore.EAttribute('trans',
eType=Ecore.EString,
transient=True))
package.eClassifiers.extend([MyRoot, A, SubA, AbsA])
package.MyRoot = MyRoot
package.SubA = SubA
package.A = A
# we register the metamodel first
global_registry[package.nsURI] = package
return package
def test__ecore_task__filtered_elements():
# prepare test model:
# -------------------
# ThePackage
# Class1
# SubPackage
# Class2
# MyEnum
package = EPackage('ThePackage')
class1 = EClass('Class1')
class2 = EClass('Class2')
enum = EEnum('MyEnum', literals=['A', 'B'])
subpackage = EPackage('SubPackage')
package.eSubpackages.append(subpackage)
package.eClassifiers.append(class1)
subpackage.eClassifiers.extend([class2, enum])
task = EcoreTask()
task.element_type = EPackage
assert set(task.filtered_elements(package)) == {package, subpackage}
task.element_type = EClass
assert set(task.filtered_elements(package)) == {class1, class2}
def lib():
package = Ecore.EPackage('mypackage')
package.nsURI = 'http://simplemetamodel/1.0'
package.nsPrefix = 'simplemm'
AbsA = Ecore.EClass('AbsA', abstract=True)
AbsA.eStructuralFeatures.append(Ecore.EReference('toa', AbsA))
A = Ecore.EClass('A', superclass=(AbsA,))
SubA = Ecore.EClass('SubA', superclass=(A,))
MyRoot = Ecore.EClass('MyRoot')
MyRoot.a_container = Ecore.EReference('a_container', eType=AbsA, upper=-1,
containment=True)
MyRoot.eStructuralFeatures.append(MyRoot.a_container)
package.eClassifiers.extend([MyRoot, A, SubA, AbsA])
package.MyRoot = MyRoot
package.SubA = SubA
package.A = A
# we register the metamodel first
global_registry[package.nsURI] = package
return package
prefix, _type = self._type_attribute(node).split(':')
if not prefix:
raise ValueError('Prefix {0} is not registered, line {1}'
.format(prefix, node.tag))
epackage = self.prefix2epackage(prefix)
etype = epackage.getEClassifier(_type)
if not etype:
raise ValueError('Type {0} is unknown in {1}, line{2}'
.format(_type, epackage, node.tag))
else:
etype = feature_container.eType
if isinstance(etype, EProxy):
etype.force_resolve()
# we create the instance
if etype is EClass or etype is EClass.eClass:
name = node.get('name')
eobject = etype(name)
elif (etype is EStringToStringMapEntry
or etype is EStringToStringMapEntry.eClass) \
and feature_container is EAnnotation.details:
annotation_key = node.get('key')
annotation_value = node.get('value')
parent_eobj.details[annotation_key] = annotation_value
if annotation_key == 'documentation':
container = parent_eobj.eContainer()
if hasattr(container, 'python_class'):
container = container.python_class
container.__doc__ = annotation_value
return (None, None, tuple(), tuple(), False)
elif isinstance(etype, EDataType):
key = node.tag
EClassifier.eTypeParameters = EReference('eTypeParameters', ETypeParameter,
upper=-1, containment=True)
EClassifier.instanceTypeName = EAttribute('instanceTypeName', EString)
EClassifier.instanceClass = EAttribute('instanceClass', EJavaClass)
EClassifier.defaultValue = EAttribute('defaultValue', EJavaObject)
EClassifier.instanceTypeName = EAttribute('instanceTypeName', EString,
volatile=True, unsettable=True)
EDataType.instanceClassName_ = EAttribute('instanceClassName', EString)
EDataType.serializable = EAttribute('serializable', EBoolean)
EClass.abstract = EAttribute('abstract', EBoolean)
EClass.eStructuralFeatures = EReference('eStructuralFeatures',
EStructuralFeature,
upper=-1, containment=True)
EClass.eGenericSuperTypes = EReference('eGenericSuperTypes', EGenericType,
containment=True, upper=-1)
EClass.eAttributes_ = EReference('eAttributes', EAttribute,
upper=-1, derived=True)
EClass.eReferences_ = EReference('eReferences', EReference,
upper=-1, derived=True)
EClass.eSuperTypes = EReference('eSuperTypes', EClass, upper=-1)
EClass.eOperations = EReference('eOperations', EOperation,
upper=-1, containment=True)
EClass.instanceClassName = EAttribute('instanceClassName', EString)
EClass.interface = EAttribute('interface', EBoolean)
EStructuralFeature.eContainingClass = \
EReference('eContainingClass', EClass,
eOpposite=EClass.eStructuralFeatures)
EReference.containment = EAttribute('containment', EBoolean)
lower=1, eOpposite=EPackage.eSubpackages)
EClassifier.ePackage = EReference('ePackage', EPackage,
eOpposite=EPackage.eClassifiers)
EClassifier.eTypeParameters = EReference('eTypeParameters', ETypeParameter,
upper=-1, containment=True)
EClassifier.instanceTypeName = EAttribute('instanceTypeName', EString)
EClassifier.instanceClass = EAttribute('instanceClass', EJavaClass)
EClassifier.defaultValue = EAttribute('defaultValue', EJavaObject)
EClassifier.instanceTypeName = EAttribute('instanceTypeName', EString,
volatile=True, unsettable=True)
EDataType.instanceClassName_ = EAttribute('instanceClassName', EString)
EDataType.serializable = EAttribute('serializable', EBoolean)
EClass.abstract = EAttribute('abstract', EBoolean)
EClass.eStructuralFeatures = EReference('eStructuralFeatures',
EStructuralFeature,
upper=-1, containment=True)
EClass.eGenericSuperTypes = EReference('eGenericSuperTypes', EGenericType,
containment=True, upper=-1)
EClass.eAttributes_ = EReference('eAttributes', EAttribute,
upper=-1, derived=True)
EClass.eReferences_ = EReference('eReferences', EReference,
upper=-1, derived=True)
EClass.eSuperTypes = EReference('eSuperTypes', EClass, upper=-1)
EClass.eOperations = EReference('eOperations', EOperation,
upper=-1, containment=True)
EClass.instanceClassName = EAttribute('instanceClassName', EString)
EClass.interface = EAttribute('interface', EBoolean)
EStructuralFeature.eContainingClass = \
new_supers = self.__compute_supertypes()
self.python_class.__bases__ = new_supers
elif notif.feature is EClass.eOperations:
if notif.kind is Kind.ADD:
self.__create_fun(notif.new)
elif notif.kind is Kind.REMOVE:
delattr(self.python_class, notif.old.name)
elif notif.feature is EClass.eStructuralFeatures:
if notif.kind is Kind.ADD:
setattr(self.python_class, notif.new.name, notif.new)
elif notif.kind is Kind.ADD_MANY:
for x in notif.new:
setattr(self.python_class, x.name, x)
elif notif.kind is Kind.REMOVE:
delattr(self.python_class, notif.old.name)
elif notif.feature is EClass.name and notif.kind is Kind.SET:
self.python_class.__name__ = notif.new
self.__name__ = notif.new
result.abstract = self.abstract
for attribute in self.eAttributes:
result.eStructuralFeatures.append(copyEAttribute(attribute))
parent.eClassifiers.append(self)
@mapping
def copyEAttribute(self: Ecore.EAttribute) -> Ecore.EAttribute:
result.name = self.name + 'Copy'
result.lowerBound = self.lowerBound
result.upperBound = self.upperBound
result.eType = self.eType
root = Ecore.EPackage('test')
A1 = Ecore.EClass('A1')
root.eClassifiers.append(A1)
A1.eStructuralFeatures.append(Ecore.EAttribute('name', eType=Ecore.EString))
inPackage = root
result = createEPackage(inPackage)
rset = ResourceSet()
outresource = rset.create_resource(URI('testt.xmi'))
outresource.append(result)
outresource.save()