Пример #1
0
    def test_replace_model(self):
        from libcellml import Component, Importer, Model, Parser

        parser = Parser()

        model = parser.parseModel(
            file_contents("importer/generic_no_source.cellml"))

        importer = Importer()

        wrongSourceModel = Model("wrong")
        rightSourceModel = Model("right")
        rightSourceModel.addComponent(Component("a"))
        rightSourceModel.addComponent(Component("b"))
        rightSourceModel.addComponent(Component("c"))
        rightSourceModel.addComponent(Component("d"))

        self.assertTrue(
            importer.addModel(wrongSourceModel, "i_dont_exist.cellml"))

        self.assertFalse(
            importer.replaceModel(rightSourceModel, "not_in_library"))
        self.assertTrue(
            importer.replaceModel(rightSourceModel, "i_dont_exist.cellml"))

        importer.resolveImports(model, "")

        self.assertEqual(0, importer.issueCount())
        self.assertFalse(model.hasUnresolvedImports())
Пример #2
0
    def test_replace_model(self):
        from libcellml import Component, Importer, Model, Parser

        parser = Parser()

        model = parser.parseModel(
            file_contents('importer/generic_no_source.cellml'))

        importer = Importer()

        wrongSourceModel = Model('wrong')
        rightSourceModel = Model('right')
        rightSourceModel.addComponent(Component('a'))
        rightSourceModel.addComponent(Component('b'))
        rightSourceModel.addComponent(Component('c'))
        rightSourceModel.addComponent(Component('d'))

        self.assertTrue(
            importer.addModel(wrongSourceModel, 'i_dont_exist.cellml'))

        self.assertFalse(
            importer.replaceModel(rightSourceModel, 'not_in_library'))
        self.assertTrue(
            importer.replaceModel(rightSourceModel, 'i_dont_exist.cellml'))

        importer.resolveImports(model, '')

        self.assertEqual(0, importer.issueCount())
        self.assertFalse(model.hasUnresolvedImports())
Пример #3
0
    def test_clean(self):

        from libcellml import Component, Model, Units, Variable, Printer

        model = Model()
        c1 = Component('c1')
        c2 = Component()
        c2.setId('c2')
        c3 = Component()
        c4 = Component()
        u1 = Units('used')
        u2 = Units()
        u2.setId('u2')
        u3 = Units()
        v = Variable('x')

        model.addComponent(c1)
        model.addComponent(c2)
        model.addComponent(c3)
        model.addComponent(c4)
        model.addUnits(u1)
        model.addUnits(u2)
        model.addUnits(u3)

        c3.addVariable(v)

        self.assertEqual(4, model.componentCount())
        self.assertEqual(3, model.unitsCount())

        # Call the Model.clean() function to remove the empty items (c4 and u3).
        model.clean()

        self.assertEqual(3, model.componentCount())
        self.assertEqual(2, model.unitsCount())
Пример #4
0
    def test_create_destroy(self):
        from libcellml import Component

        # Test create/copy/destroy
        x = Component()
        del(x)
        y = Component()
        z = Component(y)
        del(y, z)
Пример #5
0
    def test_create_destroy(self):
        from libcellml import Component

        # Test create/copy/destroy
        x = Component()
        del x

        y = Component("c3")
        self.assertEqual("c3", y.name())
        del y
Пример #6
0
    def test_parent(self):
        from libcellml import Model, Component

        x = Model("model")
        self.assertIsNone(x.parent())

        c = Component()
        self.assertIsNone(c.parent())
        x.addComponent(c)
        self.assertEqual("model", c.parent().name())
        self.assertEqual(1, x.componentCount())
Пример #7
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())
Пример #8
0
    def test_get_component(self):
        from libcellml import Error, Component

        # ComponentPtr getComponent()
        e = Error()
        self.assertIsNone(e.getComponent())
        name = 'cellml'
        c = Component()
        c.setName(name)
        e.setComponent(c)
        self.assertIsInstance(e.getComponent(), Component)
        self.assertEqual(e.getComponent().getName(), name)
Пример #9
0
    def test_component(self):
        from libcellml import Issue, Component

        # ComponentPtr component()
        e = Issue()
        self.assertIsNone(e.component())
        name = 'cellml'
        c = Component()
        c.setName(name)
        e.setComponent(c)
        self.assertIsInstance(e.component(), Component)
        self.assertEqual(e.component().name(), name)
Пример #10
0
    def test_inherited_methods(self):
        from libcellml import Component

        x = Component()
        idx = 'test'
        self.assertEqual(x.getId(), '')
        x.setId(idx)
        self.assertEqual(x.getId(), idx)
        y = Component(x)
        self.assertEqual(y.getId(), idx)
