Пример #1
0
    def test_importer(self):
        from libcellml import Importer, Parser, Printer

        parser = Parser()
        i = Importer()

        m = parser.parseModel(file_contents('importer/diamond.cellml'))
        printer = Printer()

        i.resolveImports(m, resource_path('importer/'))
        self.assertFalse(m.hasUnresolvedImports())

        # Library should contain left, right, and one instance (not two) of the point.
        self.assertEqual(3, i.libraryCount())
        self.assertEqual(resource_path('importer/diamond_left.cellml'),
                         i.key(0))
        self.assertEqual(resource_path('importer/diamond_point.cellml'),
                         i.key(1))
        self.assertEqual(resource_path('importer/diamond_right.cellml'),
                         i.key(2))

        # Access library items by their URL.
        left = i.library(resource_path('importer/diamond_left.cellml'))

        self.assertEqual(file_contents('importer/diamond_left.cellml'),
                         printer.printModel(left))
Пример #2
0
    def test_remove_all_models(self):
        from libcellml import Parser, Importer
        parser = Parser()
        model = parser.parseModel(file_contents('importer/diamond.cellml'))
        importer = Importer()
        importer.resolveImports(model, resource_path('importer/'))

        self.assertEqual(3, importer.libraryCount())

        importer.removeAllModels()

        self.assertEqual(0, importer.libraryCount())
Пример #3
0
    def test_flatten(self):
        from libcellml import Importer, Parser

        parser = Parser()
        importer = Importer()

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

        importer.resolveImports(model, resource_path('importer/'))

        flattenedModel = importer.flattenModel(model)
        self.assertEqual(2, flattenedModel.componentCount())
Пример #4
0
    def test_resolve_imports(self):
        from libcellml import Importer
        from libcellml import Parser

        i = Importer()
        p = Parser()

        m1 = p.parseModel(file_contents('importer/units_imported.cellml'))
        m2 = p.parseModel(file_contents('importer/units_imported.cellml'))
        m3 = p.parseModel(file_contents('importer/units_imported.cellml'))

        self.assertEqual(0, p.issueCount())

        self.assertTrue(m1.hasUnresolvedImports())
        i.resolveImports(m1, resource_path('importer/'))
        self.assertFalse(m1.hasUnresolvedImports())

        self.assertTrue(m2.hasUnresolvedImports())
        i.resolveImports(m2, resource_path('importer'))
        self.assertFalse(m2.hasUnresolvedImports())

        self.assertTrue(m3.hasUnresolvedImports())
        i.resolveImports(m3, resource_path('importer\\'))
        self.assertFalse(m3.hasUnresolvedImports())
Пример #5
0
    def test_resolve_imports(self):
        from libcellml import Importer
        from libcellml import Parser

        i = Importer()
        p = Parser()

        m = p.parseModel(file_contents('sine_approximations_import.xml'))

        self.assertEqual(0, p.issueCount())

        self.assertTrue(m.hasUnresolvedImports())

        i.resolveImports(m, resource_path())
        self.assertFalse(m.hasUnresolvedImports())
Пример #6
0
    def test_is_resolved_component(self):
        from libcellml import Importer, Parser

        parser = Parser()
        importer = Importer()

        model = parser.parseModel(
            file_contents("importer/component_importer_unresolved.cellml"))
        self.assertEqual(0, parser.issueCount())
        importer.resolveImports(model, resource_path("importer/"))

        self.assertEqual(1, importer.issueCount())

        c = model.component(0)

        self.assertFalse(c.isResolved())
Пример #7
0
    def test_is_resolved_units(self):
        from libcellml import Importer, Parser

        parser = Parser()
        importer = Importer()

        model = parser.parseModel(
            file_contents("importer/master_units.cellml"))
        self.assertEqual(0, parser.issueCount())

        importer.resolveImports(model, resource_path("importer/"))

        self.assertEqual(0, importer.issueCount())

        u = model.units(0)

        self.assertTrue(u.isResolved())
Пример #8
0
    def test_clear_imports(self):
        from libcellml import Importer, Parser

        parser = Parser()
        importer = Importer()

        model = parser.parseModel(
            file_contents('importer/nested_components.cellml'))
        self.assertEqual(0, parser.issueCount())

        importer.resolveImports(model, resource_path('importer/'))

        self.assertEqual(0, importer.issueCount())

        self.assertFalse(model.hasUnresolvedImports())
        importer.clearImports(model)
        self.assertTrue(model.hasUnresolvedImports())