Exemplo n.º 1
0
    def test_enum(self):
        """Test how an enum is written in Python"""

        names = ["ONE", "TWO", "THREE"]
        values = [1, 2, 3]
        constants = [
                m.Mock(
                    name="TEST_ENUM_%s_VALUE" % n,
                    value=v,
                    comment="Value comment")
                for (n, v) in zip(names, values)]
        enum = m.Mock(
                name="TestEnum",
                comment="Enum description",
                constants=constants)

        result = enum_to_py(enum)
        expected = ('class TestEnum(Enum):\n'
            '    """Enum description\n'
            '    """\n'
            '\n'
            '    ONE = 1  # Value comment\n'
            '    TWO = 2  # Value comment\n'
            '    THREE = 3  # Value comment')
        self.assertEqual(result, expected)
Exemplo n.º 2
0
    def test_properties(self):
        """Test that get and set methods are translated to properties"""

        type = m.Mock(
                name="CMISSTestType")
        routines = [
                "CMISSTestLabelGet",
                "CMISSTestLabelSet",
                "CMISSTestSetPropertySet",
                "CMISSTestGetPropertyGet",
                "CMISSTestDoSomething"]
        type.methods = [
                m.Mock(name=r, comment_lines=[], parameters=[None, None])
                for r in routines]
        type.methods.append(
                m.Mock(
                    name="CMISSTestTooManyParamsGet",
                    comment_lines=[],
                    parameters=[None, None, None]))
        properties = [p[0] for p in type_properties(type)]

        self.assertTrue("Label" in properties)
        # If there's only a Get or Set, these are still included but
        # as read or write only properties
        self.assertTrue("SetProperty" in properties)
        self.assertTrue("GetProperty" in properties)
        self.assertFalse("DoSomething" in properties)
        self.assertFalse("TooManyParameters" in properties)
Exemplo n.º 3
0
Arquivo: test_c.py Projeto: mmak33/cm
    def test_routine_names(self):
        """Test how routines are renamed for the C bindings

        Only interface routines that take C strings and arrays rather
        than scalars are kept, so those indicators not needed in the names.
        """

        test_obj_names = [
            "CMISSRoutineObj", "CMISSRoutine1", "CMISSRoutineC1",
            "CMISSRoutineCObj"
        ]
        expected_obj_names = ("CMISSRoutine", "CMISSRoutineC")

        test_num_names = [
            "CMISSRoutineNumber", "CMISSRoutineCNumber", "CMISSRoutineNumber0",
            "CMISSRoutineCNumber1", "CMISSRoutineCCNumber1"
        ]
        expected_num_names = ("CMISSRoutineNum", "CMISSRoutineCNum")

        for routine_name in test_obj_names:
            routine = m.Mock(name=routine_name)
            self.assertEqual(subroutine_c_names(routine), expected_obj_names)
        for routine_name in test_num_names:
            routine = m.Mock(name=routine_name)
            self.assertEqual(subroutine_c_names(routine), expected_num_names)
Exemplo n.º 4
0
    def test_property_docstring(self):
        """Test conversion of get/set routine comment to property docstring"""

        comments = [
                "Sets/changes the test property.",
                "Returns the test property.",
                "Gets the test property."]
        for comment in comments:
            property = m.Mock(comment_lines=[comment])
            result = property_docstring(property)
            self.assertEqual(result, "The test property.")