Пример #11
0
    def test_has_parent(self):
        from libcellml import Entity, Component

        # bool hasParent(Component* c)
        x = Entity()
        c1 = Component()
        self.assertFalse(x.hasParent())
        x.setParent(c1)
        self.assertTrue(x.hasParent())
        x.clearParent()
        self.assertFalse(x.hasParent())
        c2 = Component()
        c2.setParent(c1)
        x.setParent(c2)
        self.assertTrue(x.hasParent())
Пример #12
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)
Пример #13
0
    def test_add_component(self):
        from libcellml import ComponentEntity, Component

        # void addComponent(const ComponentPtr &c)
        x = ComponentEntity()
        y = Component()
        x.addComponent(y)
Пример #14
0
    def test_has_parent(self):
        from libcellml import Entity, Component

        # bool hasParent(Component* c)
        x = Entity()
        c = Component()
        self.assertFalse(x.hasParent(c))
        x.setParent(c)
        self.assertTrue(x.hasParent(c))
        x.clearParent()
        self.assertFalse(x.hasParent(c))
        d = Component()
        d.setParent(c)
        x.setParent(d)
        self.assertTrue(x.hasParent(d))
        self.assertTrue(x.hasParent(c))
Пример #15
0
    def test_remove_parent(self):
        from libcellml import Model, Component

        m = Model()
        c = Component()
        c.setParent(m)
        self.assertIsNotNone(c.parent())
        c.removeParent()
        self.assertIsNone(c.parent())
Пример #16
0
    def test_create_destroy(self):
        from libcellml import AnalyserExternalVariable
        from libcellml import Component
        from libcellml import Model
        from libcellml import Variable

        m = Model('model')
        c = Component('component')
        v = Variable('test')

        self.assertTrue(m.addComponent(c))
        self.assertTrue(c.addVariable(v))

        aev = AnalyserExternalVariable(v)

        self.assertEqual(v.name(), aev.variable().name())

        d0 = Variable('d0')
        d1 = Variable('d1')
        d2 = Variable('d2')
        d3 = Variable('d3')

        c.addVariable(d0)
        c.addVariable(d1)
        c.addVariable(d2)
        c.addVariable(d3)

        self.assertTrue(aev.addDependency(d0))
        self.assertTrue(aev.addDependency(d1))
        self.assertTrue(aev.addDependency(d2))
        self.assertTrue(aev.addDependency(d3))

        self.assertEqual(4, aev.dependencyCount())

        self.assertIsNotNone(aev.dependency(0))
        self.assertIsNotNone(aev.dependency(m, c.name(), d1.name()))

        self.assertIsNotNone(aev.dependencies())

        self.assertTrue(aev.containsDependency(d0))
        self.assertTrue(aev.containsDependency(m, c.name(), d1.name()))

        self.assertTrue(aev.removeDependency(1))
        self.assertTrue(aev.removeDependency(d0))
        self.assertTrue(aev.removeDependency(m, c.name(), d2.name()))

        aev.removeAllDependencies()
Пример #17
0
    def test_replace_component(self):
        from libcellml import Component

        c = Component()
        c1 = Component("component_1")

        c.addComponent(c1)

        c2 = Component("component_2")

        self.assertTrue(c.replaceComponent(0, c2))
        self.assertEqual(1, c.componentCount())
        self.assertEqual("component_2", c.component(0).name())
Пример #18
0
    def test_component_ref(self):
        from libcellml import Issue, Component

        e = Issue()
        self.assertIsNone(e.math())
        c = Component("comp")
        e.setComponentRef(c)
        self.assertIsInstance(e.componentRef(), Component)
        self.assertEqual(e.componentRef().name(), "comp")
Пример #19
0
    def test_inheritance(self):
        import libcellml
        from libcellml import Component

        x = Component()
        self.assertIsInstance(x, libcellml.componententity.ComponentEntity)
        self.assertIsInstance(x, libcellml.importedentity.ImportedEntity)
        self.assertIsInstance(x, libcellml.namedentity.NamedEntity)
        self.assertIsInstance(x, libcellml.entity.Entity)
Пример #20
0
    def test_add_component(self):
        from libcellml import Model, Component

        m = Model()
        c = Component()

        self.assertEqual(0, m.componentCount())
        m.addComponent(c)
        self.assertTrue(m.containsComponent(c))
        self.assertEqual(1, m.componentCount())
