def test_auto_ids(self): from libcellml import Annotator, Parser, Variable annotator = Annotator() parser = Parser() model_string = file_contents("annotator/unique_ids.cellml") model = parser.parseModel(model_string) annotator.setModel(model) annotator.clearAllIds() annotator.assignAllIds() self.assertEqual("b4da55", model.id()) self.assertEqual("b4da56", model.importSource(0).id()) self.assertEqual("b4da57", model.importSource(1).id()) self.assertEqual("b4da58", model.units(0).id()) self.assertEqual("b4da59", model.units(1).id()) self.assertEqual("b4da5a", model.units(2).id()) self.assertEqual("b4da5b", model.units(3).id()) self.assertEqual("b4da5c", model.units(1).unitId(0)) self.assertEqual("b4da5d", model.component(0).id()) self.assertEqual("b4da5e", model.component(1).id()) self.assertEqual("b4da5f", model.component(1).component(0).id()) self.assertEqual("b4da60", model.component(1).variable(0).id()) self.assertEqual("b4da61", model.component(1).variable(1).id()) self.assertEqual("b4da62", model.component(1).component(0).variable(0).id()) self.assertEqual("b4da63", model.component(1).component(0).variable(1).id()) self.assertEqual("b4da64", model.component(1).reset(0).id()) self.assertEqual("b4da65", model.component(1).reset(0).resetValueId()) self.assertEqual("b4da66", model.component(1).reset(0).testValueId()) c2v1 = model.component("component2").variable("variable1") c2v2 = model.component("component2").variable("variable2") c3v1 = model.component("component3").variable("variable1") c3v2 = model.component("component3").variable("variable2") self.assertEqual("b4da67", Variable.equivalenceConnectionId(c2v1, c3v1)) self.assertEqual("b4da67", Variable.equivalenceConnectionId(c2v2, c3v2)) self.assertEqual("b4da68", Variable.equivalenceMappingId(c2v1, c3v1)) self.assertEqual("b4da69", Variable.equivalenceMappingId(c2v2, c3v2)) self.assertEqual("b4da6a", model.component("component2").encapsulationId()) self.assertEqual("b4da6b", model.component("component3").encapsulationId()) self.assertEqual("b4da6c", model.encapsulationId())
# and go home. # Use the clearAllIds function to completely remove all id strings from the model. # Check that they have gone by repeating step 4.a to print any ids to the terminal. annotator.clearAllIds() ids = annotator.ids() print('There are {} ids in the model.'.format(len(ids))) # 6.c # Go looking for Marco, but he's gone home already. # Try and retrieve an item with id 'marco' and check that a null pointer is returned. # Retrieve and print any issues to the terminal. marco_item = annotator.item('marco') print('The type of item with ID "marco" is {}'.format( cellmlElementTypeAsString(marco_item.type()))) print_issues(annotator) # 6.d # Regret nuking our friends and make plans to return tomorrow and # annotate everything. Use the assignAllIds function to give an automatic # id to everything in the model. annotator.assignAllIds() # 6.e # Try to retrieve duplicated ids from the annotator as in step 4.b, and # check that it returns an empty list. duplicated_ids = annotator.duplicateIds() print('There are {} duplicated ids in the model.'.format( len(duplicated_ids))) # end 6