def assert_func(command, alias): with pytest.raises(SystemExit) as e: 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_parser_error_when_gids_and_all_option(capsys): with pytest.raises(SystemExit) as e: main(["pause", "-a", "0000000000000001"]) 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_show_help(capsys): """ Show help. Arguments: capsys: Pytest fixture to capture output. """ with pytest.raises(SystemExit): main(["-h"]) captured = capsys.readouterr() assert "aria2p" in captured.out
""" 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/3/using/cmdline.html#cmdoption-m """ import sys from aria2p.cli.main import main if __name__ == "__main__": sys.exit(main(sys.argv[1:]))
def test_main_show_subcommand(server, capsys): 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 test_no_interface_deps_print_error(server, monkeypatch, capsys): monkeypatch.setattr(top, "Interface", None) main(["-p", str(server.port)]) line = first_err_line(capsys) assert "aria2p[tui]" in line
def test_main_returns_2_when_no_remote_running(port): assert main([f"--port={port}"]) == 2
def test_errors_and_print_message(server, capsys): assert main(["-p", str(server.port), "call", "tellstatus", "-P", "invalid gid"]) > 0 assert capsys.readouterr().err == "Invalid GID invalid gid\n"
def test_error_when_missing_arg(command, option, capsys): with pytest.raises(SystemExit): main([command]) assert option in capsys.readouterr().err