def testGenerator(self): def returner(): return (str(x) for x in range(10)) # get the generator code object genCode = returner.func_code.co_consts[1] # FIXME: this is what co_varnames looks like, but I don't understand why # possible clue in Python, Lib/compiler/ast.py, class GenExpr if utils.pythonVersion() < utils.PYTHON_2_5: self.assertEquals(genCode.co_varnames, ('[outmost-iterable]', 'x')) else: self.assertEquals(genCode.co_varnames, ('.0', 'x')) # wrap it into a Funtion so we can look at it f = function.Function( function.FakeFunction(genCode.co_name, genCode)) self.failIf(f.isMethod) self.assertEquals(f.minArgs, 1) self.assertEquals(f.maxArgs, 1) if utils.pythonVersion() < utils.PYTHON_2_5: self.assertEquals(f.arguments(), ('[outmost-iterable]', )) else: self.assertEquals(f.arguments(), ('.0', ))
def addFunction(self, func, alias): """ @type func: callable @param alias: the name of the token in the module; for example _ = gettext.gettext will have alias _ @type alias: str """ self.functions[alias] = function.Function(func)
def addMethod(self, methodName, method=None): """ Add the given method to this class by name. @type methodName: str @type method: method or None """ if not method: self.methods[methodName] = None else: self.methods[methodName] = function.Function(method, 1)
def addMethod(self, methodName, method=None): """ Add the given method to this class by name. The name is the real name of the method, not an alias; ie the name of the method as defined in the code. @type methodName: str @type method: method or None """ if not method: self.methods[methodName] = None else: assert method.func_name == methodName self.methods[methodName] = function.Function(method, 1)
def addFunction(self, func): self.functions[func.__name__] = function.Function(func)
def addMethod(self, method, methodName=None): if type(method) == types.StringType: self.methods[method] = None else: assert methodName is not None, "must supply methodName" self.methods[methodName] = function.Function(method, 1)
def addFunction(self, func): """ @type func: callable """ self.functions[func.__name__] = function.Function(func)