Exemple #1
0
    def test_imports(self):
        from libcellml import Model, ImportSource, Units

        m = Model()
        u = Units()

        u.setImportSource(ImportSource())

        m.addUnits(u)
        self.assertTrue(m.hasImports())

        self.assertEqual(1, m.importSourceCount())

        i = ImportSource()
        i.setUrl('actual_url')

        m.addImportSource(i)

        self.assertEqual(2, m.importSourceCount())

        i1 = m.importSource(0)

        self.assertTrue(m.hasImportSource(i))

        m.removeImportSource(0)

        self.assertEqual(1, m.importSourceCount())

        m.removeAllImportSources()

        self.assertEqual(0, m.importSourceCount())
Exemple #2
0
    def test_import_source(self):
        from libcellml import ImportSource

        # Test create/copy/destroy
        x = ImportSource()
        y = ImportSource()
        z = ImportSource(y)
        del (x, y, z)
Exemple #3
0
    def test_set_source(self):
        from libcellml import Component, ImportSource

        x = Component()
        i = ImportSource()
        i.setUrl('bonjour')
        x.setSourceComponent(i, 'camembert')
        self.assertEqual(x.importSource().url(), 'bonjour')
        self.assertEqual(x.importReference(), 'camembert')
Exemple #4
0
    def test_get_import_source(self):
        from libcellml import Error, ImportSource

        # ImportSourcePtr getImportSource()
        e = Error()
        self.assertIsNone(e.getComponent())
        name = 'uri'
        i = ImportSource()
        i.setId(name)
        e.setImportSource(i)
        self.assertIsInstance(e.getImportSource(), ImportSource)
        self.assertEqual(e.getImportSource().getId(), name)
Exemple #5
0
    def test_get_import_source(self):
        from libcellml import ImportedEntity, ImportSource

        # ImportSourcePtr getImportSource()
        i = ImportSource()
        source = 'hello'
        i.setUrl(source)
        x = ImportedEntity()
        self.assertIsNone(x.getImportSource())
        x.setImportSource(i)
        self.assertIsNotNone(x.getImportSource())
        self.assertEqual(x.getImportSource().getUrl(), source)
Exemple #6
0
    def test_import_source(self):
        from libcellml import Issue, ImportSource

        # ImportSourcePtr importSource()
        e = Issue()
        self.assertIsNone(e.component())
        name = 'uri'
        i = ImportSource()
        i.setId(name)
        e.setImportSource(i)
        self.assertIsInstance(e.importSource(), ImportSource)
        self.assertEqual(e.importSource().id(), name)
    def test_has_model(self):
        from libcellml import ImportSource, Model

        x = ImportSource()
        model = Model()
        self.assertFalse(x.hasModel())
        x.setModel(model)
        self.assertTrue(x.hasModel())
        x.removeModel()
        self.assertFalse(x.hasModel())
    def test_url(self):
        from libcellml import ImportSource

        source = 'cheers'
        x = ImportSource()
        self.assertEqual(x.url(), '')
        x.setUrl(source)
        self.assertEqual(x.url(), source)
        x.setUrl('')
        self.assertEqual(x.url(), '')
    def test_has_model(self):
        from libcellml import ImportSource, Model

        # bool hasModel() const;
        x = ImportSource()
        self.assertFalse(x.hasModel())
        x.setModel(Model())
        self.assertTrue(x.hasModel())
        x.setModel(None)
        self.assertFalse(x.hasModel())
Exemple #10
0
    def test_get_url(self):
        from libcellml import ImportSource

        # std::string getUrl()
        source = 'cheers'
        x = ImportSource()
        self.assertEqual(x.getUrl(), '')
        x.setUrl(source)
        self.assertEqual(x.getUrl(), source)
        x.setUrl('')
        self.assertEqual(x.getUrl(), '')
    def test_model(self):
        from libcellml import ImportSource, Model

        model = Model()
        model.setName('bert')
        x = ImportSource()
        self.assertIsNone(x.model())
        x.setModel(model)
        self.assertEqual(x.model().name(), model.name())
        x.setModel(None)
        self.assertIsNone(x.model())
    def test_set_model(self):
        from libcellml import ImportSource, Model

        # void setModel(const ModelPtr &model);
        x = ImportSource()
        x.setModel(None)
        x.setModel(Model())
        x.setModel(None)
    def test_set_url(self):
        from libcellml import ImportSource

        # void setUrl(const std::string &reference)
        x = ImportSource()
        x.setUrl('')
        x.setUrl('hello')
        x.setUrl('')
Exemple #14
0
    def test_get_model(self):
        from libcellml import ImportSource, Model

        # libcellml::ModelPtr getModel() const;
        model = Model()
        model.setName('bert')
        x = ImportSource()
        self.assertIsNone(x.getModel())
        x.setModel(model)
        self.assertEqual(x.getModel().getName(), model.getName())
        x.setModel(None)
        self.assertIsNone(x.getModel())
