def test_json_resource_createSaveModifyRead(tmpdir, lib): f = tmpdir.mkdir('pyecore-tmp').join('test.json') resource = JsonResource(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 = JsonResource(URI(str(f))) resource.load() assert resource.contents != [] assert len(resource.contents[0].eContents) == 3
def test_json_resource_save_metamodel_uri(tmpdir, lib): f = tmpdir.mkdir('pyecore-tmp').join('test.json') resource = JsonResource(URI(str(f)), use_uuid=True) resource.append(lib) resource.save() # we read the model resource = JsonResource(URI(str(f))) resource.load() root = resource.contents[0] assert len(root.eContents) == len(lib.eContents) assert isinstance(root, lib.eClass.python_class)
def test_json_resource_save_static_metamodel(tmpdir): f = tmpdir.mkdir('pyecore-tmp').join('test.json') resource = JsonResource(URI(str(f))) # we add the elements to the resource resource.append(eClass) resource.save() # we read the model resource = JsonResource(URI(str(f))) resource.load() assert resource.contents != [] assert len(resource.contents[0].eContents) == 2 root = resource.contents[0] assert root.eContents[0].name == 'A'
def test_json_save_multiple_roots_roundtrip(tmpdir): A = Ecore.EClass('A') A.eStructuralFeatures.append(Ecore.EAttribute('name', Ecore.EString)) pack = Ecore.EPackage('pack', 'packuri', 'pack') pack.eClassifiers.append(A) f = tmpdir.mkdir('pyecore-tmp').join('multiple.json') resource = JsonResource(URI(str(f))) resource.append(A(name='root1')) resource.append(A(name='root2')) resource.save() global_registry[pack.nsURI] = pack resource = JsonResource(URI(str(f))) resource.load() assert len(resource.contents) == 2 assert resource.contents[0].name == 'root1' assert resource.contents[1].name == 'root2' del global_registry[pack.nsURI]