コード例 #1
0
    #  3.e
    #      Check that the id of 'polo' is now unique in the model by calling the
    #      isUnique function.
    assert (annotator.isUnique('polo'))

    #  end 3.e

    #  Now we know that there is only one item in the model with id 'polo', and we also know
    #  that it has type UNIT.  This means that we can retrieve a Unit item directly from the
    #  annotator rather than needing to cast it using the std.any_cast.  Instead of calling
    #  the annotator's item function, call the Annotator.unit function with the id 'polo' to return the
    #  unit item directly.

    #  3.f
    #      Retrieve the Units item with id polo without casting.
    polo_unit = annotator.unitsItem('polo')

    #  end 3.f
    #  The Unit item is an object it has methods. **TODO**
    #      - units() to retreive the units the unit belongs to, and
    #      - index() to retreive the index of this Unit within the parent.

    print('----------------------------------------------------------')
    print('   STEP 4: See who else is lurking in this pool           ')
    print('----------------------------------------------------------')

    #  Now that we've found Marco and fixed the duplicates of Polo, we'd like to know
    #  what other ids are being used in this model.
    #  4.a
    #      Use the Annotator.ids function to return a vector of id strings used in the model, and
    #      print them to the terminal.
コード例 #2
0
    def test_type_based_retrieval(self):
        from libcellml import Annotator, Model, Parser

        annotator = Annotator()
        model = Model()
        parser = Parser()

        model_string = file_contents("annotator/unique_ids.cellml")

        model = parser.parseModel(model_string)
        annotator.setModel(model)

        v1v1 = (model.component("component2").variable("variable1"), model.component(
            "component2").component("component3").variable("variable1"))
        v2v2 = (model.component("component2").variable("variable2"), model.component(
            "component2").component("component3").variable("variable2"))

        self.assertEqual(model.name(), annotator.model("model_1").name())
        self.assertEqual(model.name(), annotator.encapsulation("encapsulation_1").name())
        self.assertEqual(model.component("component1").name(),
                         annotator.component("component_1").name())
        self.assertEqual(model.component("component2").name(),
                         annotator.component("component_2").name())
        self.assertEqual(model.component("component2").name(),
                         annotator.componentEncapsulation("component_ref_1").name())
        self.assertEqual(model.component("component2").component("component3").name(),
                         annotator.component("component_3").name())
        self.assertEqual(model.component("component2").component("component3").name(),
                         annotator.componentEncapsulation("component_ref_2").name())
        self.assertEqual(model.component("component1").importSource().url(),
                         annotator.importSource("import_1").url())
        self.assertEqual(model.units("units1").name(),
                         annotator.units("units_1").name())
        self.assertEqual(model.units("units1").importSource().url(),
                         annotator.importSource("import_2").url())
        self.assertEqual(model.units("units2").name(),
                         annotator.units("units_2").name())
        self.assertEqual(model.units("units2").name(),
                         annotator.unitsItem("unit_1").units().name())
        self.assertEqual(0, annotator.unitsItem("unit_1").index())

        self.assertEqual(model.component("component2").variable("variable1").name(),
                         annotator.variable("variable_1").name())

        self.assertEqual(model.component("component2").variable("variable2").name(),
                         annotator.variable("variable_2").name())
        self.assertEqual(model.component("component2").reset(0).variable().name(),
                         annotator.reset("reset_1").variable().name())
        self.assertEqual(model.component("component2").reset(0).testVariable().name(),
                         annotator.reset("reset_1").testVariable().name())
        self.assertEqual(model.component("component2").reset(0).testValue(),
                         annotator.testValue("test_value_1").testValue())
        self.assertEqual(model.component("component2").reset(0).resetValue(),
                         annotator.resetValue("reset_value_1").resetValue())

        self.assertEqual(model.component("component2").component("component3").variable("variable1").name(),
                         annotator.variable("variable_3").name())
        self.assertEqual(model.component("component2").component("component3").variable("variable2").name(),
                         annotator.variable("variable_4").name())
        self.assertEqual(v1v1[0].name(),
                         annotator.connection("connection_1").variable1().name())

        self.assertEqual(v1v1[1].name(),
                         annotator.connection("connection_1").variable2().name())
        self.assertEqual(v1v1[0].name(),
                         annotator.mapVariables("map_variables_1").variable1().name())
        self.assertEqual(v1v1[1].name(),
                         annotator.mapVariables("map_variables_1").variable2().name())
        self.assertEqual(v2v2[0].name(),
                         annotator.mapVariables("map_variables_2").variable1().name())
        self.assertEqual(v2v2[1].name(),
                         annotator.mapVariables("map_variables_2").variable2().name())

        self.assertIsNone(annotator.model("i_dont_exist"))
        self.assertIsNone(annotator.component("i_dont_exist"))
        self.assertIsNone(annotator.variable("i_dont_exist"))
        self.assertIsNone(annotator.units("i_dont_exist"))
        self.assertIsNone(annotator.unitsItem("i_dont_exist"))
        self.assertIsNone(annotator.reset("i_dont_exist"))
        self.assertIsNone(annotator.resetValue("i_dont_exist"))
        self.assertIsNone(annotator.testValue("i_dont_exist"))
        self.assertIsNone(annotator.componentEncapsulation("i_dont_exist"))
        self.assertIsNone(annotator.connection("i_dont_exist"))
        self.assertIsNone(annotator.importSource("i_dont_exist"))