def my_init(space, w_self, __args__): "Our new AssertionError.__init__()." w_parent_init = space.getattr(w_BuiltinAssertionError, space.wrap('__init__')) space.call_args(w_parent_init, __args__.prepend(w_self)) ## # Argh! we may see app-level helpers in the frame stack! ## # that's very probably very bad... ## ^^^the above comment may be outdated, but we are not sure # if the assertion provided a message, don't do magic args_w, kwargs_w = __args__.unpack() if args_w: w_msg = args_w[0] else: frame = space.getexecutioncontext().gettopframe() runner = AppFrame(space, frame) try: source = runner.statement source = str(source).strip() except py.error.ENOENT: source = None from pypy import conftest if source and py.test.config._assertstate.mode != "off": msg = interpret(source, runner, should_fail=True) space.setattr(w_self, space.wrap('args'), space.newtuple([space.wrap(msg)])) w_msg = space.wrap(msg) else: w_msg = space.w_None space.setattr(w_self, space.wrap('msg'), w_msg)
def my_init(space, w_self, __args__): "Our new AssertionError.__init__()." w_parent_init = space.getattr(w_BuiltinAssertionError, space.wrap('__init__')) space.call_args(w_parent_init, __args__.prepend(w_self)) ## # Argh! we may see app-level helpers in the frame stack! ## # that's very probably very bad... ## ^^^the above comment may be outdated, but we are not sure # if the assertion provided a message, don't do magic args_w, kwargs_w = __args__.unpack() if args_w: w_msg = args_w[0] else: frame = space.getexecutioncontext().gettopframe() runner = AppFrame(space, frame) try: source = runner.statement source = str(source).strip() except py.error.ENOENT: source = None from pypy import conftest if source and py.test.config._assertstate.mode != "off": msg = interpret(source, runner, should_fail=True) space.setattr(w_self, space.wrap('args'), space.newtuple([space.wrap(msg)])) w_msg = space.wrap(msg) else: w_msg = space.w_None space.setattr(w_self, space.wrap('msg'), w_msg)
def __init__(self, message, frame): Exception.__init__(self, message) # copied and adapted from pytest's magic AssertionError f = py.code.Frame(frame) try: source = f.code.fullsource if source is not None: try: source = source.getstatement(f.lineno) except IndexError: source = None else: source = str(source.deindent()).strip() except py.error.ENOENT: source = None if source and source.startswith('self._assert(') and newinterpret: # transform self._assert(x, 'foo') into assert x, 'foo' source = source.replace('self._assert(', 'assert ') source = source[:-1] # remove the trailing ')' self.msg = newinterpret.interpret(source, f, should_fail=True) else: self.msg = "<could not determine information>"
def __init__(self, message, frame): Exception.__init__(self, message) # copied and adapted from pytest's magic AssertionError f = py.code.Frame(frame) try: source = f.code.fullsource if source is not None: try: source = source.getstatement(f.lineno) except IndexError: source = None else: source = str(source.deindent()).strip() except py.error.ENOENT: source = None if source and source.startswith('self._assert(') and newinterpret: # transform self._assert(x, 'foo') into assert x, 'foo' source = source.replace('self._assert(', 'assert ') source = source[:-1] # remove the trailing ')' self.msg = newinterpret.interpret(source, f, should_fail=True) else: self.msg = "<could not determine information>"