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_references():
res_set = ResourceSet()
resource = res_set.get_resource(URI(os.path.join(os.path.dirname(__file__), "xmi-data/GeppettoModelTest.xmi")))
model1 = resource.contents[0]
common_library_1 = SharedLibraryManager.get_shared_common_library()
model1.libraries.append(common_library_1)
res_set = ResourceSet()
resource = res_set.get_resource(URI(os.path.join(os.path.dirname(__file__), "xmi-data/GeppettoModelTest.xmi")))
model2 = resource.contents[0]
common_library_2 = SharedLibraryManager.get_shared_common_library()
model2.libraries.append(common_library_2)
factory = GeppettoModelFactory(common_library_1)
variable = factory.create_state_variable('0')
model1.variables.append(variable)
model1.libraries.append(factory.geppetto_common_library)
factory2 = GeppettoModelFactory(common_library_2)
variable = factory2.create_state_variable('0')
model2.variables.append(variable)
serialized1 = json.loads(GeppettoSerializer.serialize(model1, False))
def test_resourceset_defaut_decoders():
assert 'xmi' in ResourceSet.resource_factory
assert 'ecore' in ResourceSet.resource_factory
assert '*' in ResourceSet.resource_factory
def test_resourceset_createresource_xmi():
rset = ResourceSet()
resource = rset.create_resource(URI('simple.xmi'))
rpath = path.abspath('simple.xmi')
assert rpath in rset.resources
assert rset.resources[rpath] is resource
assert rset in resource.decoders
assert isinstance(resource, rset.resource_factory['xmi']('').__class__)
def test_resourceset_createresource_ecore():
rset = ResourceSet()
resource = rset.create_resource(URI('simple.ecore'))
rpath = path.abspath('simple.ecore')
assert rpath in rset.resources
assert rset.resources[rpath] is resource
assert rset in resource.decoders
assert isinstance(resource, rset.resource_factory['ecore']('').__class__)
def test_delete_resolved_proxy_2_models_loaded_simple_relation(lib):
rset = ResourceSet()
xmi_file = path.join('tests', 'xmi', 'xmi-tests', 'a3.xmi')
root = rset.get_resource(xmi_file).contents[0]
xmi_file = path.join('tests', 'xmi', 'xmi-tests', 'b1.xmi')
root2 = rset.get_resource(xmi_file).contents[0]
b = root.a[0].simpleb
b.force_resolve()
b.delete()
assert root.a[0].simpleb is None
assert len(root2.b) == 0
def test_globaluridecoder():
assert Global_URI_decoder.can_resolve('http://simple.ecore'
'#//test') is False
rset = ResourceSet()
resource = rset.create_resource('http://simple.ecore')
global_registry['http://simple.ecore'] = resource
assert Global_URI_decoder.can_resolve('http://simple.ecore#//test') is True
def test_resource_load_proxy_href_inner(simplemm):
rset = ResourceSet()
rset.metamodel_registry[simplemm.nsURI] = simplemm
root = rset.get_resource(path.join('tests', 'xmi',
'xmi-tests', 'a2.xmi')).contents[0]
rset.get_resource(path.join('tests', 'xmi', 'xmi-tests',
'inner', 'b2.xmi'))
assert isinstance(root.a[0].tob[0], EProxy)
B = simplemm.getEClassifier('B')
root.a[0].tob[0].eClass # We force the proxy resolution
assert isinstance(root.a[0].tob[0], B.python_class)
assert EcoreUtils.isinstance(root.a[0].tob[0], B)
def __init__(self, resource_set=None, command_stack_class=CommandStack):
self.resource_set = resource_set or ResourceSet()
self.__stack = command_stack_class()
self.clipboard = []
from pyecore.resources import ResourceSet, URI
import model as pygeppetto
# We create a new resource set (not required, but better)
rset = ResourceSet()
model_url = URI('tests/xmi-data/MediumNet.net.nml.xmi') # > 3100 objects
resource = rset.get_resource(model_url) # We load the model
geppettomodel = resource.contents[0] # We get the root
assert geppettomodel is not None # Is the root not None?
# At this point, we can handle the geppettomodel variable as it is the XMI
# model root
# If geppettomodel name is empty or None we set it
if not geppettomodel.name:
geppettomodel.name = 'pygeppetto_API_demo'
# We save the modified model in a new file
resource.save(output=URI('new-Medium.xmi'))
def load_model(model_path):
rset = ResourceSet()
resource = rset.get_resource(model_path)
return resource