Пример #21
0
    def test_remove_all_components(self):
        from libcellml import ComponentEntity, Component

        # void removeAllComponents()
        x = ComponentEntity()
        x.removeAllComponents()
        x.addComponent(Component())
        self.assertEqual(x.componentCount(), 1)
        x.removeAllComponents()
        self.assertEqual(x.componentCount(), 0)
Пример #22
0
    def test_link_units(self):
        from libcellml import Component, Model, Units, Variable

        m = Model()
        c = Component()
        v = Variable()
        u = Units("orange")

        self.assertFalse(m.hasUnlinkedUnits())

        m.addUnits(u)
        v.setUnits("orange")
        c.addVariable(v)
        m.addComponent(c)

        self.assertTrue(m.hasUnlinkedUnits())

        m.linkUnits()

        self.assertFalse(m.hasUnlinkedUnits())
Пример #23
0
    def test_remove_component(self):
        from libcellml import Model, Component

        m = Model()
        c1 = Component()
        c2 = Component()

        self.assertEqual(0, m.componentCount())
        m.addComponent(c1)
        m.addComponent(c2)
        self.assertEqual(2, m.componentCount())

        m.removeAllComponents()
        self.assertEqual(0, m.componentCount())

        m.addComponent(c1)
        m.addComponent(c2)

        self.assertEqual(2, m.componentCount())
        m.removeComponent(c2)
        self.assertEqual(1, m.componentCount())
Пример #24
0
    def test_remove_all_variables(self):
        from libcellml import Component, Variable

        # void removeAllVariables()
        c = Component()
        v1 = Variable()
        v2 = Variable()
        c.addVariable(v1)
        c.addVariable(v2)
        self.assertTrue(c.hasVariable(v1))
        self.assertTrue(c.hasVariable(v2))
        c.removeAllVariables()
        self.assertFalse(c.hasVariable(v1))
        self.assertFalse(c.hasVariable(v2))
Пример #25
0
    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())
Пример #26
0
    def test_clone(self):
        from libcellml import Component, Model, Units, Variable

        m = Model()
        c1 = Component("c1")
        c2 = Component("c2")
        v = Variable("v1")
        u = Units("apple")

        m.addComponent(c1)
        m.addComponent(c2)
        c1.addVariable(v)
        v.setUnits(u)
        m.addUnits(u)

        mCloned = m.clone()

        self.assertEqual(2, mCloned.componentCount())
        self.assertEqual(1, mCloned.unitsCount())
        self.assertEqual(1, mCloned.component(0).variableCount())
        self.assertEqual("apple",
                         mCloned.component(0).variable(0).units().name())
Пример #27
0
    def test_set_parent(self):
        from libcellml import Entity, Model, Component

        m = Model()
        x = Entity()
        x.setParent(m)
        self.assertIsNotNone(x.parent())
        # TODO: Check equivalence

        c = Component()
        x = Entity()
        x.setParent(c)
        self.assertIsNotNone(x.parent())
Пример #28
0
    def test_reset(self):
        from libcellml import Component, Reset

        c = Component()
        r = Reset()
        r.setTestValue('<math></math>')
        c.addReset(r)
        self.assertEqual(1, c.resetCount())
        self.assertTrue(c.hasReset(r))

        rReturned = c.reset(0)
        self.assertEqual(r.testValue(), rReturned.testValue())
Пример #29
0
    def test_clear_parent(self):
        from libcellml import Entity, Model, Component

        # void clearParent()
        x = Entity()
        self.assertIsNone(x.getParent())
        x.setParent(Model())
        self.assertIsNotNone(x.getParent())
        x.clearParent()
        self.assertIsNone(x.getParent())
        x.setParent(Component())
        self.assertIsNotNone(x.getParent())
        x.clearParent()
        self.assertIsNone(x.getParent())
Пример #30
0
    def test_add_model(self):
        from libcellml import Component, Importer, Model, Parser

        parser = Parser()
        importer = Importer()

        model = parser.parseModel(
            file_contents('importer/generic_no_source.cellml'))

        sourceModel = Model('source')
        sourceModel.addComponent(Component('a'))
        sourceModel.addComponent(Component('b'))
        sourceModel.addComponent(Component('c'))
        sourceModel.addComponent(Component('d'))

        # Add a model manually to the library, including the URL that it will replace in future imports.
        self.assertTrue(importer.addModel(sourceModel, 'i_dont_exist.cellml'))
        self.assertFalse(importer.addModel(sourceModel, 'i_dont_exist.cellml'))

        importer.resolveImports(model, '')

        self.assertEqual(0, importer.issueCount())
        self.assertFalse(model.hasUnresolvedImports())