Skip to content

Commit

Permalink
Add a proper test for the --app flag and docs.
Browse files Browse the repository at this point in the history
  • Loading branch information
kgaughan committed Nov 24, 2024
1 parent c970e55 commit 109bf41
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 2 deletions.
12 changes: 11 additions & 1 deletion docs/runner.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ Is equivalent to::

waitress-serve --port=8041 --url-scheme=https myapp:wsgifunc

Or:

waitress-serve --port=8041 --url-scheme=https --app=myapp:wsgifunc

The full argument list is :ref:`given below <invocation>`.

Boolean arguments are represented by flags. If you wish to explicitly set a
Expand Down Expand Up @@ -64,13 +68,19 @@ Invocation

Usage::

waitress-serve [OPTS] MODULE:OBJECT
waitress-serve [OPTS] [MODULE:OBJECT]

Common options:

``--help``
Show this information.

``--app=MODULE:OBJECT``
Run the given callable object the WSGI application.

You can specify the WSGI application using this flag or as a positional
argument.

``--call``
Call the given object to get the WSGI application.

Expand Down
2 changes: 2 additions & 0 deletions src/waitress/adjustments.py
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,8 @@ def parse_args(cls, argv):
kw[param] = "false"
elif param in ("help", "call"):
kw[param] = True
elif param == "app":
kw[param] = value
elif cls._param_map[param] is asbool:
kw[param] = "true"
else:
Expand Down
8 changes: 7 additions & 1 deletion src/waitress/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,19 @@
HELP = """\
Usage:
{0} [OPTS] MODULE:OBJECT
{0} [OPTS] [MODULE:OBJECT]
Standard options:
--help
Show this information.
--app=MODULE:OBJECT
Run the given callable object the WSGI application.
You can specify the WSGI application using this flag or as a positional
argument.
--call
Call the given object to get the WSGI application.
Expand Down
10 changes: 10 additions & 0 deletions tests/test_adjustments.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,16 @@ def test_both(self):
self.assertDictEqual(opts, {"call": True, "help": True, "app": None})
self.assertSequenceEqual(args, [])

def test_app_flag(self):
opts, args = self.parse(["--app=fred:wilma", "barney:betty"])
self.assertEqual(opts["app"], "fred:wilma")
self.assertSequenceEqual(args, ["barney:betty"])

def test_app_arg(self):
opts, args = self.parse(["barney:betty"])
self.assertEqual(opts["app"], "barney:betty")
self.assertSequenceEqual(args, [])

def test_positive_boolean(self):
opts, args = self.parse(["--expose-tracebacks"])
self.assertDictContainsSubset({"expose_tracebacks": "true"}, opts)
Expand Down

0 comments on commit 109bf41

Please sign in to comment.