コード例 #1
0
ファイル: test_model.py プロジェクト: awickens/libcellml
    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())
コード例 #2
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')
コード例 #3
0
    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(), '')
コード例 #4
0
    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)
コード例 #5
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(), '')
コード例 #6
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)
コード例 #7
0
    def test_set_url(self):
        from libcellml import ImportSource

        # void setUrl(const std::string &reference)
        x = ImportSource()
        x.setUrl('')
        x.setUrl('hello')
        x.setUrl('')
コード例 #8
0
    #      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 
    #      Associate the import source with the component using the setImportSource function.