def test_setRequest(self): ints = Introspector(Interface) request = {'PATH_INFO': '++module++zope.app.introspector.Introspector'} zope.deprecation.__show__.off() ints.setRequest(request) zope.deprecation.__show__.on() self.assertEqual(ints.currentclass, Introspector)
def test_getDirectlyProvided(self): ob = TestClass() ints = Introspector(ob) self.assertEqual(tuple(ints.getDirectlyProvided()), ()) directlyProvides(ob, I, I2) ints = Introspector(ob) self.assertEqual(tuple(ints.getDirectlyProvided()), (I, I2))
def test_getMarkerInterfaceNames(self): ints = Introspector(Content()) expected = ['zope.app.introspector.tests.test_introspector.M1', 'zope.app.introspector.tests.test_introspector.M2', 'zope.app.introspector.tests.test_introspector.M3'] expected.sort() self.assertEqual(ints.getMarkerInterfaceNames(), tuple(expected))
def test_getDirectlyProvidedNames(self): ob = TestClass() ints = Introspector(ob) self.assertEqual(tuple(ints.getDirectlyProvidedNames()), ()) directlyProvides(ob, I, I2) ints = Introspector(ob) self.assertEqual(tuple(ints.getDirectlyProvidedNames()), ('zope.app.introspector.tests.test_introspector.I', 'zope.app.introspector.tests.test_introspector.I2'))
def testIntrospectorOnInterface(self): request = {} ints = Introspector(I3) self.assertEqual(ints.isInterface(), 1) request['PATH_INFO'] = ( '++module++zope.app.introspector.tests.test_introspector.I3') ints.setRequest(request) self.assertEqual( ints.getModule(), 'zope.app.introspector.tests.test_introspector') self.assertEqual(ints.getExtends(), (I, I2, )) self.assertEqual( ints.getDocString(), "This is dummy doc string") Iname = 'I3' bases = ['zope.app.introspector.tests.test_introspector.I', 'zope.app.introspector.tests.test_introspector.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_isInterface(self): ints = Introspector(ITestClass) self.assertEqual(ints.isInterface(), 1) ints = Introspector(TestClass()) self.assertEqual(ints.isInterface(), 0) ints = Introspector(WeirdClass()) self.assertEqual(ints.isInterface(), 0) verifyObject(IIntrospector, ints)
def test_getDirectMarkers(self): ints = Introspector(Content()) self.assertEqual(ints.getDirectMarkersOf(I3), (M3,))
def test_getMarkerInterfaces(self): ints = Introspector(Content()) expected = [M1, M2, M3] expected.sort() self.assertEqual(ints.getMarkerInterfaces(), tuple(expected))
def testIntrospectorOnClass(self): request = {} ints = Introspector(TestClass) self.assertEqual(ints.isInterface(), 0) request['PATH_INFO'] = ( '++module++zope.app.tests.test_introspector.TestClass') ints.setRequest(request) self.assertEqual(ints.getClass(), 'TestClass') self.assertEqual( ints.getBaseClassNames(), ['zope.app.introspector.tests.test_introspector.BaseTestClass']) self.assertEqual( ints.getModule(), 'zope.app.introspector.tests.test_introspector') self.assertEqual(ints.getDocString(), "This is my stupid doc string") self.assertEqual(ints.getInterfaces(), (ITestClass,)) self.assertEqual( ints.getInterfaceNames(), ['zope.app.introspector.tests.test_introspector.ITestClass']) self.assertEqual(ints.getExtends(), (BaseTestClass,))
def test_getClass(self): ints = Introspector(TestClass()) request = {} ints.setRequest(request) self.assertEqual(ints.getClass(), 'TestClass')