Skip to content

Commit

Permalink
Fix command line arg parsing; issue aio-libs#797
Browse files Browse the repository at this point in the history
  • Loading branch information
jashandeep-sohi committed Feb 22, 2016
1 parent e3e1369 commit 86d1934
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion aiohttp/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ def main(argv):
type=int,
default="8080"
)
args, extra_args = arg_parser.parse_known_args(argv)
args, extra_args = arg_parser.parse_known_args(argv[1:])

# Import logic
mod_str, _, func_str = args.entry_func.partition(":")
Expand Down
2 changes: 1 addition & 1 deletion docs/web.rst
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Command Line Interface (CLI)
:mod:`aiohttp.web` implements a basic CLI for quickly serving an
:class:`Application` in *development* over TCP/IP::

$ python -m aiohttp.web -H localhost -P 8080 package.module.init_func
$ python -m aiohttp.web -H localhost -P 8080 package.module:init_func

``package.module.init_func`` should be an importable :term:`callable` that
accepts a list of any non-parsed command-line arguments and returns an
Expand Down
2 changes: 1 addition & 1 deletion examples/web_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Serve this app using::
$ python -m aiohttp.web -H localhost -P 8080 --repeat 10 web_app.init \
$ python -m aiohttp.web -H localhost -P 8080 --repeat 10 web_app:init \
> "Hello World"
Here ``--repeat`` & ``"Hello World"`` are application specific command-line
Expand Down
18 changes: 9 additions & 9 deletions tests/test_web_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

@mock.patch("aiohttp.web.ArgumentParser.error", side_effect=SystemExit)
def test_entry_func_empty(error):
argv = [""]
argv = ["web.py", ""]

with pytest.raises(SystemExit):
web.main(argv)
Expand All @@ -19,7 +19,7 @@ def test_entry_func_empty(error):

@mock.patch("aiohttp.web.ArgumentParser.error", side_effect=SystemExit)
def test_entry_func_only_module(error):
argv = ["test"]
argv = ["web.py", "test"]

with pytest.raises(SystemExit):
web.main(argv)
Expand All @@ -31,7 +31,7 @@ def test_entry_func_only_module(error):

@mock.patch("aiohttp.web.ArgumentParser.error", side_effect=SystemExit)
def test_entry_func_only_function(error):
argv = [":test"]
argv = ["web.py", ":test"]

with pytest.raises(SystemExit):
web.main(argv)
Expand All @@ -43,7 +43,7 @@ def test_entry_func_only_function(error):

@mock.patch("aiohttp.web.ArgumentParser.error", side_effect=SystemExit)
def test_entry_func_only_seperator(error):
argv = [":"]
argv = ["web.py", ":"]

with pytest.raises(SystemExit):
web.main(argv)
Expand All @@ -55,7 +55,7 @@ def test_entry_func_only_seperator(error):

@mock.patch("aiohttp.web.ArgumentParser.error", side_effect=SystemExit)
def test_entry_func_relative_module(error):
argv = [".a.b:c"]
argv = ["web.py", ".a.b:c"]

with pytest.raises(SystemExit):
web.main(argv)
Expand All @@ -66,7 +66,7 @@ def test_entry_func_relative_module(error):
@mock.patch("aiohttp.web.import_module", side_effect=ImportError)
@mock.patch("aiohttp.web.ArgumentParser.error", side_effect=SystemExit)
def test_entry_func_non_existent_module(error, import_module):
argv = ["alpha.beta:func"]
argv = ["web.py", "alpha.beta:func"]

with pytest.raises(SystemExit):
web.main(argv)
Expand All @@ -77,7 +77,7 @@ def test_entry_func_non_existent_module(error, import_module):
@mock.patch("aiohttp.web.import_module")
@mock.patch("aiohttp.web.ArgumentParser.error", side_effect=SystemExit)
def test_entry_func_non_existent_attribute(error, import_module):
argv = ["alpha.beta:func"]
argv = ["web.py", "alpha.beta:func"]
module = import_module("alpha.beta")
del module.func

Expand All @@ -92,7 +92,7 @@ def test_entry_func_non_existent_attribute(error, import_module):
@mock.patch("aiohttp.web.run_app")
@mock.patch("aiohttp.web.import_module")
def test_entry_func_call(import_module, run_app):
argv = ("-H testhost -P 6666 --extra-optional-eins alpha.beta:func "
argv = ("web.py -H testhost -P 6666 --extra-optional-eins alpha.beta:func "
"--extra-optional-zwei extra positional args").split()
module = import_module("alpha.beta")

Expand All @@ -109,7 +109,7 @@ def test_entry_func_call(import_module, run_app):
@mock.patch("aiohttp.web.import_module")
@mock.patch("aiohttp.web.ArgumentParser.exit", side_effect=SystemExit)
def test_running_application(exit, import_module, run_app):
argv = ("-H testhost -P 6666 --extra-optional-eins alpha.beta:func "
argv = ("web.py -H testhost -P 6666 --extra-optional-eins alpha.beta:func "
"--extra-optional-zwei extra positional args").split()
module = import_module("alpha.beta")
app = module.func()
Expand Down

0 comments on commit 86d1934

Please sign in to comment.