summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Bruhin <me@the-compiler.org>2023-06-23 23:38:54 +0200
committerFlorian Bruhin <me@the-compiler.org>2023-06-30 19:29:28 +0200
commit73fb5c4c49a9f79b1820486dc11e819f859d593a (patch)
treeef75c38635b1414c975cc5f8e4e3e7b587188ff3
parentad77048d530aefeecdd1c784accaddb929f8bdc6 (diff)
downloadqutebrowser-73fb5c4c49a9f79b1820486dc11e819f859d593a.tar.gz
qutebrowser-73fb5c4c49a9f79b1820486dc11e819f859d593a.zip
qt: Switch to autoselection of Qt backend by default
-rw-r--r--qutebrowser/qt/machinery.py6
-rw-r--r--tests/unit/test_qt_machinery.py191
2 files changed, 99 insertions, 98 deletions
diff --git a/qutebrowser/qt/machinery.py b/qutebrowser/qt/machinery.py
index bd5062120..a5705a933 100644
--- a/qutebrowser/qt/machinery.py
+++ b/qutebrowser/qt/machinery.py
@@ -150,7 +150,7 @@ def _select_wrapper(args: Optional[argparse.Namespace]) -> SelectionInfo:
- If --qt-wrapper is given, use that.
- Otherwise, if the QUTE_QT_WRAPPER environment variable is set, use that.
- - Otherwise, use PyQt5 (FIXME:qt6 autoselect).
+ - Otherwise, try the wrappers in WRAPPER in order (PyQt6 -> PyQt5)
"""
# If any Qt wrapper has been imported before this, something strange might
# be happening.
@@ -174,11 +174,9 @@ def _select_wrapper(args: Optional[argparse.Namespace]) -> SelectionInfo:
)
return SelectionInfo(wrapper=env_wrapper, reason=SelectionReason.env)
- # FIXME:qt6 Go back to the auto-detection once ready
# FIXME:qt6 Make sure to still consider _DEFAULT_WRAPPER for packagers
# (rename to _WRAPPER_OVERRIDE since our sed command is broken anyways then?)
- # return _autoselect_wrapper()
- return SelectionInfo(wrapper=_DEFAULT_WRAPPER, reason=SelectionReason.default)
+ return _autoselect_wrapper()
# Values are set in init(). If you see a NameError here, it means something tried to
diff --git a/tests/unit/test_qt_machinery.py b/tests/unit/test_qt_machinery.py
index b4d302ae5..40631accc 100644
--- a/tests/unit/test_qt_machinery.py
+++ b/tests/unit/test_qt_machinery.py
@@ -230,111 +230,114 @@ def test_autoselect(
assert machinery._autoselect_wrapper() == expected
-@pytest.mark.parametrize(
- "args, env, expected",
- [
- # Defaults with no overrides
- (
- None,
- None,
- machinery.SelectionInfo(
- wrapper="PyQt5", reason=machinery.SelectionReason.default
- ),
- ),
- (
- argparse.Namespace(qt_wrapper=None),
- None,
- machinery.SelectionInfo(
- wrapper="PyQt5", reason=machinery.SelectionReason.default
- ),
- ),
- (
- argparse.Namespace(qt_wrapper=None),
- "",
- machinery.SelectionInfo(
- wrapper="PyQt5", reason=machinery.SelectionReason.default
- ),
- ),
- # Only argument given
- (
- argparse.Namespace(qt_wrapper="PyQt6"),
- None,
- machinery.SelectionInfo(
- wrapper="PyQt6", reason=machinery.SelectionReason.cli
+class TestSelectWrapper:
+ @pytest.mark.parametrize(
+ "args, env, expected",
+ [
+ # Only argument given
+ (
+ argparse.Namespace(qt_wrapper="PyQt6"),
+ None,
+ machinery.SelectionInfo(
+ wrapper="PyQt6", reason=machinery.SelectionReason.cli
+ ),
),
- ),
- (
- argparse.Namespace(qt_wrapper="PyQt5"),
- None,
- machinery.SelectionInfo(
- wrapper="PyQt5", reason=machinery.SelectionReason.cli
+ (
+ argparse.Namespace(qt_wrapper="PyQt5"),
+ None,
+ machinery.SelectionInfo(
+ wrapper="PyQt5", reason=machinery.SelectionReason.cli
+ ),
),
- ),
- (
- argparse.Namespace(qt_wrapper="PyQt5"),
- "",
- machinery.SelectionInfo(
- wrapper="PyQt5", reason=machinery.SelectionReason.cli
+ (
+ argparse.Namespace(qt_wrapper="PyQt5"),
+ "",
+ machinery.SelectionInfo(
+ wrapper="PyQt5", reason=machinery.SelectionReason.cli
+ ),
),
- ),
- # Only environment variable given
- (
- None,
- "PyQt6",
- machinery.SelectionInfo(
- wrapper="PyQt6", reason=machinery.SelectionReason.env
+ # Only environment variable given
+ (
+ None,
+ "PyQt6",
+ machinery.SelectionInfo(
+ wrapper="PyQt6", reason=machinery.SelectionReason.env
+ ),
),
- ),
- (
- None,
- "PyQt5",
- machinery.SelectionInfo(
- wrapper="PyQt5", reason=machinery.SelectionReason.env
+ (
+ None,
+ "PyQt5",
+ machinery.SelectionInfo(
+ wrapper="PyQt5", reason=machinery.SelectionReason.env
+ ),
),
- ),
- # Both given
- (
- argparse.Namespace(qt_wrapper="PyQt5"),
- "PyQt6",
- machinery.SelectionInfo(
- wrapper="PyQt5", reason=machinery.SelectionReason.cli
+ # Both given
+ (
+ argparse.Namespace(qt_wrapper="PyQt5"),
+ "PyQt6",
+ machinery.SelectionInfo(
+ wrapper="PyQt5", reason=machinery.SelectionReason.cli
+ ),
),
- ),
- (
- argparse.Namespace(qt_wrapper="PyQt6"),
- "PyQt5",
- machinery.SelectionInfo(
- wrapper="PyQt6", reason=machinery.SelectionReason.cli
+ (
+ argparse.Namespace(qt_wrapper="PyQt6"),
+ "PyQt5",
+ machinery.SelectionInfo(
+ wrapper="PyQt6", reason=machinery.SelectionReason.cli
+ ),
),
- ),
- (
- argparse.Namespace(qt_wrapper="PyQt6"),
- "PyQt6",
- machinery.SelectionInfo(
- wrapper="PyQt6", reason=machinery.SelectionReason.cli
+ (
+ argparse.Namespace(qt_wrapper="PyQt6"),
+ "PyQt6",
+ machinery.SelectionInfo(
+ wrapper="PyQt6", reason=machinery.SelectionReason.cli
+ ),
),
- ),
- ],
-)
-def test_select_wrapper(
- args: Optional[argparse.Namespace],
- env: Optional[str],
- expected: machinery.SelectionInfo,
- monkeypatch: pytest.MonkeyPatch,
- undo_init: None,
-):
- if env is None:
- monkeypatch.delenv("QUTE_QT_WRAPPER", raising=False)
- else:
- monkeypatch.setenv("QUTE_QT_WRAPPER", env)
+ ],
+ )
+ def test_select(
+ self,
+ args: Optional[argparse.Namespace],
+ env: Optional[str],
+ expected: machinery.SelectionInfo,
+ monkeypatch: pytest.MonkeyPatch,
+ ):
+ if env is None:
+ monkeypatch.delenv("QUTE_QT_WRAPPER", raising=False)
+ else:
+ monkeypatch.setenv("QUTE_QT_WRAPPER", env)
- assert machinery._select_wrapper(args) == expected
+ assert machinery._select_wrapper(args) == expected
+
+ @pytest.mark.parametrize(
+ "args, env",
+ [
+ (None, None),
+ (argparse.Namespace(qt_wrapper=None), None),
+ (argparse.Namespace(qt_wrapper=None), ""),
+ ],
+ )
+ def test_autoselect_by_default(
+ self,
+ args: Optional[argparse.Namespace],
+ env: Optional[str],
+ monkeypatch: pytest.MonkeyPatch,
+ ):
+ """Test that the default behavior is to autoselect a wrapper.
+
+ Autoselection itself is tested further down.
+ """
+ if env is None:
+ monkeypatch.delenv("QUTE_QT_WRAPPER", raising=False)
+ else:
+ monkeypatch.setenv("QUTE_QT_WRAPPER", env)
+ assert machinery._select_wrapper(args).reason == machinery.SelectionReason.auto
-def test_select_wrapper_after_qt_import(monkeypatch: pytest.MonkeyPatch):
- monkeypatch.setitem(sys.modules, "PyQt6", None)
- with pytest.warns(UserWarning, match="PyQt6 already imported"):
- machinery._select_wrapper(args=None)
+ def test_after_qt_import(self, monkeypatch: pytest.MonkeyPatch):
+ monkeypatch.setitem(sys.modules, "PyQt6", None)
+ with pytest.warns(UserWarning, match="PyQt6 already imported"):
+ machinery._select_wrapper(args=None)
class TestInit: