Skip to content

Commit

Permalink
- If an application value of None is supplied to the ``create…
Browse files Browse the repository at this point in the history
…_server``

  constructor function, a ValueError is now raised eagerly instead of an error
  occuring during runtime.  See #60

Closes #60
  • Loading branch information
mcdonc committed Jul 14, 2014
1 parent 769c151 commit 77698fb
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
------------------

Expand Down
5 changes: 5 additions & 0 deletions waitress/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 10 additions & 4 deletions waitress/tests/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
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
Expand All @@ -18,7 +20,7 @@ def _makeOne(self, application, host='127.0.0.1', port=0,
_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 = {}
Expand All @@ -32,13 +34,17 @@ def _makeOneWithMap(self, adj=None, _start=True, host='127.0.0.1',
_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')

Expand Down Expand Up @@ -198,7 +204,7 @@ class TestUnixWSGIServer(unittest.TestCase):
def _makeOne(self, _start=True, _sock=None):
from waitress.server import create_server
return create_server(
None,
dummy_app,
map={},
_start=_start,
_sock=_sock,
Expand Down

0 comments on commit 77698fb

Please sign in to comment.