How to use the pyecore.resources.xmi.XMIResource 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 / pyecore / tests / test_resources.py View on Github external
def test_resource_swap(simplemm):
    root = simplemm.Root()
    a = simplemm.A()
    b = simplemm.B()
    root.a.append(a)
    root.b.append(b)

    r1 = XMIResource(URI('resource1.xmi'))
    r2 = XMIResource(URI('resource2.xmi'))
    r1.append(root)

    assert root.eResource is r1
    assert a.eResource is root.eResource
    assert b.eResource is root.eResource

    r2.append(root)
    assert root.eResource is r2
    assert a.eResource is root.eResource
    assert b.eResource is root.eResource
github pyecore / pyecore / tests / test_resources.py View on Github external
def test_resource_multiroot_container_changement():
    resource = XMIResource('testResource')
    A = EClass('A')
    A.eStructuralFeatures.append(EReference('toa', A, containment=True))

    a1 = A()
    a2 = A()

    resource = XMIResource('test')
    resource.append(a1)
    resource.append(a2)

    assert resource.contents == [a1, a2]

    a1.toa = a2
    assert resource.contents == [a1]
github pyecore / pyecore / tests / xmi / test_xmi_serialization.py View on Github external
def test_resource_crossref_uuid(tmpdir, lib):
    f1 = tmpdir.mkdir('pyecore-tmp2').join('main_uuid1.xmi')
    f2 = tmpdir.join('pyecore-tmp2', 'href_uuid2.xmi')
    r1 = XMIResource(URI(str(f1)))
    r2 = XMIResource(URI(str(f2)))
    r2.use_uuid = True

    # we create some instances
    root = lib.MyRoot()
    a1 = lib.A()
    a2 = lib.SubA()
    a1.toa = a2
    root.a_container.append(a1)

    # we add the elements to the first resource
    r1.append(root)

    # we create and add element to the second resource
    root2 = lib.MyRoot()
    root2.a_container.append(a2)
    r2.append(root2)
github pyecore / pyecore / tests / xmi / test_xmi_serialization.py View on Github external
def test_xmi_ecore_save_option_xmitype(tmpdir):
    f = tmpdir.mkdir('pyecore-tmp').join('xmitype.xmi')
    resource = XMIResource(URI(str(f)))

    resource.append(eClass)
    resource.save(options={XMIOptions.OPTION_USE_XMI_TYPE: True})

    has_xmi_type = False
    with open(str(f)) as output:
        for line in output:
            if 'xmi:type="' in line:
                has_xmi_type = True
                break
    assert has_xmi_type

    resource.save()
    has_xmi_type = False
    with open(str(f)) as output:
        for line in output:
github pyecore / pyecore / tests / xmi / test_xmi_serialization.py View on Github external
suba1 = lib.SubA()
    root.a_container.extend([a1, suba1])

    # we add the elements to the resource
    resource.append(root)
    resource.save()

    # we add more instances
    a2 = lib.A()
    root.a_container.append(a2)

    # we save again
    resource.save()

    # we read the model
    resource = XMIResource(URI(str(f)))
    resource.load()
    assert resource.contents != []
    assert len(resource.contents[0].eContents) == 3
github pyecore / pyecore / tests / xmi / test_xmi_deserialization.py View on Github external
def test_xmiresource_load_ecore_testEMF():
    xmi_file = path.join('tests', 'xmi', 'xmi-tests', 'testEMF.xmi')
    resource = XMIResource(URI(xmi_file))
    resource.load()
    assert resource.contents != []
    root = resource.contents[0]
    A = root.getEClassifier('A')
    assert A
    B = root.getEClassifier('B')
    assert B
    TInterface = root.getEClassifier('TInterface')
    assert TInterface
    TClass = root.getEClassifier('TClass')
    assert TClass
    a = A()
    assert Ecore.EcoreUtils.isinstance(a, TClass)
    assert Ecore.EcoreUtils.isinstance(a, TInterface)
    assert A.findEStructuralFeature('abstract')
    assert A.findEStructuralFeature('isAbs')
github pyecore / pyecore / tests / xmi / test_xmi_serialization.py View on Github external
def test_resource_crossref_uuid(tmpdir, lib):
    f1 = tmpdir.mkdir('pyecore-tmp2').join('main_uuid1.xmi')
    f2 = tmpdir.join('pyecore-tmp2', 'href_uuid2.xmi')
    r1 = XMIResource(URI(str(f1)))
    r2 = XMIResource(URI(str(f2)))
    r2.use_uuid = True

    # we create some instances
    root = lib.MyRoot()
    a1 = lib.A()
    a2 = lib.SubA()
    a1.toa = a2
    root.a_container.append(a1)

    # we add the elements to the first resource
    r1.append(root)

    # we create and add element to the second resource
    root2 = lib.MyRoot()
    root2.a_container.append(a2)
github pyecore / pyecore / tests / xmi / test_xmi_serialization.py View on Github external
def test_resource_createset(tmpdir, lib):
    f = tmpdir.mkdir('pyecore-tmp').join('test.xmi')
    resource = XMIResource(URI(str(f)))

    # we create some instances
    root = lib.MyRoot()
    a1 = lib.A()
    suba1 = lib.SubA()
    root.a_container.extend([a1, suba1])

    # we add the elements to the resource
    resource.append(root)
    resource.save()

    # we read the model
    resource = XMIResource(URI(str(f)))
    resource.load()
    assert resource.contents != []
    assert len(resource.contents[0].eContents) == 2
github pyecore / pyecore / pyecore / resources / __init__.py View on Github external
ResourceSet.resource_factory = {'xmi': lambda uri: xmi.XMIResource(uri),
                                'ecore': lambda uri: xmi.XMIResource(uri),