Esempio n. 1
0
def test_show_list_empty(monkeypatch, capsys):
    monkeypatch.setattr(MetadataFactory, "getList", lambda self: [])
    meta = MetadataFactory(ArchiveId("tools", "mac", "desktop"))
    with pytest.raises(EmptyMetadata) as error:
        show_list(meta)
    assert error.type == EmptyMetadata
    assert format(error.value) == "No tools available for this request."
Esempio n. 2
0
def test_show_list_versions(monkeypatch, capsys):
    _html = (Path(__file__).parent / "data" /
             "mac-desktop.html").read_text("utf-8")
    monkeypatch.setattr(MetadataFactory, "fetch_http", lambda *args: _html)

    expect_file = Path(__file__).parent / "data" / "mac-desktop-expect.json"
    expected = "\n".join(
        json.loads(expect_file.read_text("utf-8"))["qt"]["qt"]) + "\n"

    show_list(MetadataFactory(mac_qt))
    out, err = capsys.readouterr()
    assert out == expected
Esempio n. 3
0
def test_show_list_tools(monkeypatch, capsys):
    page = (Path(__file__).parent / "data" /
            "mac-desktop.html").read_text("utf-8")
    monkeypatch.setattr(MetadataFactory, "fetch_http", lambda self, _: page)

    expect_file = Path(__file__).parent / "data" / "mac-desktop-expect.json"
    expect = "\n".join(json.loads(
        expect_file.read_text("utf-8"))["tools"]) + "\n"

    meta = MetadataFactory(ArchiveId("tools", "mac", "desktop"))
    show_list(meta)
    out, err = capsys.readouterr()
    sys.stdout.write(out)
    sys.stderr.write(err)
    assert out == expect
Esempio n. 4
0
    def run_list_tool(self, args: argparse.ArgumentParser):
        """Print tools"""

        if not args.target:
            print(" ".join(ArchiveId.TARGETS_FOR_HOST[args.host]))
            return
        if args.target not in ArchiveId.TARGETS_FOR_HOST[args.host]:
            raise CliInputError(
                "'{0.target}' is not a valid target for host '{0.host}'".
                format(args))

        meta = MetadataFactory(
            archive_id=ArchiveId("tools", args.host, args.target),
            tool_name=args.tool_name,
            is_long_listing=args.long,
        )
        show_list(meta)
Esempio n. 5
0
    def run_list_qt(self, args: argparse.ArgumentParser):
        """Print versions of Qt, extensions, modules, architectures"""

        if not args.target:
            print(" ".join(ArchiveId.TARGETS_FOR_HOST[args.host]))
            return
        if args.target not in ArchiveId.TARGETS_FOR_HOST[args.host]:
            raise CliInputError(
                "'{0.target}' is not a valid target for host '{0.host}'".
                format(args))
        if args.modules:
            modules_ver, modules_query = args.modules[0], tuple(args.modules)
        else:
            modules_ver, modules_query = None, None

        for version_str in (modules_ver, args.extensions, args.arch,
                            args.archives[0] if args.archives else None):
            Cli._validate_version_str(version_str,
                                      allow_latest=True,
                                      allow_empty=True)

        spec = None
        try:
            if args.spec is not None:
                spec = SimpleSpec(args.spec)
        except ValueError as e:
            raise CliInputError(
                f"Invalid version specification: '{args.spec}'.\n" +
                SimpleSpec.usage()) from e

        meta = MetadataFactory(
            archive_id=ArchiveId(
                "qt",
                args.host,
                args.target,
                args.extension if args.extension else "",
            ),
            spec=spec,
            is_latest_version=args.latest_version,
            modules_query=modules_query,
            extensions_ver=args.extensions,
            architectures_ver=args.arch,
            archives_query=args.archives,
        )
        show_list(meta)
Esempio n. 6
0
def test_show_list_tools_long_ifw(capsys, monkeypatch, columns, expect):
    update_xml = (Path(__file__).parent / "data" /
                  "mac-desktop-tools_ifw-update.xml").read_text("utf-8")
    monkeypatch.setattr(MetadataFactory, "fetch_http",
                        lambda self, _: update_xml)

    monkeypatch.setattr(shutil, "get_terminal_size",
                        lambda fallback: os.terminal_size((columns, 24)))

    meta = MetadataFactory(
        ArchiveId("tools", "mac", "desktop"),
        tool_name="tools_ifw",
        is_long_listing=True,
    )
    show_list(meta)
    out, err = capsys.readouterr()
    sys.stdout.write(out)
    sys.stderr.write(err)
    assert out == expect
Esempio n. 7
0
def test_show_list_bad_connection(monkeypatch, capsys):
    for exception_class, error_msg in (
        (ArchiveConnectionError, "Failure to connect to some url"),
        (ArchiveDownloadError, "Failure to download some xml file"),
    ):

        def mock(self):
            raise exception_class(error_msg)

        monkeypatch.setattr(MetadataFactory, "getList", mock)
        meta = MetadataFactory(mac_wasm, spec=SimpleSpec("<5.9"))
        with pytest.raises(exception_class) as error:
            show_list(meta)
        assert error.type == exception_class
        assert format(error.value) == (
            f"{error_msg}\n"
            "==============================Suggested follow-up:==============================\n"
            "* Please use 'aqt list-qt mac desktop --extensions <QT_VERSION>' to list valid extensions.\n"
            "* Please use 'aqt list-qt mac desktop' to check that versions of qt exist within the spec '<5.9'."
        )