def test_resource_createSaveModifyRead(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 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
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
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') assert a.isAbs is False assert a.abstract is False assert a.eResource is None assert A.eResource is resource
def test_xmiresource_load_ecore_testEMF(): global_registry[Ecore.nsURI] = Ecore resource = XMIResource(URI('tests/xmi/xmi-tests/testEMF.xmi')) 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') assert a.isAbs is False assert a.abstract is False assert a.eResource is None assert A.eResource is resource