def test_replace_model(self): from libcellml import Component, Importer, Model, Parser parser = Parser() model = parser.parseModel( file_contents('importer/generic_no_source.cellml')) importer = Importer() wrongSourceModel = Model('wrong') rightSourceModel = Model('right') rightSourceModel.addComponent(Component('a')) rightSourceModel.addComponent(Component('b')) rightSourceModel.addComponent(Component('c')) rightSourceModel.addComponent(Component('d')) self.assertTrue( importer.addModel(wrongSourceModel, 'i_dont_exist.cellml')) self.assertFalse( importer.replaceModel(rightSourceModel, 'not_in_library')) self.assertTrue( importer.replaceModel(rightSourceModel, 'i_dont_exist.cellml')) importer.resolveImports(model, '') self.assertEqual(0, importer.issueCount()) self.assertFalse(model.hasUnresolvedImports())
def test_replace_model(self): from libcellml import Component, Importer, Model, Parser parser = Parser() model = parser.parseModel( file_contents("importer/generic_no_source.cellml")) importer = Importer() wrongSourceModel = Model("wrong") rightSourceModel = Model("right") rightSourceModel.addComponent(Component("a")) rightSourceModel.addComponent(Component("b")) rightSourceModel.addComponent(Component("c")) rightSourceModel.addComponent(Component("d")) self.assertTrue( importer.addModel(wrongSourceModel, "i_dont_exist.cellml")) self.assertFalse( importer.replaceModel(rightSourceModel, "not_in_library")) self.assertTrue( importer.replaceModel(rightSourceModel, "i_dont_exist.cellml")) importer.resolveImports(model, "") self.assertEqual(0, importer.issueCount()) self.assertFalse(model.hasUnresolvedImports())
def test_add_model(self): from libcellml import Component, Importer, Model, Parser parser = Parser() importer = Importer() model = parser.parseModel( file_contents('importer/generic_no_source.cellml')) sourceModel = Model('source') sourceModel.addComponent(Component('a')) sourceModel.addComponent(Component('b')) sourceModel.addComponent(Component('c')) sourceModel.addComponent(Component('d')) # Add a model manually to the library, including the URL that it will replace in future imports. self.assertTrue(importer.addModel(sourceModel, 'i_dont_exist.cellml')) self.assertFalse(importer.addModel(sourceModel, 'i_dont_exist.cellml')) importer.resolveImports(model, '') self.assertEqual(0, importer.issueCount()) self.assertFalse(model.hasUnresolvedImports())