How to use the pyecore.ecore.EString function in pyecore

To help you get started, we’ve selected a few pyecore examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pyecore / pyecoregen / tests / test_generated_library.py View on Github external
def test_book_defaultvalue_generated(generated_library):
    book = generated_library.Book()
    assert book.category is generated_library.BookCategory.ScienceFiction
    assert book.pages == 0
    assert book.title is Ecore.EString.default_value
github pyecore / pyecoregen / tests / test_adapter.py View on Github external
def test__pythonic_names():
    p = ecore.EPackage('MyPackage')

    c1 = ecore.EClass('MyClass')
    p.eClassifiers.append(c1)
    a1 = ecore.EAttribute('att', ecore.EString, upper=-1)
    c1.eStructuralFeatures.append(a1)

    c2 = ecore.EClass('pass')
    p.eClassifiers.append(c2)
    a2 = ecore.EAttribute('else', ecore.EString, upper=-1)
    c2.eStructuralFeatures.append(a2)

    assert c2.name == 'pass'
    assert a2.name == 'else'

    with pythonic_names():
        assert c1.name == 'MyClass'
        assert a1.name == 'att'
        assert c2.name == 'pass_'
        assert a2.name == 'else_'

    assert c2.name == 'pass'
    assert a2.name == 'else'
github pyecore / pyecore / tests / simple / simple.py View on Github external
from functools import partial
import pyecore.ecore as Ecore
from pyecore.ecore import EObject, EAttribute, EString, EEnum, EReference, \
                          MetaEClass, EInteger, abstract


nsPrefix = 'simple'
nsURI = 'http://simple/1.0'


@abstract
class AbstractA(EObject, metaclass=MetaEClass):
    name = EAttribute(eType=EString)

    def __init__(self):
        pass


class A(AbstractA):
    def __init__(self):
        pass


class B(EObject, metaclass=MetaEClass):
    a = EReference(eType=AbstractA)

    def __init__(self):
        pass
github pyecore / pyecoregen / tests / test_templates.py View on Github external
def test_class_with_derived_features(pygen_output_dir):
    rootpkg = EPackage('simpleClasses')
    MyClass = EClass('MyClass')
    rootpkg.eClassifiers.append(MyClass)
    any_feature = EAttribute('any', EString, derived=True)
    MyClass.eStructuralFeatures.append(any_feature)

    mm = generate_meta_model(rootpkg, pygen_output_dir)

    generated_class = mm.eClassifiers['MyClass']

    assert mm.MyClass is generated_class
    assert isinstance(mm.MyClass._any, EAttribute)
    assert mm.MyClass._any.derived is True
    assert mm.MyClass._any.name == 'any'
github pyecore / pyecore / tests / xmi / test_xmi_serialization.py View on Github external
# we read the model
    resource = XMIResource(URI(str(f)))
    resource.load()
    assert resource.contents != []
    assert len(resource.contents[0].eContents) == 3


eClass = Ecore.EPackage(name='test', nsURI='http://test/1.0',
                        nsPrefix='test')


@Ecore.EMetaclass
class A(object):
    name = Ecore.EAttribute('name', Ecore.EString)
    age = Ecore.EAttribute('age', Ecore.EInt)
    names = Ecore.EAttribute(eType=Ecore.EString, upper=-1)


def test_xmi_ecore_save_load(tmpdir):
    f = tmpdir.mkdir('pyecore-tmp').join('test.xmi')
    resource = XMIResource(URI(str(f)))

    resource.append(eClass)
    resource.save()

    resource = XMIResource(URI(str(f)))
    resource.load()
    root = resource.contents[0]
    assert root.name == 'test'
    assert root.getEClassifier('A') is not None
github pyecore / pyecore / tests / json / test_json_save.py View on Github external
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
github pyecore / pyecore / tests / json / test_json_load.py View on Github external
from os import path


@pytest.fixture()
def rset():
    rset = ResourceSet()
    rset.resource_factory['json'] = lambda uri: JsonResource(uri)
    return rset


eClass = Ecore.EPackage(nsURI='http://test/1.0', name='pack', nsPrefix='pack')


@Ecore.EMetaclass
class A(object):
    name = Ecore.EAttribute(eType=Ecore.EString)
    children = Ecore.EReference(upper=-1, containment=True)
    parent = Ecore.EReference(eOpposite=children)

    def __init__(self, name=None, children=None):
        if children:
            self.children.update(children)
        self.name = name

    def __repr__(self):
        return self.name


A.children.eType = A
A.parent.eType = A
github pyecore / pyecore / tests / xmi / test_xmi_deserialization.py View on Github external
def test_load_multipleroot_with_refs():
    rset = ResourceSet()
    multi_root = path.join('tests', 'xmi', 'xmi-tests',
                           'multiple_with_refs.xmi')

    package = Ecore.EPackage('amm', 'ammuri', 'amm')
    A = Ecore.EClass('A')
    A.eStructuralFeatures.append(Ecore.EAttribute('name', Ecore.EString))
    A.eStructuralFeatures.append(Ecore.EReference('toa', A))
    A.eStructuralFeatures.append(Ecore.EReference('contains', A,
                                                  containment=True))
    package.eClassifiers.append(A)

    rset.metamodel_registry[package.nsURI] = package
    resource = rset.get_resource(URI(str(multi_root)))

    root1, root2 = resource.contents
    assert root1.contains.toa is root2
    assert root1.name == 'root1'
    assert root2.name == 'root2'
    assert root1.contains.name == 'inner'
github pyecore / pyecoregen / tests / test_templates.py View on Github external
def test_user_module_derived_collection(pygen_output_dir):
    rootpkg = EPackage('derived_collection')
    c1 = EClass('MyClass')
    c1.eStructuralFeatures.append(EAttribute('any', EString, derived=True, upper=-1))
    rootpkg.eClassifiers.append(c1)
    c2 = EClass('MyOtherClass')
    c2.eStructuralFeatures.append(EReference('other', c1, derived=True, upper=-1))
    c2.eSuperTypes.append(c1)
    rootpkg.eClassifiers.append(c2)

    mm = generate_meta_model(rootpkg, pygen_output_dir)

    c = mm.MyOtherClass()
    assert isinstance(c, mm.MyOtherClass)
    assert isinstance(c, mm.MyClass)
    with pytest.raises(AttributeError):
        len(c.any)
    with pytest.raises(AttributeError):
        len(c.other)
github pyecore / pyecore / examples / wikilibrary / static / library.py View on Github external
name = 'library'
nsPrefix = 'lib'
nsURI = 'http://emf.wikipedia.org/2011/Library'

# Do not remove
eClass = Ecore.EPackage(name=name, nsURI=nsURI, nsPrefix=nsPrefix)

BookCategory = EEnum('BookCategory', literals=['ScienceFiction',
                                               'Biography',
                                               'Mistery'])



class Book(EObject, metaclass=MetaEClass):
    title = EAttribute(eType=EString)
    pages = EAttribute(eType=EInteger)
    category = EAttribute(eType=BookCategory,
                          default_value=BookCategory.ScienceFiction)

    def __init__(self):
        pass


class Writer(EObject, metaclass=MetaEClass):
    name = EAttribute(eType=EString)
    books = EReference(eType=Book, lower=1, upper=-1)

    def __init__(self):
        pass