Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def generated_metamodel(pygen_output_dir):
rset = ResourceSet()
resource = rset.get_resource(URI('input/A.ecore'))
library_model = resource.contents[0]
generator = EcoreGenerator(with_dependencies=True)
generator.generate(library_model, pygen_output_dir)
return importlib.import_module('a')
def test_resource_normalize_unknown_protocol():
u = URI('pathmap://test')
assert u.normalize() == u.plain
u = URI('platform:/test')
assert u.normalize() == u.plain
def test_readwrite_mediumXMI(tmpdir, rset):
resource = rset.get_resource(URI(filepath('MediumNet.net.nml.xmi')))
root = resource.contents[0]
f = tmpdir.mkdir('pyecore-tmp').join('medium.xmi')
resource.save(output=URI(str(f)))
def test__resource_uriconverter_simple():
class MyURI(URI):
pass
class MyURIConverter(AbstractURIConverter):
@staticmethod
def can_handle(uri):
return uri.protocol == 'myuri'
@staticmethod
def convert(uri):
new_path = uri.plain.replace('myuri://', '')
return MyURI(new_path)
rset = ResourceSet()
rset.uri_converter.append(MyURIConverter)
xmi_file = path.join('tests', 'xmi', 'xmi-tests', 'C.ecore')
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))
serialized2 = json.loads(GeppettoSerializer.serialize(model2, False))
def test_roundtrip_mediumXMI(tmpdir, rset):
resource = rset.get_resource(URI(filepath('MediumNet.net.nml.xmi')))
root = resource.contents[0]
# We change the root name
root.name = 'mediumTestModel'
# We serialize the modifications
f = tmpdir.mkdir('pyecore-tmp').join('medium.xmi')
resource.save(output=URI(str(f)))
# We read again the file
resource = rset.get_resource(URI(str(f)))
root = resource.contents[0]
assert root
assert root.name == 'mediumTestModel'
def test_uri_noprotocol():
uri = URI('test.ecore')
assert uri.protocol is None
assert uri.extension == 'ecore'
assert uri.plain == 'test.ecore'
def test_roundtrip_LargeXMI(tmpdir, rset):
resource = rset.get_resource(URI(filepath('LargeConns.net.nml.xmi')))
root = resource.contents[0]
# We change the root name
root.name = 'largeTestModel'
# We serialize the modifications
f = tmpdir.mkdir('pyecore-tmp').join('large.xmi')
resource.save(output=URI(str(f)))
# We read again the file
resource = rset.get_resource(URI(str(f)))
root = resource.contents[0]
assert root
assert root.name == 'largeTestModel'
def test_command_resource(mm):
rset = ResourceSet()
resource = rset.create_resource(URI('http://logical'))
a = mm.A()
resource.append(a)
cmd = Set(a, 'name', 'test_value')
assert cmd.resource is resource
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'))