[Zope-CVS] CVS: PythonNet/tests/python - stresstest.py:1.2 test_event.py:1.5 test_module.py:1.4

Brian Lloyd cvs-admin at zope.org
Wed Oct 22 22:53:12 EDT 2003


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

Modified Files:
	stresstest.py test_event.py test_module.py 
Log Message:
Lots of fixes to support Python 2.3.2, new sneaky CLR.dll stub to support 
loading the managed runtime into a plain CPython process, prep for b1.


=== PythonNet/tests/python/stresstest.py 1.1 => 1.2 ===
--- PythonNet/tests/python/stresstest.py:1.1	Mon Oct 20 23:05:16 2003
+++ PythonNet/tests/python/stresstest.py	Wed Oct 22 22:53:11 2003
@@ -6,12 +6,12 @@
     import time
     start = time.clock()
 
-    for i in range(20000):
+    for i in range(200):
         print i
         for name in (
             'test_module',
             'test_conversion',
-            'test_class',
+            #'test_class',
             'test_interface',
             'test_enum',
             'test_field',
@@ -25,13 +25,15 @@
             module = __import__(name)
             module.main()
 
-    import pdb; pdb.set_trace()
+    #import pdb; pdb.set_trace()
 
     stop = time.clock()
     took = str(stop - start)
     print 'Total Time: %s' % took
 
-
+    import gc
+    for i in gc.get_objects():
+        print i
 
 if __name__ == '__main__':
     main()


=== PythonNet/tests/python/test_event.py 1.4 => 1.5 ===
--- PythonNet/tests/python/test_event.py:1.4	Mon Oct 20 23:05:16 2003
+++ PythonNet/tests/python/test_event.py	Wed Oct 22 22:53:11 2003
@@ -29,6 +29,8 @@
         object.PublicEvent(object, TestEventArgs(10))
         self.failUnless(handler.value == 10)
 
+        object.PublicEvent -= handler.handler
+
 
     def testPublicStaticEvent(self):
         """Test public static events."""
@@ -53,6 +55,8 @@
         object.ProtectedEvent(object, TestEventArgs(10))
         self.failUnless(handler.value == 10)
 
+        object.ProtectedEvent -= handler.handler
+
 
     def testProtectedStaticEvent(self):
         """Test protected static events."""
@@ -66,6 +70,8 @@
         EventTest.ProtectedStaticEvent(None, TestEventArgs(10))
         self.failUnless(handler.value == 10)
 
+        EventTest.ProtectedStaticEvent -= handler.handler
+
 
     def testInternalEvents(self):
         """Test internal events."""
@@ -129,6 +135,10 @@
         self.failUnless(handler2.value == 20)
         self.failUnless(handler3.value == 20)
 
+        object.PublicEvent -= handler1.handler
+        object.PublicEvent -= handler2.handler
+        object.PublicEvent -= handler3.handler
+
 
     def testConditionalFireEvent(self):
         """Test conditional firing of events."""
@@ -137,10 +147,13 @@
         self.failIf(object.PublicEvent)
 
         handler = GenericHandler()
+        
         object.PublicEvent += handler.handler
 
         self.failUnless(object.PublicEvent)
 
+        object.PublicEvent -= handler.handler
+
 
     def testIndirectFireEvent(self):
         """Test indirect firing of events."""
@@ -154,6 +167,8 @@
         object.FireEvent(TestEventArgs(10))
         self.failUnless(handler.value == 10)
 
+        object.PublicEvent -= handler.handler
+        
         object = EventTest
 
         handler = GenericHandler()
@@ -164,6 +179,8 @@
         object.FireStatic(TestEventArgs(10))
         self.failUnless(handler.value == 10)
 
+        object.PublicStaticEvent -= handler.handler
+        
 
     def testFireEmptyEvent(self):
         """Test behavior of invoking an event with no subscribers."""
@@ -189,6 +206,8 @@
         if not object.PublicEvent:
             raise ValueError, 'Event descriptor should evaluate true'
 
+        object.PublicEvent -= handler.handler
+
 
     def testInstanceMethodHandler(self):
         """Test instance method handlers."""
@@ -411,26 +430,32 @@
             def handler(self, one):
                 return 'too many'
 
+        object = EventTest()
+        handler = BadHandler()
+
         def test():
-            object = EventTest()
-            handler = BadHandler()
             object.PublicEvent += handler.handler
-            object.PublicEvent(object, TestEventArgs(10))        
+            object.PublicEvent(object, TestEventArgs(10))
 
         self.failUnlessRaises(TypeError, test)
 
+        object.PublicEvent -= handler.handler
+
         class BadHandler:
             def handler(self, one, two, three, four, five):
                 return 'not enough'
 
+        object = EventTest()
+        handler = BadHandler()
+
         def test():
-            object = EventTest()
-            handler = BadHandler()
             object.PublicEvent += handler.handler
-            object.PublicEvent(object, TestEventArgs(10))        
+            object.PublicEvent(object, TestEventArgs(10))
 
         self.failUnlessRaises(TypeError, test)
 
+        object.PublicEvent -= handler.handler
+
 
     def testIncorrectInvokation(self):
         """Test incorrect invokation of events."""
@@ -449,6 +474,8 @@
 
         self.failUnlessRaises(TypeError, test)
 
+        object.PublicEvent -= handler.handler
+
 
     def testExplicitCLSEventRegistration(self):
         """Test explicit CLS event registration."""
@@ -482,6 +509,17 @@
 
     def testEventDescriptorAbuse(self):
         """Test event descriptor abuse."""
+
+        def test():
+            del EventTest.PublicEvent
+
+        self.failUnlessRaises(TypeError, test)
+
+        def test():
+            del EventTest.__dict__['PublicEvent']
+
+        self.failUnlessRaises(TypeError, test)
+
         desc = EventTest.__dict__['PublicEvent']
 
         def test():


=== PythonNet/tests/python/test_module.py 1.3 => 1.4 ===
--- PythonNet/tests/python/test_module.py:1.3	Mon Oct 20 23:05:16 2003
+++ PythonNet/tests/python/test_module.py	Wed Oct 22 22:53:11 2003
@@ -27,7 +27,7 @@
         """Test the interface exposed by CLR module objects."""
         import CLR.System as System
 
-        self.assertEquals(type(System.__dict__), types.DictProxyType)
+        self.assertEquals(type(System.__dict__), type({}))
         self.assertEquals(System.__name__, 'CLR.System')
         self.assertEquals(System.__doc__, None)
         self.failUnless(self.isCLRClass(System.String))
@@ -263,47 +263,17 @@
 
     def testModuleAttrAbuse(self):
         """Test handling of attempts to set module attributes."""
-        def test():
-            import CLR.System
-            CLR.System.__dict__['foo'] = 0
-
-        self.failUnlessRaises(TypeError, test)
-
-        def test():
-            import CLR.System
-            del CLR.System.__dict__['String']
-
-        self.failUnlessRaises(TypeError, test)
-
-        def test():
-            import CLR.System
-            del CLR.System.__dict__
-
-        self.failUnlessRaises(TypeError, test)
-
-        def test():
-            import CLR.System
-            CLR.System.Int32 = 0
-
-        self.failUnlessRaises(TypeError, test)
 
+        # It would be safer to use a dict-proxy as the __dict__ for CLR
+        # modules, but as of Python 2.3 some parts of the CPython runtime
+        # like dir() will fail if a module dict is not a real dictionary.
+        
         def test():
             import CLR.System
-            del CLR.System.Int32
-
-        self.failUnlessRaises(TypeError, test)
-
-        def test():
-            import CLR
-            CLR.LoadAssembly = None
-
-        self.failUnlessRaises(TypeError, test)
-
-        def test():
-            import CLR
-            del CLR.LoadAssembly
+            CLR.System.__dict__['foo'] = 0
+            return 1
 
-        self.failUnlessRaises(TypeError, test)
+        self.failUnless(test())
 
 
     def testModuleTypeAbuse(self):




More information about the Zope-CVS mailing list