def test_type_based_retrieval(self): from libcellml import Annotator, Model, Parser annotator = Annotator() model = Model() parser = Parser() model_string = file_contents("annotator/unique_ids.cellml") model = parser.parseModel(model_string) annotator.setModel(model) v1v1 = (model.component("component2").variable("variable1"), model.component("component2").component("component3").variable( "variable1")) v2v2 = (model.component("component2").variable("variable2"), model.component("component2").component("component3").variable( "variable2")) self.assertEqual(model.name(), annotator.model("model_1").name()) self.assertEqual(model.name(), annotator.encapsulation("encapsulation_1").name()) self.assertEqual( model.component("component1").name(), annotator.component("component_1").name()) self.assertEqual( model.component("component2").name(), annotator.component("component_2").name()) self.assertEqual( model.component("component2").name(), annotator.component("component_ref_1").name()) self.assertEqual( model.component("component2").component("component3").name(), annotator.component("component_3").name()) self.assertEqual( model.component("component2").component("component3").name(), annotator.componentRef("component_ref_2").name()) self.assertEqual( model.component("component1").importSource().url(), annotator.importSource("import_1").url()) self.assertEqual( model.units("units1").name(), annotator.units("units_1").name()) self.assertEqual( model.units("units1").importSource().url(), annotator.importSource("import_2").url()) self.assertEqual( model.units("units2").name(), annotator.units("units_2").name()) self.assertEqual( model.units("units2").name(), annotator.unit("unit_1").units().name()) self.assertEqual(0, annotator.unit("unit_1").index()) self.assertEqual( model.component("component2").variable("variable1").name(), annotator.variable("variable_1").name()) self.assertEqual( model.component("component2").variable("variable2").name(), annotator.variable("variable_2").name()) self.assertEqual( model.component("component2").reset(0).variable().name(), annotator.reset("reset_1").variable().name()) self.assertEqual( model.component("component2").reset(0).testVariable().name(), annotator.reset("reset_1").testVariable().name()) self.assertEqual( model.component("component2").reset(0).testValue(), annotator.testValue("test_value_1").testValue()) self.assertEqual( model.component("component2").reset(0).resetValue(), annotator.resetValue("reset_value_1").resetValue()) self.assertEqual( model.component("component2").component("component3").variable( "variable1").name(), annotator.variable("variable_3").name()) self.assertEqual( model.component("component2").component("component3").variable( "variable2").name(), annotator.variable("variable_4").name()) self.assertEqual( v1v1[0].name(), annotator.connection("connection_1").variable1().name()) self.assertEqual( v1v1[1].name(), annotator.connection("connection_1").variable2().name()) self.assertEqual( v1v1[0].name(), annotator.mapVariables("map_variables_1").variable1().name()) self.assertEqual( v1v1[1].name(), annotator.mapVariables("map_variables_1").variable2().name()) self.assertEqual( v2v2[0].name(), annotator.mapVariables("map_variables_2").variable1().name()) self.assertEqual( v2v2[1].name(), annotator.mapVariables("map_variables_2").variable2().name()) self.assertIsNone(annotator.model("i_dont_exist")) self.assertIsNone(annotator.component("i_dont_exist")) self.assertIsNone(annotator.variable("i_dont_exist")) self.assertIsNone(annotator.units("i_dont_exist")) self.assertIsNone(annotator.unit("i_dont_exist")) self.assertIsNone(annotator.reset("i_dont_exist")) self.assertIsNone(annotator.resetValue("i_dont_exist")) self.assertIsNone(annotator.testValue("i_dont_exist")) self.assertIsNone(annotator.componentRef("i_dont_exist")) self.assertIsNone(annotator.connection("i_dont_exist")) self.assertIsNone(annotator.importSource("i_dont_exist"))
# STEP 3 # Retrieve items by their id where the item type is known. # Retrieve a component with the id of 'yellow'. We can only do this because # we have prior knowledge that the item with id of 'yellow' is actually # a Component. component = annotator.component('yellow') # The same applies to the other item types below. variable = annotator.variable('indigo') reset = annotator.reset('violet') importSource = annotator.importSource('orange') units = annotator.units('green') unit = annotator.unit('blue') connection = annotator.connection('beige') mapVariables = annotator.mapVariables('puce') # Some kinds of items are returned by their parent item. These are: # - componentRef: returns the Component with this id on its encapsulation item. componentRef = annotator.componentRef('black') # - encapsulation: returns the Model with this id on its encapsulation item. encapsulation = annotator.encapsulation('brown') # - resetValue: returns the Reset with this id on its reset value. resetValue = annotator.resetValue('taupe') # - testValue: returns the Reset with this id on its test value. testValue = annotator.testValue('mauve')