def test_inside_function_call(self): from zope.interface.advice import getFrameInfo kind, module, f_locals, f_globals = getFrameInfo(sys._getframe()) self.assertEqual(kind, "function call") self.assertTrue(f_locals is locals()) # ??? for d in module.__dict__, f_globals: self.assertTrue(d is globals())
def _update_info(name,attr,data): from zope.interface.advice import getFrameInfo, addClassAdvisor kind, module, _locals, _globals = getFrameInfo(sys._getframe(2)) if kind=='exec': # Fix for class-in-doctest-exec if '__module__' in _locals and _locals is not _globals: kind="class" if kind != "class": raise SyntaxError( name+"() must be called in the body of a class statement" ) info = _locals.setdefault(attr,{}) for k,v in data.items(): if k in info: raise ValueError("%r defined multiple times for this class" % (k,)) info[k] = v
class NewStyleClass: __metaclass__ = type classLevelFrameInfo = getFrameInfo(sys._getframe())
class ClassicClass: __metaclass__ = ClassType classLevelFrameInfo = getFrameInfo(sys._getframe())
from zope.interface.advice import addClassAdvisor from zope.interface.advice import getFrameInfo my_globals = globals() def ping(log, value): def pong(klass): log.append((value, klass)) return [klass] addClassAdvisor(pong) try: from types import ClassType class ClassicClass: __metaclass__ = ClassType classLevelFrameInfo = getFrameInfo(sys._getframe()) except ImportError: ClassicClass = None class NewStyleClass: __metaclass__ = type classLevelFrameInfo = getFrameInfo(sys._getframe()) moduleLevelFrameInfo = getFrameInfo(sys._getframe())
############################################################################## import sys from zope.interface.advice import addClassAdvisor from zope.interface.advice import getFrameInfo my_globals = globals() def ping(log, value): def pong(klass): log.append((value,klass)) return [klass] addClassAdvisor(pong) try: from types import ClassType class ClassicClass: __metaclass__ = ClassType classLevelFrameInfo = getFrameInfo(sys._getframe()) except ImportError: ClassicClass = None class NewStyleClass: __metaclass__ = type classLevelFrameInfo = getFrameInfo(sys._getframe()) moduleLevelFrameInfo = getFrameInfo(sys._getframe())
def checkCallInfo(self): kind, module, f_locals, f_globals = getFrameInfo(sys._getframe()) self.assertEquals(kind, "function call") self.assert_(f_locals is locals()) # ??? for d in module.__dict__, f_globals: self.assert_(d is globals())