def test_auto_ids_group(self): from libcellml import Annotator, Component, Model from libcellml.enums import CellmlElementType_COMPONENT annotator = Annotator() model = Model() component1 = Component("c1") component2 = Component("c2") component3 = Component("c3") model.addComponent(component1) model.addComponent(component2) component2.addComponent(component3) annotator.setModel(model) self.assertEqual("", model.id()) self.assertEqual("", component1.id()) self.assertEqual("", component2.id()) self.assertEqual("", component3.id()) annotator.assignIds(CellmlElementType_COMPONENT) self.assertEqual("", model.id()) self.assertEqual("b4da55", component1.id()) self.assertEqual("b4da56", component2.id()) self.assertEqual("b4da57", component3.id())
print('----------------------------------------------------------') print(' STEP 6: Give up and go home ') print('----------------------------------------------------------') # 6.a # Loop through all of the model's components and print their id to the terminal. # Use the assignIds string with an item type (CellmlElementType.COMPONENT) # to give all of the items of that type a new unique id. Print the ids again and # notice that the blanks have been filled with automatically generated strings, # but existing ids are unchanged. print('Before automatic assignment the components have ids:') for index in range(0, model.componentCount()): print(' - "{}"'.format(model.component(index).id())) annotator.assignIds(CellmlElementType.COMPONENT) print('After automatic assignment the components have ids:') for index in range(0, model.componentCount()): print(' - "{}"'.format(model.component(index).id())) # 6.b # Finally, we decide that it's too cold for swimming, and want to nuke all the ids # 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