def test_parser_error_when_gids_and_all_option(capsys): with pytest.raises(SystemExit) as e: cli.main(["pause", "-a", "2089b05ecca3d829"]) assert e.value.code == 2 lines = err_lines(capsys) assert lines[0].startswith("usage: aria2p pause") assert lines[1].endswith("-a/--all: not allowed with arguments gids")
def test_main_show_subcommand(capsys): with Aria2Server(port=7501) as server: cli.main(["-p", str(server.port), "show"]) first_line = first_out_line(capsys) for word in ("GID", "STATUS", "PROGRESS", "DOWN_SPEED", "UP_SPEED", "ETA", "NAME"): assert word in first_line
def assert_func(command, alias): with pytest.raises(SystemExit) as e: cli.main([alias]) assert e.value.code == 2 lines = err_lines(capsys) assert lines[0].startswith("usage: aria2p " + command) assert lines[1].endswith( "the following arguments are required: gids or --all")
def test_show_help(capsys): """ Show help. Arguments: capsys: Pytest fixture to capture output. """ with pytest.raises(SystemExit): cli.main(["-h"]) captured = capsys.readouterr() assert "aria2p" in captured.out
def test_errors_and_print_message(capsys): with Aria2Server(port=7502) as server: assert cli.main([ "-p", str(server.port), "call", "tellstatus", "-P", "invalid gid" ]) > 0 assert capsys.readouterr().err == "Invalid GID invalid gid\n"
def test_parser_error_when_no_gid_and_no_all_option(capsys): with pytest.raises(SystemExit) as e: assert cli.main(["resume"]) assert e.value.code == 2 lines = err_lines(capsys) assert lines[0].startswith("usage: aria2p resume") assert lines[1].endswith("the following arguments are required: gids or --all")
def test_main_no_command_defaults_to_top(mocked_function): with Aria2Server(port=7500) as server: cli.main(["-p", str(server.port)]) assert mocked_function.called
def test_parser_no_error(mocked_function): with Aria2Server(port=7550) as server: cli.main(["-p", str(server.port), "purge", "-a"]) assert mocked_function.called
def test_main_returns_2_when_no_remote_running(): assert cli.main(["--port=7549"]) == 2
""" Entry-point module, in case you use `python -m aria2p`. Why does this file exist, and why __main__? For more info, read: - https://www.python.org/dev/peps/pep-0338/ - https://docs.python.org/2/using/cmdline.html#cmdoption-m - https://docs.python.org/3/using/cmdline.html#cmdoption-m """ import sys from aria2p.cli import main if __name__ == "__main__": sys.exit(main(sys.argv[1:]))
def test_main_returns_2_when_no_remote_running(): assert cli.main([]) == 2
def test_no_interface_deps_print_error(monkeypatch, capsys): monkeypatch.setattr(cli, "Interface", None) with Aria2Server(port=7523) as server: cli.main(["-p", str(server.port)]) line = first_err_line(capsys) assert "aria2p[tui]" in line
def test_main_no_command_defaults_to_show(mocked_function): cli.main([]) assert mocked_function.called
def test_main_no_command_defaults_to_top(mocked_function, server): cli.main(["-p", str(server.port)]) assert mocked_function.called
def test_parser_no_error(mocked_function, server): cli.main(["-p", str(server.port), "remove", "-a"]) assert mocked_function.called
def test_main_returns_2_when_no_remote_running(port): assert cli.main([f"--port={port}"]) == 2