Merge pull request #81 from ryanpetrello/next

Slight tweak to DebugMiddleware, and a fix for a test broken in Python 2.6
This commit is contained in:
Ryan Petrello
2012-03-17 13:01:29 -07:00
3 changed files with 30 additions and 2 deletions

View File

@@ -121,6 +121,9 @@ class DebugMiddleware(object):
self.app = app
def __call__(self, environ, start_response):
assert not environ['wsgi.multiprocess'], (
"The EvalException middleware is not usable in a "
"multi-process environment")
try:
return self.app(environ, start_response)
except:

View File

@@ -26,8 +26,11 @@ class TestCommandRunner(unittest.TestCase):
def test_run(self):
from pecan.commands import CommandRunner
runner = CommandRunner()
with self.assertRaises(RuntimeError):
runner.run(['serve', 'missing_file.py'])
self.assertRaises(
RuntimeError,
runner.run,
['serve', 'missing_file.py']
)
class TestCreateCommand(unittest.TestCase):

View File

@@ -23,3 +23,25 @@ class TestDebugMiddleware(TestCase):
r = self.app.get('/error', expect_errors=True)
assert r.status_int == 400
assert 'AssertionError' in r.body
def test_middleware_complains_in_multi_process_environment(self):
class MultiProcessApp(object):
def __init__(self, app):
self.app = app
def __call__(self, environ, start_response):
environ['wsgi.multiprocess'] = True
return self.app(environ, start_response)
def conditional_error_app(environ, start_response):
start_response("200 OK", [('Content-type', 'text/plain')])
return ['Hello, World!']
app = TestApp(MultiProcessApp(DebugMiddleware(conditional_error_app)))
self.assertRaises(
AssertionError,
app.get,
'/'
)