def exec(model): # Create the manager dm = DiscoverMetamodels() # Read the model fm = dm.use_transformation_t2m(src=model, dst='fm') # Print the model #print(fm) # Transform to Python-sat metamodel pysatm = dm.use_transformation_m2m(src=fm, dst='pysat') # Operation execute return the object instance operation = dm.use_operation(src=pysatm, operation='DeadFeatures') # Print the result print("Result:", str(operation.get_result()))
def test_discover_complex_plugin(self, mocker): mocker.return_value = [complex_plugin] search = DiscoverMetamodels() stats = search.plugins.get_stats() assert stats.get('amount_plugins') == 1 assert stats.get('plugin1').get('amount_operations') == 1 assert stats.get('plugin1').get('amount_transformations') == 3
def test_discover_apply_functions(self, mocker): mocker.return_value = [one_plugin] search = DiscoverMetamodels() with raises(PluginNotFound) as error: search.use_transformation_t2m(src='file.ext', dst='foo') assert error.typename == 'PluginNotFound' variability_model = search.use_transformation_t2m(src='file.ext', dst='ext') text = search.use_transformation_m2t(src=variability_model, dst='file.ext') search.use_transformation_m2m(src=variability_model, dst='ext') operation = search.use_operation(src=variability_model, operation='Operation1') assert isinstance(variability_model, VariabilityModel) assert text == 'example' assert operation.get_result() == '123456'
def setUp(self, mocker): self.filename = tempfile.NamedTemporaryFile(suffix='.xml').name mocker.return_value = [three_plugins] self.discover = DiscoverMetamodels()
class TestDiscoverUseOperationFromFile(TestCase): @mock.patch.object(discover, 'filter_modules_from_plugin_paths') def setUp(self, mocker): self.filename = tempfile.NamedTemporaryFile(suffix='.xml').name mocker.return_value = [three_plugins] self.discover = DiscoverMetamodels() def test_discover_use_operation_from_file_with_plugins(self): self.discover.use_operation_from_file('Valid', self.filename, 'plugin1') self.discover.use_operation_from_file('Operation1', self.filename, 'plugin1') def test_discover_use_operation_from_file_unexist(self): with raises(OperationNotFound): self.discover.use_operation_from_file('Unexist', self.filename) def test_discover_use_operation_from_file_no_step(self): self.discover.use_operation_from_file('Valid', self.filename) self.discover.use_operation_from_file('Operation1', self.filename) def test_discover_use_operation_from_file_one_step(self): self.discover.use_operation_from_file('Valid', self.filename) self.discover.use_operation_from_file('Operation2', self.filename) def test_discover_use_operation_from_file_two_step(self): self.discover.use_operation_from_file('Valid', self.filename) self.discover.use_operation_from_file('Operation3', self.filename) def test_discover_use_operation_from_file_unreachable_way(self): filename = tempfile.NamedTemporaryFile(suffix='.xml2').name with raises(NotImplementedError): self.discover.use_operation_from_file('Operation1', filename)
def test_discover(self): search = DiscoverMetamodels() assert len(search.plugins) == 1
import hug from famapy.core.discover import DiscoverMetamodels dm = DiscoverMetamodels() @hug.cli() @hug.get('/get-plugins/', versions=1) def get_plugins(): """ Get availables plugins """ plugins = dm.get_plugins() return {'plugins': plugins} @hug.cli() @hug.get('/get-operations/{plugin}/') def get_operations_by_plugin(plugin: str, versions=1): """ Get availables operations gave a plugin name """ operations = dm.get_operations_by_plugin(plugin) return {'operations': operations} @hug.cli() def use_operation(plugin: str, operation: str, filename: str, versions=1): """ Execute an operation gave a plugin, an operation and one input file. - Read input model, transform and call operation """ result = dm.use_operation_from_file(plugin, operation, filename)
from famapy.core.discover import DiscoverMetamodels # create the manager dm = DiscoverMetamodels() # Example t2m fm = dm.use_transformation_t2m(src='example.xml', dst='fm') print(fm) # Example m2t dm.use_transformation_m2t(src=fm, dst='output.json') # Example m2m # TODO: create VariabilityModel and get src extension # todo debe haber alguna forma de pasarle el modelo cargado a la transformacion # y que te lo devuelva en pysast # dm.use_transformation_m2m(src=VariabilityModel, dst='pysat') pysatm = dm.use_transformation_m2m(src=fm, dst='pysat') print(pysatm) # operation execute return the object instance operation = dm.use_operation(src=pysatm, operation='Valid') print("Result operation valid:", operation.is_valid())