Improve coverage of debug module
This commit is contained in:
@@ -4,6 +4,8 @@ debugging Eventlet-powered applications."""
|
|||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import linecache
|
import linecache
|
||||||
|
import string
|
||||||
|
import inspect
|
||||||
|
|
||||||
__all__ = ['spew', 'unspew', 'format_hub_listeners', 'hub_listener_stacks',
|
__all__ = ['spew', 'unspew', 'format_hub_listeners', 'hub_listener_stacks',
|
||||||
'hub_exceptions', 'tpool_exceptions']
|
'hub_exceptions', 'tpool_exceptions']
|
||||||
@@ -122,4 +124,4 @@ def tpool_exceptions(state):
|
|||||||
functions that are executed in it, in addition to raising them like
|
functions that are executed in it, in addition to raising them like
|
||||||
it normally does."""
|
it normally does."""
|
||||||
from eventlet import tpool
|
from eventlet import tpool
|
||||||
tpool.QUIET = not state
|
tpool.QUIET = not state
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ try:
|
|||||||
GreenletExit = greenlet.GreenletExit
|
GreenletExit = greenlet.GreenletExit
|
||||||
greenlet = greenlet.greenlet
|
greenlet = greenlet.greenlet
|
||||||
except ImportError, e:
|
except ImportError, e:
|
||||||
|
raise
|
||||||
try:
|
try:
|
||||||
from py.magic import greenlet
|
from py.magic import greenlet
|
||||||
getcurrent = greenlet.getcurrent
|
getcurrent = greenlet.getcurrent
|
||||||
|
|||||||
@@ -4,12 +4,90 @@ import eventlet
|
|||||||
from eventlet import debug
|
from eventlet import debug
|
||||||
from eventlet import api
|
from eventlet import api
|
||||||
from tests import LimitedTestCase, main
|
from tests import LimitedTestCase, main
|
||||||
|
from unittest import TestCase
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from cStringIO import StringIO
|
from cStringIO import StringIO
|
||||||
except ImportError:
|
except ImportError:
|
||||||
from StringIO import StringIO
|
from StringIO import StringIO
|
||||||
|
|
||||||
|
class TestSpew(TestCase):
|
||||||
|
def setUp(self):
|
||||||
|
self.orig_trace = sys.settrace
|
||||||
|
sys.settrace = self._settrace
|
||||||
|
self.tracer = None
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
sys.settrace = self.orig_trace
|
||||||
|
sys.stdout = sys.__stdout__
|
||||||
|
|
||||||
|
def _settrace(self, cb):
|
||||||
|
self.tracer = cb
|
||||||
|
|
||||||
|
def test_spew(self):
|
||||||
|
debug.spew()
|
||||||
|
self.failUnless(isinstance(self.tracer, debug.Spew))
|
||||||
|
|
||||||
|
def test_unspew(self):
|
||||||
|
debug.spew()
|
||||||
|
debug.unspew()
|
||||||
|
self.failUnlessEqual(self.tracer, None)
|
||||||
|
|
||||||
|
def test_line(self):
|
||||||
|
sys.stdout = 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("debug_test:%i" % lineno in output, "Didn't find line %i in %s" % (lineno, output))
|
||||||
|
self.failUnless("f=<frame object at" in output)
|
||||||
|
|
||||||
|
def test_line_nofile(self):
|
||||||
|
sys.stdout = StringIO()
|
||||||
|
s = debug.Spew()
|
||||||
|
g = globals().copy()
|
||||||
|
del g['__file__']
|
||||||
|
f = eval("sys._getframe()", g)
|
||||||
|
s(f, "line", None)
|
||||||
|
output = sys.stdout.getvalue()
|
||||||
|
self.failUnless("[unknown]:1" in output, "Didn't find [unknown]:1 in %s" % (output))
|
||||||
|
self.failUnless("VM instruction #" in output, output)
|
||||||
|
|
||||||
|
def test_line_global(self):
|
||||||
|
global GLOBAL_VAR
|
||||||
|
sys.stdout = 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()
|
||||||
|
self.failUnless("debug_test:%i" % lineno in output, "Didn't find line %i in %s" % (lineno, output))
|
||||||
|
self.failUnless("f=<frame object at" in output)
|
||||||
|
self.failUnless("GLOBAL_VAR" in f.f_globals)
|
||||||
|
self.failUnless("GLOBAL_VAR=<eventlet.debug.Spew object at" in output)
|
||||||
|
del GLOBAL_VAR
|
||||||
|
|
||||||
|
def test_line_novalue(self):
|
||||||
|
sys.stdout = 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()
|
||||||
|
self.failUnless("debug_test:%i" % lineno in output, "Didn't find line %i in %s" % (lineno, output))
|
||||||
|
self.failIf("f=<frame object at" in output)
|
||||||
|
|
||||||
|
def test_line_nooutput(self):
|
||||||
|
sys.stdout = StringIO()
|
||||||
|
s = debug.Spew(trace_names=['foo'])
|
||||||
|
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.failUnlessEqual(output, "")
|
||||||
|
|
||||||
|
|
||||||
class TestDebug(LimitedTestCase):
|
class TestDebug(LimitedTestCase):
|
||||||
def test_everything(self):
|
def test_everything(self):
|
||||||
debug.hub_exceptions(True)
|
debug.hub_exceptions(True)
|
||||||
@@ -18,7 +96,10 @@ class TestDebug(LimitedTestCase):
|
|||||||
debug.tpool_exceptions(False)
|
debug.tpool_exceptions(False)
|
||||||
debug.hub_listener_stacks(True)
|
debug.hub_listener_stacks(True)
|
||||||
debug.hub_listener_stacks(False)
|
debug.hub_listener_stacks(False)
|
||||||
|
debug.hub_timer_stacks(True)
|
||||||
|
debug.hub_timer_stacks(False)
|
||||||
debug.format_hub_listeners()
|
debug.format_hub_listeners()
|
||||||
|
debug.format_hub_timers()
|
||||||
|
|
||||||
def test_hub_exceptions(self):
|
def test_hub_exceptions(self):
|
||||||
debug.hub_exceptions(True)
|
debug.hub_exceptions(True)
|
||||||
@@ -46,4 +127,4 @@ class TestDebug(LimitedTestCase):
|
|||||||
"Traceback not in:\n" + fake.getvalue())
|
"Traceback not in:\n" + fake.getvalue())
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|||||||
Reference in New Issue
Block a user