def wrapper(): try: func() except Exception as e: message = str(e) if message != "Timeout": raise XFail(get_function_name(func)) else: raise Skipped("Timeout") raise XPass(get_function_name(func))
def debug_rl(*args, **kwargs): expr = args[0] result = rule(*args, **kwargs) if result != expr: file.write("Rule: %s\n" % get_function_name(rule)) file.write("In: %s\nOut: %s\n\n" % (expr, result)) return result
def debug_rl(*args, **kwargs): expr = args[0] result = rule(*args, **kwargs) if result != expr: file.write("Rule: %s\n" % get_function_name(rule)) file.write("In: %s\nOut: %s\n\n"%(expr, result)) return result
def test_debug(): from sympy.core.compatibility import StringIO file = StringIO() rl = debug(posdec, file) rl(5) log = file.getvalue() file.close() assert get_function_name(posdec) in log assert '5' in log assert '4' in log
def maketree(f, *args, **kw): global _debug_tmp global _debug_iter oldtmp = _debug_tmp _debug_tmp = [] _debug_iter += 1 def tree(subtrees): def indent(s, type=1): x = s.split("\n") r = "+-%s\n" % x[0] for a in x[1:]: if a == "": continue if type == 1: r += "| %s\n" % a else: r += " %s\n" % a return r if len(subtrees) == 0: return "" f = [] for a in subtrees[:-1]: f.append(indent(a)) f.append(indent(subtrees[-1], 2)) return ''.join(f) # If there is a bug and the algorithm enters an infinite loop, enable the # following lines. It will print the names and parameters of all major functions # that are called, *before* they are called #from sympy.core.compatibility import reduce #print("%s%s %s%s" % (_debug_iter, reduce(lambda x, y: x + y, \ # map(lambda x: '-', range(1, 2 + _debug_iter))), get_function_name(f), args)) r = f(*args, **kw) _debug_iter -= 1 s = "%s%s = %s\n" % (get_function_name(f), args, r) if _debug_tmp != []: s += tree(_debug_tmp) _debug_tmp = oldtmp _debug_tmp.append(s) if _debug_iter == 0: print((_debug_tmp[0])) _debug_tmp = [] return r
def public(obj): """ Append ``obj``'s name to global ``__all__`` variable (call site). By using this decorator on functions or classes you achieve the same goal as by filling ``__all__`` variables manually, you just don't have to repeat yourself (object's name). You also know if object is public at definition site, not at some random location (where ``__all__`` was set). Note that in multiple decorator setup (in almost all cases) ``@public`` decorator must be applied before any other decorators, because it relies on the pointer to object's global namespace. If you apply other decorators first, ``@public`` may end up modifying the wrong namespace. Examples ======== >>> from sympy.utilities.decorator import public >>> __all__ Traceback (most recent call last): ... NameError: name '__all__' is not defined >>> @public ... def some_function(): ... pass >>> __all__ ['some_function'] """ if isinstance(obj, types.FunctionType): ns = get_function_globals(obj) name = get_function_name(obj) elif isinstance(obj, (type(type), class_types)): ns = sys.modules[obj.__module__].__dict__ name = obj.__name__ else: raise TypeError("expected a function or a class, got %s" % obj) if "__all__" not in ns: ns["__all__"] = [name] else: ns["__all__"].append(name) return obj
def write(brl, expr, result): file.write("Rule: %s\n" % get_function_name(brl)) file.write("In: %s\nOut: %s\n\n" % (expr, result))