Example #1
0
    def testCppPythonInheritanceDirectors(self):
        """ Test that we can extend a C++ object in Python and use the extensions from C++ """
        # This returns "I am a C++ object".
        cpp_class = SimpleDummyBaseClass()
        self.assertEqual(cpp_class.whoAmI(), "I am a C++ object")

        # This is a dummy prototype.
        class DerrivedClass(SimpleDummyBaseClass):
            def __init__(self):
                # Call the base class constructor.
                SimpleDummyBaseClass.__init__(self)
            def whoAmI(self):
                return "I am extended in Python"

        # Now we get another answer from calling whoAmI()
        py_class = DerrivedClass()
        self.assertEqual(py_class.whoAmI(), "I am extended in Python")

        # Calling from C++ gives the same result.
        self.assertEqual(Backend.callWhoAmI(cpp_class), "I am a C++ object")

        self.assertEqual(Backend.callWhoAmI(py_class), "I am extended in Python")
Example #2
0
 def __init__(self):
     # Call the base class constructor.
     SimpleDummyBaseClass.__init__(self)