def test_id(self): from libcellml import Variable from libcellml.variable import Variable_setEquivalenceMappingId, Variable_setEquivalenceConnectionId, \ Variable_equivalenceMappingId, Variable_equivalenceConnectionId from libcellml.variable import Variable_removeEquivalenceMappingId, Variable_removeEquivalenceConnectionId v1 = Variable("v1") v2 = Variable("v2") Variable.addEquivalence(v1, v2) self.assertEqual("", Variable.equivalenceMappingId(v1, v2)) Variable.setEquivalenceMappingId(v1, v2, "mapping_id") self.assertEqual("mapping_id", Variable.equivalenceMappingId(v1, v2)) Variable.removeEquivalenceMappingId(v1, v2) self.assertEqual("", Variable.equivalenceMappingId(v1, v2)) Variable_setEquivalenceMappingId(v1, v2, "other_mapping_id") self.assertEqual("other_mapping_id", Variable_equivalenceMappingId(v1, v2)) Variable_removeEquivalenceMappingId(v1, v2) self.assertEqual("", Variable_equivalenceMappingId(v1, v2)) self.assertEqual("", Variable.equivalenceConnectionId(v1, v2)) Variable.setEquivalenceConnectionId(v1, v2, "connection_id") self.assertEqual("connection_id", Variable.equivalenceConnectionId(v1, v2)) Variable.removeEquivalenceConnectionId(v1, v2) self.assertEqual("", Variable.equivalenceConnectionId(v1, v2)) Variable_setEquivalenceConnectionId(v1, v2, "other_connection_id") self.assertEqual("other_connection_id", Variable_equivalenceConnectionId(v1, v2)) Variable_removeEquivalenceConnectionId(v1, v2) self.assertEqual("", Variable_equivalenceConnectionId(v1, v2))
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())
def test_auto_id_individual(self): from libcellml import Annotator, CellmlElementType, Parser, Variable from libcellml import Unit, VariablePair annotator = Annotator() parser = Parser() model_string = file_contents("annotator/no_ids.cellml") model = parser.parseModel(model_string) annotator.setModel(model) self.assertEqual( "b4da55", annotator.assignId(model.component(0), CellmlElementType.COMPONENT)) self.assertEqual("b4da55", model.component(0).id()) self.assertEqual( "b4da56", annotator.assignId(model.component("component2"), CellmlElementType.COMPONENT_REF)) self.assertEqual("b4da56", model.component("component2").encapsulationId()) self.assertEqual( "b4da57", annotator.assignId( VariablePair( model.component("component2").variable("variable1"), model.component("component2").variable( "variable1").equivalentVariable(0)), CellmlElementType.CONNECTION)) self.assertEqual( "b4da57", Variable.equivalenceConnectionId( model.component("component2").variable("variable1"), model.component("component2").variable( "variable1").equivalentVariable(0))) self.assertEqual("b4da58", annotator.assignId(model.importSource(0))) self.assertEqual("b4da58", model.importSource(0).id()) self.assertEqual( "b4da59", annotator.assignId( VariablePair( model.component("component2").variable("variable2"), model.component("component2").variable( "variable2").equivalentVariable(0)), CellmlElementType.MAP_VARIABLES)) self.assertEqual( "b4da59", Variable.equivalenceMappingId( model.component("component2").variable("variable2"), model.component("component2").variable( "variable2").equivalentVariable(0))) self.assertEqual("b4da5a", annotator.assignId(model, CellmlElementType.MODEL)) self.assertEqual("b4da5a", model.id()) self.assertEqual( "b4da5b", annotator.assignId( model.component("component2").reset(0), CellmlElementType.RESET)) self.assertEqual("b4da5b", model.component("component2").reset(0).id()) self.assertEqual( "b4da5c", annotator.assignId( model.component("component2").reset(0), CellmlElementType.RESET_VALUE)) self.assertEqual("b4da5c", model.component("component2").reset(0).resetValueId()) self.assertEqual( "b4da5d", annotator.assignId( model.component("component2").reset(0), CellmlElementType.TEST_VALUE)) self.assertEqual("b4da5d", model.component("component2").reset(0).testValueId()) self.assertEqual("b4da5e", annotator.assignId(Unit(model.units(1), 0))) self.assertEqual("b4da5e", model.units(1).unitId(0)) self.assertEqual("b4da5f", annotator.assignId(model.units(1))) self.assertEqual("b4da5f", model.units(1).id()) self.assertEqual("b4da60", annotator.assignId(model.component(1).variable(0))) self.assertEqual("b4da60", model.component(1).variable(0).id()) self.assertEqual( "b4da61", annotator.assignId(model, CellmlElementType.ENCAPSULATION)) self.assertEqual("b4da61", model.encapsulationId())
def test_assign_by_type(self): from libcellml import Annotator, Parser, Variable from libcellml import Unit, VariablePair annotator = Annotator() parser = Parser() model_string = file_contents("annotator/no_ids.cellml") model = parser.parseModel(model_string) annotator.setModel(model) c = model.component(0) self.assertEqual("", model.id()) annotator.assignModelId(model) self.assertEqual("b4da55", model.id()) self.assertEqual("", model.encapsulationId()) annotator.assignEncapsulationId(model) self.assertEqual("b4da56", model.encapsulationId()) self.assertEqual("", c.id()) annotator.assignComponentId(c) self.assertEqual("b4da57", c.id()) self.assertEqual("", c.encapsulationId()) annotator.assignComponentRefId(c) self.assertEqual("b4da58", c.encapsulationId()) c2v1 = model.component("component2").variable("variable1") c3v1 = model.component("component3").variable("variable1") self.assertEqual("", Variable.equivalenceConnectionId(c2v1, c3v1)) annotator.assignConnectionId(VariablePair(c2v1, c3v1)) self.assertEqual("b4da59", Variable.equivalenceConnectionId(c2v1, c3v1)) self.assertEqual("", Variable.equivalenceMappingId(c2v1, c3v1)) annotator.assignMapVariablesId(VariablePair(c2v1, c3v1)) self.assertEqual("b4da5a", Variable.equivalenceMappingId(c2v1, c3v1)) c3v2 = model.component("component3").variable("variable2") self.assertEqual("", c3v2.id()) annotator.assignVariableId(c3v2) self.assertEqual("b4da5b", c3v2.id()) u = model.units(1) self.assertEqual("", u.id()) annotator.assignUnitsId(u) self.assertEqual("b4da5c", u.id()) r = model.component("component2").reset(0) self.assertEqual("", r.id()) annotator.assignResetId(r) self.assertEqual("b4da5d", r.id()) self.assertEqual("", r.testValueId()) annotator.assignTestValueId(r) self.assertEqual("b4da5e", r.testValueId()) self.assertEqual("", r.resetValueId()) annotator.assignResetValueId(r) self.assertEqual("b4da5f", r.resetValueId()) i = model.importSource(0) self.assertEqual("", i.id()) annotator.assignImportSourceId(i) self.assertEqual("b4da60", i.id()) self.assertEqual("", u.unitId(0)) annotator.assignUnitId(Unit(u, 0)) self.assertEqual("b4da61", u.unitId(0))
def test_assign_by_type(self): from libcellml import Annotator, Parser, Variable, CellmlElementType from libcellml import UnitsItem, VariablePair annotator = Annotator() parser = Parser() model_string = file_contents("annotator/no_ids.cellml") model = parser.parseModel(model_string) annotator.setModel(model) c = model.component(0) self.assertEqual("", model.id()) annotator.assignId(model) self.assertEqual("b4da55", model.id()) self.assertEqual("", model.encapsulationId()) annotator.assignId(model, CellmlElementType.ENCAPSULATION) self.assertEqual("b4da56", model.encapsulationId()) self.assertEqual("", c.id()) annotator.assignId(c) self.assertEqual("b4da57", c.id()) self.assertEqual("", c.encapsulationId()) annotator.assignId(c, CellmlElementType.COMPONENT_REF) self.assertEqual("b4da58", c.encapsulationId()) c2v1 = model.component("component2").variable("variable1") c3v1 = model.component("component3").variable("variable1") self.assertEqual("", Variable.equivalenceConnectionId(c2v1, c3v1)) annotator.assignId(VariablePair(c2v1, c3v1), CellmlElementType.CONNECTION) self.assertEqual("b4da59", Variable.equivalenceConnectionId(c2v1, c3v1)) self.assertEqual("", Variable.equivalenceMappingId(c2v1, c3v1)) annotator.assignId(VariablePair(c2v1, c3v1)) self.assertEqual("b4da5a", Variable.equivalenceMappingId(c2v1, c3v1)) c3v2 = model.component("component3").variable("variable2") self.assertEqual("", c3v2.id()) annotator.assignId(c3v2) self.assertEqual("b4da5b", c3v2.id()) u = model.units(1) self.assertEqual("", u.id()) annotator.assignId(u) self.assertEqual("b4da5c", u.id()) r = model.component("component2").reset(0) self.assertEqual("", r.id()) annotator.assignId(r) self.assertEqual("b4da5d", r.id()) self.assertEqual("", r.testValueId()) annotator.assignId(r, CellmlElementType.TEST_VALUE) self.assertEqual("b4da5e", r.testValueId()) self.assertEqual("", r.resetValueId()) annotator.assignId(r, CellmlElementType.RESET_VALUE) self.assertEqual("b4da5f", r.resetValueId()) i = model.component("component1").importSource() self.assertEqual("", i.id()) annotator.assignId(i) self.assertEqual("b4da60", i.id()) self.assertEqual("", u.unitId(0)) annotator.assignId(UnitsItem(u, 0)) self.assertEqual("b4da61", u.unitId(0))