Improve coverage of debug module
This commit is contained in:
@@ -4,6 +4,8 @@ debugging Eventlet-powered applications."""
|
||||
import os
|
||||
import sys
|
||||
import linecache
|
||||
import string
|
||||
import inspect
|
||||
|
||||
__all__ = ['spew', 'unspew', 'format_hub_listeners', 'hub_listener_stacks',
|
||||
'hub_exceptions', 'tpool_exceptions']
|
||||
@@ -122,4 +124,4 @@ def tpool_exceptions(state):
|
||||
functions that are executed in it, in addition to raising them like
|
||||
it normally does."""
|
||||
from eventlet import tpool
|
||||
tpool.QUIET = not state
|
||||
tpool.QUIET = not state
|
||||
|
||||
@@ -4,6 +4,7 @@ try:
|
||||
GreenletExit = greenlet.GreenletExit
|
||||
greenlet = greenlet.greenlet
|
||||
except ImportError, e:
|
||||
raise
|
||||
try:
|
||||
from py.magic import greenlet
|
||||
getcurrent = greenlet.getcurrent
|
||||
|
||||
@@ -4,12 +4,90 @@ import eventlet
|
||||
from eventlet import debug
|
||||
from eventlet import api
|
||||
from tests import LimitedTestCase, main
|
||||
from unittest import TestCase
|
||||
|
||||
try:
|
||||
from cStringIO import StringIO
|
||||
except ImportError:
|
||||
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):
|
||||
def test_everything(self):
|
||||
debug.hub_exceptions(True)
|
||||
@@ -18,7 +96,10 @@ class TestDebug(LimitedTestCase):
|
||||
debug.tpool_exceptions(False)
|
||||
debug.hub_listener_stacks(True)
|
||||
debug.hub_listener_stacks(False)
|
||||
debug.hub_timer_stacks(True)
|
||||
debug.hub_timer_stacks(False)
|
||||
debug.format_hub_listeners()
|
||||
debug.format_hub_timers()
|
||||
|
||||
def test_hub_exceptions(self):
|
||||
debug.hub_exceptions(True)
|
||||
@@ -46,4 +127,4 @@ class TestDebug(LimitedTestCase):
|
||||
"Traceback not in:\n" + fake.getvalue())
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user