Exemple #15
0
    def test_set_source_units(self):
        from libcellml import Units, ImportSource

        # void setSourceUnits(const ImportPtr &imp, const std::string &name)
        i = ImportSource()
        u = Units()
        u.setSourceUnits(i, 'hello')
Exemple #16
0
    def test_set_import_source(self):
        from libcellml import ImportedEntity, ImportSource

        # void setImportSource(const ImportPtr &imp)
        x = ImportedEntity()
        x.setImportSource(ImportSource())
        x.setImportSource(None)
Exemple #17
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 Units
        from libcellml import Variable

        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)
Exemple #18
0
    def test_import_units(self):
        from libcellml import Units, ImportSource

        i = ImportSource()
        u = Units()

        u.setImportSource(i)
        u.setImportReference("Volt")

        self.assertTrue(u.isImport())
Exemple #19
0
    def test_is_import(self):
        from libcellml import ImportedEntity, ImportSource

        # bool isImport()
        x = ImportedEntity()
        self.assertFalse(x.isImport())
        x.setImportSource(ImportSource())
        self.assertTrue(x.isImport())
        x.setImportSource(None)
        self.assertFalse(x.isImport())
Exemple #20
0
    def test_has_unresolved_imports(self):
        from libcellml import Model, Component, ImportSource

        # bool hasUnresolvedImports();
        m = Model()
        self.assertFalse(m.hasUnresolvedImports())
        c = Component()
        m.addComponent(c)
        self.assertFalse(m.hasUnresolvedImports())
        c.setImportSource(ImportSource())
        self.assertTrue(m.hasUnresolvedImports())
Exemple #21
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
    def test_clone(self):
        from libcellml import ImportSource

        sourceUrl = 'cheers'
        x = ImportSource()

        x.setUrl(sourceUrl)
        self.assertEqual(x.url(), sourceUrl)

        xCloned = x.clone()
        self.assertEqual(xCloned.url(), sourceUrl)
    def test_create(self):
        from libcellml import ImportSource

        x = ImportSource()
        del x
Exemple #24
0
    def test_set_import_source(self):
        from libcellml import Error, ImportSource

        # void setImportSource(const ImportSourcePtr &import)
        e = Error()
        e.setImportSource(ImportSource())
Exemple #25
0
    def test_set_import_source(self):
        from libcellml import Issue, ImportSource

        # void setImportSource(const ImportSourcePtr &import)
        e = Issue()
        e.setImportSource(ImportSource())
Exemple #26
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())
    def test_inheritance(self):
        import libcellml
        from libcellml import ImportSource

        x = ImportSource()
        self.assertIsInstance(x, libcellml.entity.Entity)
    def test_component(self):
        from libcellml import ImportSource, Component

        x = ImportSource()
        c1 = Component("c1")
        c2 = Component("c2")

        self.assertEqual(0, x.componentCount())

        x.addComponent(c1)
        x.addComponent(c2)

        self.assertEqual(2, x.componentCount())
        self.assertEqual("c2", x.component(1).name())

        x.removeComponent(1)

        self.assertEqual(1, x.componentCount())

        x.removeAllComponents()

        self.assertEqual(0, x.componentCount())
    def test_units(self):
        from libcellml import ImportSource, Units

        x = ImportSource()
        u1 = Units("u1")
        u2 = Units("u2")

        self.assertEqual(0, x.unitsCount())

        x.addUnits(u1)
        x.addUnits(u2)

        self.assertEqual(2, x.unitsCount())
        self.assertEqual("u2", x.units(1).name())

        x.removeUnits(1)

        self.assertEqual(1, x.unitsCount())

        x.removeAllUnits()

        self.assertEqual(0, x.unitsCount())
    #      We will import only the 'gateEquations' component and set it to be a child 
    #      of the n_gate_equations component.  This means we can introduce the voltage
    #      dependence for the alpha and beta, and using a specified initial value for 
    #      the gate's status.  Note that the variable 'n' in the n_gate_equations is 
    #      equivalent to the generic gate's variable 'X'.

    #  Imports require three things:
    #      - a destination for the imported item. This could be a Component or Units item.
    #      - a model to import for the imported item from.  This is stored in an ImportSource
    #        item containing the URL of the model to read.
    #      - the name of the item to import.  This is called the 'import reference' and 
    #        is stored by the destination item.

    #  4.a 
    #      Create an ImportSource item and set its URL to be 'GateModel.cellml'.
    gate_import_source = ImportSource()
    gate_import_source.setUrl('GateModel.cellml')

    #  4.b 
    #      Create a destination component for the imported gate component, and add this to 
    #      the n_gate_equations component. 
    imported_gate = Component('importedGate')
    n_gate_equations.addComponent(imported_gate)

    #  4.c 
    #      Set the import reference on the component you just created to be the name
    #      of the component in the GateModel.cellml file that you want to use.  In this
    #      example, it is 'gateEquations'.
    imported_gate.setImportReference('gateEquations')

    #  4.d