Ejemplo n.º 1
0
    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 not conftest.option.nomagic: 
                msg = exprinfo.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)
Ejemplo n.º 2
0
 def __init__(self, *args):
     BuiltinAssertionError.__init__(self, *args)
     if args: 
         try:
             self.msg = str(args[0])
         except (KeyboardInterrupt, SystemExit):
             raise
         except:
             self.msg = "<[broken __repr__] %s at %0xd>" %(
                 args[0].__class__, id(args[0]))
         
     else: 
         f = sys._getframe(1)
         try:
             source = py.code.Frame(f).statement
             source = str(source.deindent()).strip()
         except py.error.ENOENT:
             source = None
             # this can also occur during reinterpretation, when the
             # co_filename is set to "<run>".
         if source:
             self.msg = exprinfo.interpret(source, f, should_fail=True)
             if not self.args:
                 self.args = (self.msg,)
         else:
             self.msg = None
Ejemplo n.º 3
0
    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 not conftest.option.nomagic:
                msg = exprinfo.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)
Ejemplo n.º 4
0
    def __init__(self, *args):
        BuiltinAssertionError.__init__(self, *args)
        if args:
            try:
                self.msg = str(args[0])
            except (KeyboardInterrupt, SystemExit):
                raise
            except:
                self.msg = "<[broken __repr__] %s at %0xd>" % (
                    args[0].__class__, id(args[0]))

        else:
            f = sys._getframe(1)
            try:
                source = py.code.Frame(f).statement
                source = str(source.deindent()).strip()
            except py.error.ENOENT:
                source = None
                # this can also occur during reinterpretation, when the
                # co_filename is set to "<run>".
            if source:
                self.msg = exprinfo.interpret(source, f, should_fail=True)
                if not self.args:
                    self.args = (self.msg, )
            else:
                self.msg = None
Ejemplo n.º 5
0
def test_AppFrame(space):
    import sys
    co = PyCode._from_code(space, somefunc.func_code)
    pyframe = PyFrame(space, co, space.newdict(), None)
    runner = AppFrame(space, pyframe)
    exprinfo.run("f = lambda x: x+1", runner)
    msg = exprinfo.interpret("assert isinstance(f(2), float)", runner)
    assert msg.startswith("assert isinstance(3, float)\n" " +  where 3 = ")
Ejemplo n.º 6
0
def test_AppFrame(space):
    import sys
    co = PyCode._from_code(space, somefunc.func_code)
    pyframe = PyFrame(space, co, space.newdict(), None)
    runner = AppFrame(space, pyframe)
    exprinfo.run("f = lambda x: x+1", runner)
    msg = exprinfo.interpret("assert isinstance(f(2), float)", runner)
    assert msg.startswith("assert isinstance(3, float)\n"
                          " +  where 3 = ")
Ejemplo n.º 7
0
 def reinterpret(self):
     """Reinterpret the failing statement and returns a detailed information
        about what operations are performed."""
     if self.exprinfo is None:
         from py.__.magic import exprinfo
         source = str(self.statement).strip()
         x = exprinfo.interpret(source, self.frame, should_fail=True)
         if not isinstance(x, str):
             raise TypeError, "interpret returned non-string %r" % (x,)
         self.exprinfo = x 
     return self.exprinfo
Ejemplo n.º 8
0
 def reinterpret(self):
     """Reinterpret the failing statement and returns a detailed information
        about what operations are performed."""
     if self.exprinfo is None:
         from py.__.magic import exprinfo
         source = str(self.statement).strip()
         x = exprinfo.interpret(source, self.frame, should_fail=True)
         if not isinstance(x, str):
             raise TypeError, "interpret returned non-string %r" % (x, )
         self.exprinfo = x
     return self.exprinfo
Ejemplo n.º 9
0
def test_keyboard_interrupt():
    # XXX this test is slightly strange because it is not
    # clear that "interpret" should execute "raise" statements
    # ... but it apparently currently does and it's nice to
    # exercise the code because the exprinfo-machinery is
    # not much executed when all tests pass ...

    class DummyCode:
        co_filename = 'dummy'
        co_firstlineno = 0
        co_name = 'dummy'
    class DummyFrame:
        f_globals = f_locals = {}
        f_code = DummyCode
        f_lineno = 0

    for exstr in "SystemExit", "KeyboardInterrupt", "MemoryError":
        ex = eval(exstr)
        try:
            interpret("raise %s" % exstr, py.code.Frame(DummyFrame))
        except ex:
            pass
        else:
            raise AssertionError, "ex %s didn't pass through" %(exstr, )
Ejemplo n.º 10
0
 def __init__(self, *args):
     BuiltinAssertionError.__init__(self, *args)
     if args: 
         self.msg = str(args[0])
     else: 
         f = sys._getframe(1)
         try:
             source = py.code.Frame(f).statement
             source = str(source.deindent()).strip()
         except py.error.ENOENT:
             source = None
             # this can also occur during reinterpretation, when the
             # co_filename is set to "<run>".
         if source:
             self.msg = exprinfo.interpret(source, f, should_fail=True)
             if not self.args:
                 self.args = (self.msg,)
         else:
             self.msg = None