[Zope3-checkins] CVS: Zope3/lib/python/Zope/App/OFS/Introspector/tests - TestClass.py:1.2 testIntrospector.py:1.4

Gary Poster gary@zope.com
Thu, 19 Dec 2002 13:25:39 -0500


Update of /cvs-repository/Zope3/lib/python/Zope/App/OFS/Introspector/tests
In directory cvs.zope.org:/tmp/cvs-serv8982/tests

Modified Files:
	testIntrospector.py 
Added Files:
	TestClass.py 
Log Message:
Cleaned up merge of Introspector work in Bangalore branch.  will not be hooked up until the OFS configure.zcml is also committed: I'm going to test my commit before I do so.

When this is hooked up, it will add an Introspector action in the UI.

This html was broken in the Rotterdam skin; fixed and significantly cleaned up.

A lot of DOS line endings were removed.  dos2unix reports that all is well now.

Commented-out code in the view refers to an IConfigureFor interface that goes in a direction that Jim eventually wants.  I am not merging in the necessary code elsewhere (in the services) that this code needs, so therefore I comment it out but do not delete it.

Introspector tab will be available to anonymous user, as it was in the branch.  If we don't like this, we can just fix the zcml.




=== Zope3/lib/python/Zope/App/OFS/Introspector/tests/TestClass.py 1.1 => 1.2 ===
--- /dev/null	Thu Dec 19 13:25:39 2002
+++ Zope3/lib/python/Zope/App/OFS/Introspector/tests/TestClass.py	Thu Dec 19 13:25:37 2002
@@ -0,0 +1,48 @@
+##############################################################################
+#
+# 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.
+# 
+##############################################################################
+from Interface import Interface
+from Interface.Attribute import Attribute
+
+class ITestClass(Interface):
+    def drool():
+        """...drool..."""
+class BaseTestClass:
+    """This is stupid base class"""
+    pass
+
+class TestClass(BaseTestClass):
+    """This is my stupid doc string"""
+    __implements__ = ITestClass
+    def drool(self):
+        pass
+    
+class I(Interface):
+    """bah blah
+    """
+    
+class I2(I):
+    """eek
+    """
+    
+class I3(I, I2):
+    """This is dummy doc string"""
+    
+    testAttribute1 = Attribute("""This is a dummy attribute.""")
+    testAttribute2 = Attribute("""This is a dummy attribute.""")
+    
+    def one(param):
+        """method one"""
+
+    def two(param1, param2):
+        """method two"""
\ No newline at end of file


=== Zope3/lib/python/Zope/App/OFS/Introspector/tests/testIntrospector.py 1.3 => 1.4 ===
--- Zope3/lib/python/Zope/App/OFS/Introspector/tests/testIntrospector.py:1.3	Wed Jul 17 12:54:18 2002
+++ Zope3/lib/python/Zope/App/OFS/Introspector/tests/testIntrospector.py	Thu Dec 19 13:25:37 2002
@@ -17,47 +17,83 @@
 $Id$
 """
 
+from Interface import Interface
 from unittest import TestCase, TestSuite, main, makeSuite
-from Zope.Testing.CleanUp import CleanUp # Base class w registry cleanup
-
+from Zope.Testing.CleanUp import CleanUp
 from Zope.App.OFS.Introspector.Introspector import Introspector
-
-from Interface import Interface
-from Interface.Implements import implements
-
-class IStupid(Interface):
-    
-    def drool():
-        """...drool..."""
-
-class Stupid:
-    """This is my stupid doc string"""
-    def drool(self):
-        pass
-
-implements(Stupid, IStupid)
+from TestClass import TestClass, ITestClass, BaseTestClass, I, I2, I3
 
 class Test(CleanUp, TestCase):
-    
-    def testDocString(self):
-        intro=Introspector(Stupid())
-        assert intro.getDocString()=="This is my stupid doc string"
+    """Test Introspector.
+    """
+   
+    def testIntrospector(self):
+        """Testing introspector"""
         
-    def testGetInterfaces(self):
-        intro=Introspector(Stupid()).getInterfaces()
-        assert (len(intro)==1 and intro[0]==IStupid)
+        ints = Introspector(ITestClass)
+        self.assertEqual(ints.isInterface(), 1)
         
-    def testGetName(self):
-        nm=Introspector(Stupid()).getName()
-        assert nm=="Stupid"
-    
-    def testGetInterfaceNames(self):
-        iname =  Introspector(Stupid()).getInterfaceNames()[0].split(".")
-        i = __import__(iname[-2], globals(), locals(), iname[:-2])
-        assert i.IStupid==IStupid
+        ints = Introspector(TestClass())
+        self.assertEqual(ints.isInterface(), 0)
+        request = {}
+        ints.setRequest(request)
+        self.assertEqual(ints.getClass(), 'TestClass')
+        
+        ints = Introspector(TestClass)
+        self.assertEqual(ints.isInterface(), 0)
+        request['PATH_INFO'] = '++module++Zope.App.OFS.Introspector.tests.TestClass.TestClass'
+        ints.setRequest(request)
+        self.assertEqual(ints.getClass(), 'TestClass')
+        self.assertEqual(
+            ints.getBaseClassNames(),
+            ['Zope.App.OFS.Introspector.tests.TestClass.BaseTestClass'])
+        self.assertEqual(
+            ints.getModule(),
+            'Zope.App.OFS.Introspector.tests.TestClass')
+        self.assertEqual(ints.getDocString(), "This is my stupid doc string")
+        self.assertEqual(ints.getInterfaces(), (ITestClass,))
+        self.assertEqual(
+            ints.getInterfaceNames(),
+            ['Zope.App.OFS.Introspector.tests.TestClass.ITestClass'])
+        self.assertEqual(ints.getExtends(), (BaseTestClass,))
+
+        ints = Introspector(I3)
+        self.assertEqual(ints.isInterface(), 1)
+        request['PATH_INFO'] = '++module++Zope.App.OFS.Introspector.tests.TestClass.I3'
+        ints.setRequest(request)
+        self.assertEqual(
+            ints.getModule(),
+            'Zope.App.OFS.Introspector.tests.TestClass')
+        self.assertEqual(ints.getExtends(), (I, I2, ))
+        self.assertEqual(
+            ints.getDocString(),
+            "This is dummy doc string")
+        Iname = 'I3'
+        bases = ['Zope.App.OFS.Introspector.tests.TestClass.I',
+                 'Zope.App.OFS.Introspector.tests.TestClass.I2']
+        desc = 'This is dummy doc string'
+        m1_name = 'one'
+        m1_signature = '(param)'
+        m1_desc = 'method one'
+        m2_name = 'two'
+        m2_signature = '(param1, param2)'
+        m2_desc = 'method two'
+        methods = [(m1_name, m1_signature, m1_desc),
+                   (m2_name, m2_signature, m2_desc),]
+        attr_name1 = 'testAttribute1'
+        attr_desc1 = 'This is a dummy attribute.'
+        attr_name2 = 'testAttribute2'
+        attr_desc2 = 'This is a dummy attribute.'
+        attributes = [(attr_name1, attr_desc1),
+                      (attr_name2, attr_desc2), ]
+        details = [Iname, bases, desc, methods, attributes]
+        self.assertEqual(ints.getInterfaceDetails(), details)
+ 
 
+        
 def test_suite():
-    return makeSuite(Test)
+    return TestSuite((makeSuite(Test),))
 
 if __name__=='__main__':
     main(defaultTest='test_suite')
+