diff options
author | Chris McDonough <chrism@plope.com> | 2014-07-13 22:38:29 -0400 |
---|---|---|
committer | Chris McDonough <chrism@plope.com> | 2014-07-13 22:38:29 -0400 |
commit | 77698fbf35376bdd530493e5db262c256ebe87c4 (patch) | |
tree | fa99e3059abde6f3eca4ece4f1b0d31e548dab64 | |
parent | 769c151edcc0953313a57b3a2f1a93d898d869fb (diff) | |
download | waitress-77698fbf35376bdd530493e5db262c256ebe87c4.tar.gz |
- If an ``application`` value of ``None`` is supplied to the ``create_server``
constructor function, a ValueError is now raised eagerly instead of an error
occuring during runtime. See https://github.com/Pylons/waitress/pull/60
Closes #60
-rw-r--r-- | CHANGES.txt | 4 | ||||
-rw-r--r-- | waitress/server.py | 5 | ||||
-rw-r--r-- | waitress/tests/test_server.py | 14 |
3 files changed, 19 insertions, 4 deletions
diff --git a/CHANGES.txt b/CHANGES.txt index ae592be..6d5e7c1 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -16,6 +16,10 @@ Next release - Add a ``docs`` section to tox.ini that, when run, ensures docs can be built. +- If an ``application`` value of ``None`` is supplied to the ``create_server`` + constructor function, a ValueError is now raised eagerly instead of an error + occuring during runtime. See https://github.com/Pylons/waitress/pull/60 + 0.8.9 (2014-05-16) ------------------ diff --git a/waitress/server.py b/waitress/server.py index 4d3d91a..87338c8 100644 --- a/waitress/server.py +++ b/waitress/server.py @@ -36,6 +36,11 @@ def create_server(application, server = create_server(app) server.run() """ + if application is None: + raise ValueError( + 'The "app" passed to ``create_server`` was ``None``. You forgot ' + 'to return a WSGI app within your application.' + ) adj = Adjustments(**kw) if adj.unix_socket and hasattr(socket, 'AF_UNIX'): cls = UnixWSGIServer diff --git a/waitress/tests/test_server.py b/waitress/tests/test_server.py index 8b48e10..0ff8871 100644 --- a/waitress/tests/test_server.py +++ b/waitress/tests/test_server.py @@ -2,9 +2,11 @@ import errno import socket import unittest +dummy_app = object() + class TestWSGIServer(unittest.TestCase): - def _makeOne(self, application, host='127.0.0.1', port=0, + def _makeOne(self, application=dummy_app, host='127.0.0.1', port=0, _dispatcher=None, adj=None, map=None, _start=True, _sock=None, _server=None): from waitress.server import create_server @@ -18,7 +20,7 @@ class TestWSGIServer(unittest.TestCase): _sock=_sock) def _makeOneWithMap(self, adj=None, _start=True, host='127.0.0.1', - port=0, app=None): + port=0, app=dummy_app): sock = DummySock() task_dispatcher = DummyTaskDispatcher() map = {} @@ -32,13 +34,17 @@ class TestWSGIServer(unittest.TestCase): _start=_start, ) + def test_ctor_app_is_None(self): + self.assertRaises(ValueError, self._makeOneWithMap, app=None) + + def test_ctor_start_true(self): inst = self._makeOneWithMap(_start=True) self.assertEqual(inst.accepting, True) self.assertEqual(inst.socket.listened, 1024) def test_ctor_makes_dispatcher(self): - inst = self._makeOne(None, _start=False, map={}) + inst = self._makeOne(_start=False, map={}) self.assertEqual(inst.task_dispatcher.__class__.__name__, 'ThreadedTaskDispatcher') @@ -198,7 +204,7 @@ if hasattr(socket, 'AF_UNIX'): def _makeOne(self, _start=True, _sock=None): from waitress.server import create_server return create_server( - None, + dummy_app, map={}, _start=_start, _sock=_sock, |