[Zope-CVS] CVS: PythonNet/tests/python - test_constructors.py:1.1 test_array.py:1.5 test_class.py:1.9 test_enum.py:1.3 test_interface.py:1.3 test_method.py:1.4 test_module.py:1.5

Brian Lloyd brian at zope.com
Sat Jan 17 23:29:39 EST 2004


Update of /cvs-repository/PythonNet/tests/python
In directory cvs.zope.org:/tmp/cvs-serv26381/tests/python

Modified Files:
	test_array.py test_class.py test_enum.py test_interface.py 
	test_method.py test_module.py 
Added Files:
	test_constructors.py 
Log Message:
Checkin miscellaneous stuff done since Nov.


=== Added File PythonNet/tests/python/test_constructors.py ===
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
#
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.

import sys, os, string, unittest, types
import CLR.Python.Test as Test
import CLR.System as System


class ConstructorTests(unittest.TestCase):
    """Test CLR class constructor support."""

    def testEnumConstructor(self):
        """Test enum constructor args"""
        from Test import EnumConstructorTest

        ob = EnumConstructorTest(TypeCode.Int32)
        self.failUnless(ob.value == TypeCode.Int32)


    def testFlagsConstructor(self):
        """Test flags constructor args"""
        from Test import FlagsConstructorTest
        from System.IO import FileAccess
        
        flags = FileAccess.Read | FileAccess.Write
        ob = FlagsConstructorTest(flags)
        self.failUnless(ob.value == flags)


    def testStructConstructor(self):
        """Test struct constructor args"""
        from Test import StructConstructorTest

        guid = Guid.NewGuid()
        ob = StructConstructorTest(guid)
        self.failUnless(ob.value == guid)


    def testSubclassConstructor(self):
        """Test subclass constructor args"""
        from Test import SubclassConstructorTest
        from System.Windows.Forms import Form, Control

        class sub(Form):
            pass

        form = sub()
        ob = SubclassConstructorTest(form)
        self.failUnless(isinstance(ob.value, Control))



def test_suite():
    return unittest.makeSuite(ConstructorTests)

def main():
    unittest.TextTestRunner().run(test_suite())

if __name__ == '__main__':
    testcase.setup()
    main()



=== PythonNet/tests/python/test_array.py 1.4 => 1.5 ===
--- PythonNet/tests/python/test_array.py:1.4	Mon Oct 20 23:05:16 2003
+++ PythonNet/tests/python/test_array.py	Sat Jan 17 23:29:37 2004
@@ -1289,6 +1289,44 @@
         self.failUnless(result[0, 0].__class__ == Spam)
 
 
+    def testBoxedValueTypeMutationResult(self):
+        """Test behavior of boxed value types."""
+
+        # This test actually exists mostly as documentation of an important
+        # concern when dealing with value types. Python does not have any
+        # value type semantics that can be mapped to the CLR, so it is easy
+        # to accidentally write code like the following which is not really
+        # mutating value types in-place but changing boxed copies.
+        
+        from CLR.System.Drawing import Point
+        from CLR.System import Array
+
+        items = Array.CreateInstance(Point, 5)
+
+        for i in range(5):
+            items[i] = Point(i, i)
+
+        for i in range(5):
+            # Boxed items, so settr will not change the array member.
+            self.failUnless(items[i].X == i)
+            self.failUnless(items[i].Y == i)
+            items[i].X = i + 1
+            items[i].Y = i + 1
+            self.failUnless(items[i].X == i)
+            self.failUnless(items[i].Y == i)
+
+        for i in range(5):
+            # Demonstrates the workaround that will change the members.
+            self.failUnless(items[i].X == i)
+            self.failUnless(items[i].Y == i)
+            item = items[i]
+            item.X = i + 1
+            item.Y = i + 1
+            items[i] = item
+            self.failUnless(items[i].X == i + 1)
+            self.failUnless(items[i].Y == i + 1)
+
+
     def testArrayAbuse(self):
         """Test array abuse."""
         _class = Test.PublicArrayTest


=== PythonNet/tests/python/test_class.py 1.8 => 1.9 ===
--- PythonNet/tests/python/test_class.py:1.8	Thu Nov  6 23:05:06 2003
+++ PythonNet/tests/python/test_class.py	Sat Jan 17 23:29:37 2004
@@ -36,7 +36,13 @@
         self.failUnless(ClassTest.__name__ == 'ClassTest')
         self.failUnless(ClassTest.__module__ == 'CLR.Python.Test')
         self.failUnless(type(ClassTest.__dict__) == types.DictProxyType)
-        self.failUnless(ClassTest.__doc__ == None)
+        self.failUnless(len(ClassTest.__doc__) > 0)
+
+
+    def testClassDocstrings(self):
+        """Test standard class docstring generation"""
+        value = 'Void .ctor()'
+        self.failUnless(ClassTest.__doc__ == value)
 
 
     def testNonPublicClass(self):


