From 5be71197d1c32d0326caf10988a2185a6c31463c Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Tue, 13 Jun 2023 20:20:03 +0200 Subject: qt: Allow opt-in to autoselection and enable tests --- qutebrowser/qt/machinery.py | 4 +++- tests/unit/test_qt_machinery.py | 30 +++++++++++++++++++++++------- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/qutebrowser/qt/machinery.py b/qutebrowser/qt/machinery.py index 513e0c643..f1539b07f 100644 --- a/qutebrowser/qt/machinery.py +++ b/qutebrowser/qt/machinery.py @@ -166,7 +166,9 @@ def _select_wrapper(args: Optional[argparse.Namespace]) -> SelectionInfo: env_var = "QUTE_QT_WRAPPER" env_wrapper = os.environ.get(env_var) if env_wrapper: - if env_wrapper not in WRAPPERS: + if env_wrapper == "auto": + return _autoselect_wrapper() + elif env_wrapper not in WRAPPERS: raise Error(f"Unknown wrapper {env_wrapper} set via {env_var}, " f"allowed: {', '.join(WRAPPERS)}") return SelectionInfo(wrapper=env_wrapper, reason=SelectionReason.env) diff --git a/tests/unit/test_qt_machinery.py b/tests/unit/test_qt_machinery.py index 596d21383..0875be7e4 100644 --- a/tests/unit/test_qt_machinery.py +++ b/tests/unit/test_qt_machinery.py @@ -1,6 +1,6 @@ # vim: ft=python fileencoding=utf-8 sts=4 sw=4 et: -# Copyright 2021 Florian Bruhin (The Compiler) +# Copyright 2023 Florian Bruhin (The Compiler) # # This file is part of qutebrowser. # @@ -19,6 +19,7 @@ """Test qutebrowser.qt.machinery.""" +import re import sys import html import argparse @@ -339,7 +340,6 @@ class TestInit: ): machinery.init(args=empty_args) - @pytest.mark.xfail(reason="autodetect not used yet") def test_none_available_implicit( self, stubs: Any, @@ -347,12 +347,25 @@ class TestInit: monkeypatch: pytest.MonkeyPatch, undo_init: None, ): + # FIXME:qt6 Also try without this once auto is default + monkeypatch.setenv("QUTE_QT_WRAPPER", "auto") stubs.ImportFake(modules, monkeypatch).patch() - message = "No Qt wrapper was importable." # FIXME maybe check info too - with pytest.raises(machinery.NoWrapperAvailableError, match=message): + + message_lines = [ + "No Qt wrapper was importable.", + "", + "Qt wrapper info:", + " PyQt5: not imported", + " PyQt6: ImportError: Fake ImportError for PyQt6.", + " -> selected: None (via autoselect)", + ] + + with pytest.raises( + machinery.NoWrapperAvailableError, + match=re.escape("\n".join(message_lines)), + ): machinery.init_implicit() - @pytest.mark.xfail(reason="autodetect not used yet") def test_none_available_explicit( self, stubs: Any, @@ -361,13 +374,16 @@ class TestInit: empty_args: argparse.Namespace, undo_init: None, ): + # FIXME:qt6 Also try without this once auto is default + monkeypatch.setenv("QUTE_QT_WRAPPER", "auto") stubs.ImportFake(modules, monkeypatch).patch() + info = machinery.init(args=empty_args) assert info == machinery.SelectionInfo( wrapper=None, - reason=machinery.SelectionReason.default, + reason=machinery.SelectionReason.auto, pyqt6="ImportError: Fake ImportError for PyQt6.", - pyqt5="ImportError: Fake ImportError for PyQt5.", + pyqt5=None, ) @pytest.mark.parametrize( -- cgit v1.2.3-54-g00ecf