mirror of
https://github.com/miurahr/aqtinstall.git
synced 2025-12-17 20:54:38 +03:00
refactor: test: update cases and expectations
Signed-off-by: Hiroshi Miura <miurahr@linux.com>
This commit is contained in:
@@ -167,8 +167,7 @@ class Cli:
|
||||
title="subcommands",
|
||||
description="aqt accepts several subcommands:\n"
|
||||
"install-* subcommands are commands that install components\n"
|
||||
"list-* subcommands are commands that show available components\n\n"
|
||||
"commands {install|tool|src|examples|doc} are deprecated and marked for removal\n",
|
||||
"list-* subcommands are commands that show available components\n",
|
||||
help="Please refer to each help message by using '--help' with each subcommand",
|
||||
)
|
||||
self._make_all_parsers(subparsers)
|
||||
|
||||
@@ -16,8 +16,7 @@ def expected_help(actual, prefix=None):
|
||||
expected = (
|
||||
"usage: aqt [-h] [-c CONFIG]\n"
|
||||
" {install-qt,install-tool,install-doc,install-example,install-src,"
|
||||
"list-qt,list-tool,list-doc,list-example,list-src,"
|
||||
"install,tool,doc,examples,src,help,version}\n"
|
||||
"list-qt,list-tool,list-doc,list-example,list-src,help,version}\n"
|
||||
" ...\n"
|
||||
"\n"
|
||||
"Another unofficial Qt Installer.\n"
|
||||
@@ -33,12 +32,8 @@ def expected_help(actual, prefix=None):
|
||||
" install-* subcommands are commands that install components\n"
|
||||
" list-* subcommands are commands that show available components\n"
|
||||
"\n"
|
||||
" commands {install|tool|src|examples|doc} are deprecated and marked for "
|
||||
"removal\n"
|
||||
"\n"
|
||||
" {install-qt,install-tool,install-doc,install-example,install-src,list-qt,"
|
||||
"list-tool,list-doc,list-example,list-src,"
|
||||
"install,tool,doc,examples,src,help,version}\n"
|
||||
"list-tool,list-doc,list-example,list-src,help,version}\n"
|
||||
" Please refer to each help message by using '--help' "
|
||||
"with each subcommand\n",
|
||||
)
|
||||
@@ -110,14 +105,12 @@ def test_cli_invalid_version(capsys, invalid_version):
|
||||
cli._setup_settings()
|
||||
|
||||
matcher = re.compile(
|
||||
r"^INFO : aqtinstall\(aqt\) v.* on Python 3.*\n"
|
||||
# r"^INFO : aqtinstall\(aqt\) v.* on Python 3.*\n"
|
||||
r"(.*\n)*"
|
||||
r"ERROR :.*Invalid version: '" + invalid_version + r"'! Please use the form '5\.X\.Y'\.\n.*"
|
||||
)
|
||||
|
||||
for cmd in (
|
||||
("install", invalid_version, "mac", "desktop"),
|
||||
("doc", invalid_version, "mac", "desktop"),
|
||||
("list-qt", "mac", "desktop", "--arch", invalid_version),
|
||||
):
|
||||
cli = Cli()
|
||||
@@ -234,52 +227,6 @@ def test_cli_input_errors(capsys, cmd, expect_msg, should_show_help):
|
||||
assert err.rstrip().endswith(expect_msg)
|
||||
|
||||
|
||||
# These commands use the new syntax with the legacy commands
|
||||
@pytest.mark.parametrize(
|
||||
"cmd",
|
||||
(
|
||||
"install linux desktop 5.10.0",
|
||||
"install linux desktop 5.10.0 gcc_64",
|
||||
"src linux desktop 5.10.0",
|
||||
"doc linux desktop 5.10.0",
|
||||
"example linux desktop 5.10.0",
|
||||
"tool windows desktop tools_ifw",
|
||||
),
|
||||
)
|
||||
def test_cli_legacy_commands_with_wrong_syntax(cmd):
|
||||
cli = Cli()
|
||||
cli._setup_settings()
|
||||
with pytest.raises(SystemExit) as e:
|
||||
cli.run(cmd.split())
|
||||
assert e.type == SystemExit
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"cmd",
|
||||
(
|
||||
"tool windows desktop tools_ifw qt.tools.ifw.31", # New syntax
|
||||
"tool windows desktop tools_ifw 1.2.3",
|
||||
),
|
||||
)
|
||||
def test_cli_legacy_tool_new_syntax(monkeypatch, capsys, cmd):
|
||||
# These incorrect commands cannot be filtered out directly by argparse because
|
||||
# they have the correct number of arguments.
|
||||
command = cmd.split()
|
||||
|
||||
expected = (
|
||||
"WARNING : The command 'tool' is deprecated and marked for removal in a future version of aqt.\n"
|
||||
"In the future, please use the command 'install-tool' instead.\n"
|
||||
"ERROR : Invalid version: 'tools_ifw'! Please use the form '5.X.Y'.\n"
|
||||
)
|
||||
|
||||
cli = Cli()
|
||||
cli._setup_settings()
|
||||
assert 1 == cli.run(command)
|
||||
out, err = capsys.readouterr()
|
||||
actual = err[err.index("\n") + 1 :]
|
||||
assert actual == expected
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"cmd, expect_err",
|
||||
(
|
||||
@@ -308,28 +255,6 @@ def test_cli_list_qt_deprecated_flags(capsys, cmd: str, expect_err: str):
|
||||
assert err == expect_err
|
||||
|
||||
|
||||
# These commands come directly from examples in the legacy documentation
|
||||
@pytest.mark.parametrize(
|
||||
"cmd",
|
||||
(
|
||||
"install 5.10.0 linux desktop", # default arch
|
||||
"install 5.10.2 linux android android_armv7",
|
||||
"src 5.15.2 windows desktop --archives qtbase --kde",
|
||||
"doc 5.15.2 windows desktop -m qtcharts qtnetworkauth",
|
||||
"examples 5.15.2 windows desktop -m qtcharts qtnetworkauth",
|
||||
"tool linux tools_ifw 4.0 qt.tools.ifw.40",
|
||||
),
|
||||
)
|
||||
def test_cli_legacy_commands_with_correct_syntax(monkeypatch, cmd):
|
||||
# Pretend to install correctly when any command is run
|
||||
for func in ("run_install_qt", "run_install_src", "run_install_doc", "run_install_example", "run_install_tool"):
|
||||
monkeypatch.setattr(Cli, func, lambda *args, **kwargs: 0)
|
||||
|
||||
cli = Cli()
|
||||
cli._setup_settings()
|
||||
assert 0 == cli.run(cmd.split())
|
||||
|
||||
|
||||
def test_cli_unexpected_error(monkeypatch, capsys):
|
||||
def _mocked_run(*args):
|
||||
raise RuntimeError("Some unexpected error")
|
||||
|
||||
@@ -354,45 +354,6 @@ def tool_archive(host: str, tool_name: str, variant: str, date: datetime = datet
|
||||
r"INFO : Time elapsed: .* second"
|
||||
),
|
||||
),
|
||||
(
|
||||
"tool linux tools_qtcreator 1.2.3-0-197001020304 qt.tools.qtcreator".split(),
|
||||
"linux",
|
||||
"desktop",
|
||||
"1.2.3",
|
||||
{"std": ""},
|
||||
{"std": ""},
|
||||
{"std": "linux_x64/desktop/tools_qtcreator/Updates.xml"},
|
||||
{"std": [tool_archive("linux", "tools_qtcreator", "qt.tools.qtcreator", datetime(1970, 1, 2, 3, 4, 5, 6))]},
|
||||
re.compile(
|
||||
r"^INFO : aqtinstall\(aqt\) v.* on Python 3.*\n"
|
||||
r"WARNING : The command 'tool' is deprecated and marked for removal in a future version of aqt.\n"
|
||||
r"In the future, please use the command 'install-tool' instead.\n"
|
||||
r"INFO : Downloading qt.tools.qtcreator...\n"
|
||||
r"Finished installation of tools_qtcreator-linux-qt.tools.qtcreator.7z in .*\n"
|
||||
r"INFO : Finished installation\n"
|
||||
r"INFO : Time elapsed: .* second"
|
||||
),
|
||||
),
|
||||
(
|
||||
"install 5.14.0 windows desktop win32_mingw73".split(),
|
||||
"windows",
|
||||
"desktop",
|
||||
"5.14.0",
|
||||
{"std": "win32_mingw73"},
|
||||
{"std": "mingw73_32"},
|
||||
{"std": "windows_x86/desktop/qt5_5140/Updates.xml"},
|
||||
{"std": [plain_qtbase_archive("qt.qt5.5140.win32_mingw73", "win32_mingw73")]},
|
||||
re.compile(
|
||||
r"^INFO : aqtinstall\(aqt\) v.* on Python 3.*\n"
|
||||
r"WARNING : The command 'install' is deprecated"
|
||||
r" and marked for removal in a future version of aqt.\n"
|
||||
r"In the future, please use the command 'install-qt' instead.\n"
|
||||
r"INFO : Downloading qtbase...\n"
|
||||
r"Finished installation of qtbase-windows-win32_mingw73.7z in .*\n"
|
||||
r"INFO : Finished installation\n"
|
||||
r"INFO : Time elapsed: .* second"
|
||||
),
|
||||
),
|
||||
( # Mixing --modules with --archives
|
||||
"install-qt windows desktop 5.14.0 win32_mingw73 -m qtcharts --archives qtbase".split(),
|
||||
"windows",
|
||||
@@ -531,26 +492,6 @@ def tool_archive(host: str, tool_name: str, variant: str, date: datetime = datet
|
||||
r"INFO : Time elapsed: .* second"
|
||||
),
|
||||
),
|
||||
(
|
||||
"install 5.9.0 windows desktop win32_mingw53".split(),
|
||||
"windows",
|
||||
"desktop",
|
||||
"5.9.0",
|
||||
{"std": "win32_mingw53"},
|
||||
{"std": "mingw53_32"},
|
||||
{"std": "windows_x86/desktop/qt5_59/Updates.xml"},
|
||||
{"std": [plain_qtbase_archive("qt.59.win32_mingw53", "win32_mingw53")]},
|
||||
re.compile(
|
||||
r"^INFO : aqtinstall\(aqt\) v.* on Python 3.*\n"
|
||||
r"WARNING : The command 'install' is deprecated"
|
||||
r" and marked for removal in a future version of aqt.\n"
|
||||
r"In the future, please use the command 'install-qt' instead.\n"
|
||||
r"INFO : Downloading qtbase...\n"
|
||||
r"Finished installation of qtbase-windows-win32_mingw53.7z in .*\n"
|
||||
r"INFO : Finished installation\n"
|
||||
r"INFO : Time elapsed: .* second"
|
||||
),
|
||||
),
|
||||
(
|
||||
"install-qt windows desktop 5.9.0 win32_mingw53".split(),
|
||||
"windows",
|
||||
|
||||
Reference in New Issue
Block a user