=== PythonNet/tests/python/test_enum.py 1.2 => 1.3 ===
--- PythonNet/tests/python/test_enum.py:1.2	Tue Oct  7 22:29:18 2003
+++ PythonNet/tests/python/test_enum.py	Sat Jan 17 23:29:37 2004
@@ -22,7 +22,7 @@
         self.failUnless(DayOfWeek.__name__ == 'DayOfWeek')
         self.failUnless(DayOfWeek.__module__ == 'CLR.System')
         self.failUnless(type(DayOfWeek.__dict__) == types.DictProxyType)
-        self.failUnless(DayOfWeek.__doc__ == None)
+        self.failUnless(DayOfWeek.__doc__ == '')
 
 
     def testEnumGetMember(self):


=== PythonNet/tests/python/test_interface.py 1.2 => 1.3 ===
--- PythonNet/tests/python/test_interface.py:1.2	Tue Oct  7 22:29:18 2003
+++ PythonNet/tests/python/test_interface.py	Sat Jan 17 23:29:37 2004
@@ -20,10 +20,10 @@
 
     def testInterfaceStandardAttrs(self):
         """Test standard class attributes."""
-        self.failUnless(InterfaceTest.__name__ == 'InterfaceTest')
-        self.failUnless(InterfaceTest.__module__ == 'CLR.Python.Test')
-        self.failUnless(type(InterfaceTest.__dict__) == types.DictProxyType)
-        self.failUnless(InterfaceTest.__doc__ == None)
+        from CLR.Python.Test import IPublicInterface as ip
+        self.failUnless(ip.__name__ == 'IPublicInterface')
+        self.failUnless(ip.__module__ == 'CLR.Python.Test')
+        self.failUnless(type(ip.__dict__) == types.DictProxyType)
 
 
     def testGlobalInterfaceVisibility(self):


=== PythonNet/tests/python/test_method.py 1.3 => 1.4 ===
--- PythonNet/tests/python/test_method.py:1.3	Mon Oct 27 21:07:03 2003
+++ PythonNet/tests/python/test_method.py	Sat Jan 17 23:29:37 2004
@@ -183,6 +183,68 @@
         self.failUnlessRaises(AttributeError, test)
 
 
+    def testMethodDocstrings(self):
+        """Test standard method docstring generation"""
+        method = MethodTest.GetType
+        value = 'System.Type GetType()'
+        self.failUnless(method.__doc__ == value)
+
+
+    #======================================================================
+    # Tests of specific argument and result conversion scenarios
+    #======================================================================
+
+    def testMethodCallEnumConversion(self):
+        """Test enum conversion in method call."""
+        from CLR.System import TypeCode
+
+        object = MethodTest()
+        r = object.TestEnumConversion(TypeCode.Int32)
+        self.failUnless(r == TypeCode.Int32)
+
+
+    def testMethodCallFlagsConversion(self):
+        """Test flags conversion in method call."""
+        from CLR.System.IO import FileAccess
+
+        object = MethodTest()
+        flags = FileAccess.Read | FileAccess.Write
+        r = object.TestFlagsConversion(flags)
+        self.failUnless(r == flags)
+
+
+    def testMethodCallStructConversion(self):
+        """Test struct conversion in method call."""
+        from CLR.System import Guid
+
+        object = MethodTest()
+        guid = Guid.NewGuid()
+        temp = guid.ToString()
+        r = object.TestStructConversion(guid)
+        self.failUnless(r.ToString() == temp)
+
+
+    def testSubclassInstanceConversion(self):
+        """Test subclass instance conversion in method call."""
+        from CLR.System.Windows.Forms import Form, Control
+
+        class sub(Form):
+            pass
+
+        object = MethodTest()
+        form = sub()
+        result = object.TestSubclassConversion(form)
+        self.failUnless(isinstance(result, Control))
+
+
+    def testNullArrayConversion(self):
+        """Test null array conversion in method call."""
+        from CLR.System import Type
+
+        object = MethodTest()
+        r = object.TestNullArrayConversion(None)
+        self.failUnless(r == None)
+
 
 def test_suite():
     return unittest.makeSuite(MethodTests)


=== PythonNet/tests/python/test_module.py 1.4 => 1.5 ===
--- PythonNet/tests/python/test_module.py:1.4	Wed Oct 22 22:53:11 2003
+++ PythonNet/tests/python/test_module.py	Sat Jan 17 23:29:37 2004
@@ -22,6 +22,13 @@
     def isCLRClass(self, object):
         return type(object).__name__ == 'CLR Metatype' # for now
 
+    def testAAAImportHookWorks(self):
+        """Test that the import hook works correctly both using the
+           included runtime and an external runtime. This must be
+           the first test run in the unit tests!"""
+
+        from CLR.System import String
+
 
     def testModuleInterface(self):
         """Test the interface exposed by CLR module objects."""
@@ -29,16 +36,10 @@
 
         self.assertEquals(type(System.__dict__), type({}))
         self.assertEquals(System.__name__, 'CLR.System')
+        self.assertEquals(System.__file__, None)
         self.assertEquals(System.__doc__, None)
         self.failUnless(self.isCLRClass(System.String))
         self.failUnless(self.isCLRClass(System.Int32))
-
-        def test():
-            # CLR modules don't define __file__
-            import CLR.System as System
-            file = System.__file__
-
-        self.failUnlessRaises(AttributeError, test)
 
 
     def testSimpleImport(self):




More information about the Zope-CVS mailing list