示例#1
0
 def testBaseClass(self):
     """Test base class managed type"""
     object = SubClassTest()
     self.assertEqual(object.foo(), "foo")
     self.assertEqual(TestFunctions.test_foo(object), "foo")
     self.assertEqual(object.bar("bar", 2), "bar")
     self.assertEqual(TestFunctions.test_bar(object, "bar", 2), "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"])
示例#2
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))
示例#3
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))
示例#4
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))