예제 #1
0
 def test_line_nooutput(self):
     sys.stdout = six.StringIO()
     s = debug.Spew(trace_names=['foo'])
     f = sys._getframe()
     s(f, "line", None)
     output = sys.stdout.getvalue()
     assert output == ""
예제 #2
0
    def test_hub_exceptions(self):
        debug.hub_exceptions(True)
        server = eventlet.listen(('0.0.0.0', 0))
        client = eventlet.connect(('127.0.0.1', server.getsockname()[1]))
        client_2, addr = server.accept()

        def hurl(s):
            s.recv(1)
            {}[1]  # keyerror

        fake = six.StringIO()
        orig = sys.stderr
        sys.stderr = fake
        try:
            gt = eventlet.spawn(hurl, client_2)
            eventlet.sleep(0)
            client.send(b' ')
            eventlet.sleep(0)
            # allow the "hurl" greenlet to trigger the KeyError
            # not sure why the extra context switch is needed
            eventlet.sleep(0)
        finally:
            sys.stderr = orig
            self.assertRaises(KeyError, gt.wait)
            debug.hub_exceptions(False)
        # look for the KeyError exception in the traceback
        self.assert_('KeyError: 1' in fake.getvalue(),
                     "Traceback not in:\n" + fake.getvalue())
예제 #3
0
 def test_line_nooutput(self):
     sys.stdout = six.StringIO()
     s = debug.Spew(trace_names=['foo'])
     f = sys._getframe()
     s(f, "line", None)
     output = sys.stdout.getvalue()
     self.failUnlessEqual(output, "")
예제 #4
0
def capture_stderr():
    stream = six.StringIO()
    original = sys.stderr
    try:
        sys.stderr = stream
        yield stream
    finally:
        sys.stderr = original
        stream.seek(0)
예제 #5
0
 def test_line_novalue(self):
     sys.stdout = six.StringIO()
     s = debug.Spew(show_values=False)
     f = sys._getframe()
     s(f, "line", None)
     lineno = f.f_lineno - 1  # -1 here since we called with frame f in the line above
     output = sys.stdout.getvalue()
     assert "%s:%i" % (__name__, lineno) in output, "Didn't find line %i in %s" % (lineno, output)
     assert "f=<frame object at" not in output
예제 #6
0
 def test_line(self):
     sys.stdout = six.StringIO()
     s = debug.Spew()
     f = sys._getframe()
     s(f, "line", None)
     lineno = f.f_lineno - 1  # -1 here since we called with frame f in the line above
     output = sys.stdout.getvalue()
     self.failUnless("%s:%i" % (__name__, lineno) in output,
                     "Didn't find line %i in %s" % (lineno, output))
     self.failUnless("f=<frame object at" in output)
예제 #7
0
 def test_line_nofile(self):
     sys.stdout = six.StringIO()
     s = debug.Spew()
     g = globals().copy()
     del g['__file__']
     f = eval("sys._getframe()", g)
     lineno = f.f_lineno
     s(f, "line", None)
     output = sys.stdout.getvalue()
     assert "[unknown]:%i" % lineno in output, "Didn't find [unknown]:%i in %s" % (lineno, output)
     assert "VM instruction #" in output, output
예제 #8
0
 def test_line_global(self):
     global GLOBAL_VAR
     sys.stdout = six.StringIO()
     GLOBAL_VAR = debug.Spew()
     f = sys._getframe()
     GLOBAL_VAR(f, "line", None)
     lineno = f.f_lineno - 1  # -1 here since we called with frame f in the line above
     output = sys.stdout.getvalue()
     assert "%s:%i" % (__name__, lineno) in output, "Didn't find line %i in %s" % (lineno, output)
     assert "f=<frame object at" in output
     assert "GLOBAL_VAR" in f.f_globals
     assert "GLOBAL_VAR=<eventlet.debug.Spew object at" in output
     del GLOBAL_VAR
예제 #9
0
    def __init__(self, seconds, cb, *args, **kw):
        """Create a timer.
            seconds: The minimum number of seconds to wait before calling
            cb: The callback to call when the timer has expired
            *args: The arguments to pass to cb
            **kw: The keyword arguments to pass to cb

        This timer will not be run unless it is scheduled in a runloop by
        calling timer.schedule() or runloop.add_timer(timer).
        """
        self.seconds = seconds
        self.tpl = cb, args, kw
        self.called = False
        if _g_debug:
            self.traceback = six.StringIO()
            traceback.print_stack(file=self.traceback)