Ejemplo n.º 1
0
    def testInterface(self):
        """Test python classes can derive from C# interfaces"""
        object = InterfaceTestClass()
        self.assertEqual(object.foo(), "InterfaceTestClass")
        self.assertEqual(TestFunctions.test_foo(object), "InterfaceTestClass")
        self.assertEqual(object.bar("bar", 2), "bar/bar")
        self.assertEqual(TestFunctions.test_bar(object, "bar", 2), "bar/bar")

        x = TestFunctions.pass_through(object)
        self.assertEqual(id(x), id(object))
Ejemplo n.º 2
0
    def testCreateInstance(self):
        """Test derived instances can be created from managed code"""
        object = TestFunctions.create_instance(DerivedClass)
        self.assertEqual(object.foo(), "DerivedClass")
        self.assertEqual(TestFunctions.test_foo(object), "DerivedClass")
        self.assertEqual(object.bar("bar", 2), "bar_bar")
        self.assertEqual(TestFunctions.test_bar(object, "bar", 2), "bar_bar")
        self.assertEqual(object.not_overriden(), "not_overriden")

        x = TestFunctions.pass_through(object)
        self.assertEqual(id(x), id(object))

        object2 = TestFunctions.create_instance(InterfaceTestClass)
        self.assertEqual(object2.foo(), "InterfaceTestClass")
        self.assertEqual(TestFunctions.test_foo(object2), "InterfaceTestClass")
        self.assertEqual(object2.bar("bar", 2), "bar/bar")
        self.assertEqual(TestFunctions.test_bar(object2, "bar", 2), "bar/bar")

        y = TestFunctions.pass_through(object2)
        self.assertEqual(id(y), id(object2))
Ejemplo n.º 3
0
    def testDerivedClass(self):
        """Test python class derived from managed type"""
        object = DerivedClass()
        self.assertEqual(object.foo(), "DerivedClass")
        self.assertEqual(object.base_foo(), "foo")
        self.assertEqual(object.super_foo(), "foo")
        self.assertEqual(TestFunctions.test_foo(object), "DerivedClass")
        self.assertEqual(object.bar("bar", 2), "bar_bar")
        self.assertEqual(TestFunctions.test_bar(object, "bar", 2), "bar_bar")
        self.assertEqual(object.not_overriden(), "not_overriden")
        self.assertEqual(list(object.return_list()), ["A", "B", "C"])
        self.assertEqual(list(SubClassTest.test_list(object)), ["A", "B", "C"])

        x = TestFunctions.pass_through(object)
        self.assertEqual(id(x), id(object))