Exemplo n.º 1
0
    def test_variable_pair_coverage(self):
        from libcellml import Variable, VariablePair

        v1 = Variable("ray")
        v2 = Variable("charles")
        vp = VariablePair(v1, v2)

        self.assertTrue(vp.isValid())
Exemplo n.º 2
0
    def test_connection(self):
        from libcellml import Issue, Variable, VariablePair

        e = Issue()
        self.assertIsNone(e.connection())
        v1 = Variable("v1")
        v2 = Variable("v2")
        e.setConnection(VariablePair(v1, v2))
        p = e.connection()
        self.assertIsInstance(p.variable1(), Variable)
        self.assertEqual(p.variable1().name(), "v1")
        self.assertEqual(p.variable2().name(), "v2")
Exemplo n.º 3
0
    def test_map_variables(self):
        from libcellml import Issue, Variable, VariablePair

        e = Issue()
        self.assertIsNone(e.mapVariables())
        v1 = Variable("v1")
        v2 = Variable("v2")

        e.setMapVariables(VariablePair(v1, v2))
        p = e.mapVariables()
        self.assertIsInstance(p.variable1(), Variable)
        self.assertEqual(p.variable1().name(), "v1")
        self.assertEqual(p.variable2().name(), "v2")
Exemplo n.º 4
0
    def test_create_destroy(self):
        from libcellml import Component
        from libcellml import Issue
        from libcellml import ImportSource
        from libcellml import Model
        from libcellml import Reset
        from libcellml import Unit
        from libcellml import Units
        from libcellml import Variable
        from libcellml import VariablePair

        e1 = Issue()
        del e1

        c = Component()
        e2 = Issue(c)
        del e2

        i = ImportSource()
        e3 = Issue(i)
        del e3

        m = Model()
        e4 = Issue(m)
        del e4

        r = Reset()
        e5 = Issue(r)
        del e5

        u = Units()
        e6 = Issue(u)
        del e6

        v = Variable()
        e7 = Issue(v)
        del e7

        v1 = Variable("v1")
        v2 = Variable("v2")
        vp = VariablePair(v1, v2)
        e8 = Issue(vp)
        del e8

        ui = Unit(u, 0)
        e9 = Issue(ui)
        del e9
Exemplo n.º 5
0
    def test_item(self):
        from libcellml import Component, Issue, ImportSource, Model, Unit
        from libcellml import Reset, Units, Variable, CellmlElementType, VariablePair

        i = Issue()

        item = i.item()
        self.assertEqual(CellmlElementType.UNDEFINED, item[0])
        self.assertIsNone(item[1])

        i.setItem(CellmlElementType.VARIABLE, Variable("v"))
        vItem = i.item()
        self.assertEqual(CellmlElementType.VARIABLE, vItem[0])
        self.assertEqual("v", vItem[1].name())

        i.setItem(CellmlElementType.UNITS, Units("u"))
        uItem = i.item()
        self.assertEqual(CellmlElementType.UNITS, uItem[0])
        self.assertEqual("u", uItem[1].name())

        u = Units("ui")
        u.addUnit("volt")
        u.addUnit("second")
        u.addUnit("metre")
        i.setItem(CellmlElementType.UNIT, Unit(u, 2))
        uiItem = i.item()
        self.assertEqual(CellmlElementType.UNIT, uiItem[0])
        self.assertEqual("ui", uiItem[1].units().name())
        self.assertEqual(2, uiItem[1].index())

        v1 = Variable("v1")
        v2 = Variable("v2")
        i.setItem(CellmlElementType.CONNECTION, VariablePair(v1, v2))
        vpItem = i.item()
        self.assertEqual(CellmlElementType.CONNECTION, vpItem[0])
        self.assertEqual("v1", vpItem[1].variable1().name())
        self.assertEqual("v2", vpItem[1].variable2().name())

        v3 = Variable("v3")
        v4 = Variable("v4")
        i.setItem(CellmlElementType.MAP_VARIABLES, VariablePair(v3, v4))
        vpItem = i.item()
        self.assertEqual(CellmlElementType.MAP_VARIABLES, vpItem[0])
        self.assertEqual("v3", vpItem[1].variable1().name())
        self.assertEqual("v4", vpItem[1].variable2().name())

        r = Reset()
        r.setId("r")
        i.setItem(CellmlElementType.RESET, r)
        rItem = i.item()
        self.assertEqual(CellmlElementType.RESET, rItem[0])
        self.assertEqual("r", rItem[1].id())

        r.setId("r1")
        i.setItem(CellmlElementType.RESET_VALUE, r)
        rItem = i.item()
        self.assertEqual(CellmlElementType.RESET_VALUE, rItem[0])
        self.assertEqual("r1", rItem[1].id())

        r.setId("r2")
        i.setItem(CellmlElementType.TEST_VALUE, r)
        rItem = i.item()
        self.assertEqual(CellmlElementType.TEST_VALUE, rItem[0])
        self.assertEqual("r2", rItem[1].id())

        i.setItem(CellmlElementType.MODEL, Model("m"))
        mItem = i.item()
        self.assertEqual(CellmlElementType.MODEL, mItem[0])
        self.assertEqual("m", mItem[1].name())

        i.setItem(CellmlElementType.ENCAPSULATION, Model("e"))
        mItem = i.item()
        self.assertEqual(CellmlElementType.ENCAPSULATION, mItem[0])
        self.assertEqual("e", mItem[1].name())

        iS  = ImportSource()
        iS.setId("is")
        i.setItem(CellmlElementType.IMPORT, iS)
        isItem = i.item()
        self.assertEqual(CellmlElementType.IMPORT, isItem[0])
        self.assertEqual("is", isItem[1].id())

        i.setItem(CellmlElementType.COMPONENT, Component("c"))
        cItem = i.item()
        self.assertEqual(CellmlElementType.COMPONENT, cItem[0])
        self.assertEqual("c", cItem[1].name())

        i.setItem(CellmlElementType.COMPONENT_REF, Component("c1"))
        cItem = i.item()
        self.assertEqual(CellmlElementType.COMPONENT_REF, cItem[0])
        self.assertEqual("c1", cItem[1].name())
Exemplo n.º 6
0
    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())
Exemplo n.º 7
0
    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))
Exemplo n.º 8
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))