def testFormatedFunctionName(self): self.assertEqual('simple(a, b)', reflect.formatted_function_name(simple)) self.assertEqual('defaults(a, b=3)', reflect.formatted_function_name(defaults)) self.assertEqual('varargs(a, b=None, *args)', reflect.formatted_function_name(varargs)) self.assertEqual('kwargs(a=None, b=3, *args, **kwargs)', reflect.formatted_function_name(kwargs))
def help(self): '''Prints exposed methods and their docstrings.''' cmds = self.get_exposed_cmds() t = text_helper.Table(fields=['command', 'doc'], lengths=[50, 85]) return t.render((reflect.formatted_function_name(x), x.__doc__, ) for x in cmds.values())
def _append_function_call(self, parent, function, args, kwargs, result): args = args and list(args) or list() kwargs = kwargs or dict() argspec = inspect.getargspec(function) defaults = argspec.defaults and list(argspec.defaults) text = reflect.formatted_function_name(function) call_row = self._append_row(parent, 'call', text) row = self._append_row(call_row, 'input', None) for arg in argspec.args: value = None try: value = args.pop(0) except IndexError: value = defaults and defaults.pop(0) self._append_row(row, arg, repr(value)) if args: self._render_list(row, args) self._render_dict(row, kwargs) self._append_row(call_row, 'output', pprint.pformat(result))