summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJimmy <jimmy@spalge.com>2022-04-17 16:56:02 +1200
committertoofar <toofar@spalge.com>2022-07-03 16:51:04 +1200
commit68b69d8bac2e49a4df7cd974b35f6e47826ebd2a (patch)
treeedb4f665066e4c939a9cfd3208c5b6de98f32952
parentf553ebf0c6a9cd3b753d4958a265c0ef94830895 (diff)
downloadqutebrowser-68b69d8bac2e49a4df7cd974b35f6e47826ebd2a.tar.gz
qutebrowser-68b69d8bac2e49a4df7cd974b35f6e47826ebd2a.zip
Adapt test mocking for new PyQt wrapper
Now that we are importing the PyQt modules and then accessing stuff as attributes on them the mocks in the tests should be done the same way. This was done manually, I didn't even try to automate it. Cherry picked from 81e802faaf08 on the Qt5 only branch.
-rw-r--r--tests/unit/browser/test_notification.py2
-rw-r--r--tests/unit/completion/test_completer.py2
-rw-r--r--tests/unit/completion/test_models.py2
-rw-r--r--tests/unit/config/test_configfiles.py4
-rw-r--r--tests/unit/config/test_qtargs.py6
-rw-r--r--tests/unit/keyinput/test_keyutils.py2
-rw-r--r--tests/unit/misc/test_editor.py2
-rw-r--r--tests/unit/misc/test_ipc.py8
-rw-r--r--tests/unit/utils/test_qtutils.py8
-rw-r--r--tests/unit/utils/test_standarddir.py10
-rw-r--r--tests/unit/utils/test_urlutils.py2
-rw-r--r--tests/unit/utils/test_utils.py2
-rw-r--r--tests/unit/utils/test_version.py8
13 files changed, 28 insertions, 30 deletions
diff --git a/tests/unit/browser/test_notification.py b/tests/unit/browser/test_notification.py
index 2ae64a134..f7c07b93d 100644
--- a/tests/unit/browser/test_notification.py
+++ b/tests/unit/browser/test_notification.py
@@ -194,7 +194,7 @@ class TestDBus:
@pytest.fixture
def dbus_adapter_patches(self, monkeypatch, config_stub):
monkeypatch.setattr(objects, "debug_flags", ["test-notification-service"])
- monkeypatch.setattr(notification, "QDBusInterface", FakeDBusInterface)
+ monkeypatch.setattr(notification.dbus, "QDBusInterface", FakeDBusInterface)
@pytest.fixture
def dbus_adapter(self, dbus_adapter_patches):
diff --git a/tests/unit/completion/test_completer.py b/tests/unit/completion/test_completer.py
index 659332ac2..38af142c2 100644
--- a/tests/unit/completion/test_completer.py
+++ b/tests/unit/completion/test_completer.py
@@ -70,7 +70,7 @@ def completion_widget_stub():
def completer_obj(qtbot, status_command_stub, config_stub, monkeypatch, stubs,
completion_widget_stub):
"""Create the completer used for testing."""
- monkeypatch.setattr(completer, 'QTimer', stubs.InstaTimer)
+ monkeypatch.setattr(completer.core, 'QTimer', stubs.InstaTimer)
config_stub.val.completion.show = 'auto'
return completer.Completer(cmd=status_command_stub, win_id=0,
parent=completion_widget_stub)
diff --git a/tests/unit/completion/test_models.py b/tests/unit/completion/test_models.py
index 79871487c..572dfc91e 100644
--- a/tests/unit/completion/test_models.py
+++ b/tests/unit/completion/test_models.py
@@ -1475,7 +1475,7 @@ def undo_completion_retains_sort_order(tabbed_browser_stubs, info):
def test_process_completion(monkeypatch, stubs, info):
- monkeypatch.setattr(guiprocess, 'QProcess', stubs.FakeProcess)
+ monkeypatch.setattr(guiprocess.core, 'QProcess', stubs.FakeProcess)
p1 = guiprocess.GUIProcess('testprocess')
p2 = guiprocess.GUIProcess('testprocess')
p3 = guiprocess.GUIProcess('editor')
diff --git a/tests/unit/config/test_configfiles.py b/tests/unit/config/test_configfiles.py
index 9ba02c639..c744eaa8f 100644
--- a/tests/unit/config/test_configfiles.py
+++ b/tests/unit/config/test_configfiles.py
@@ -151,7 +151,7 @@ def test_state_config(
old_data, insert, new_data
):
monkeypatch.setattr(configfiles.qutebrowser, '__version__', '1.2.3')
- monkeypatch.setattr(configfiles, 'qVersion', lambda: '5.6.7')
+ monkeypatch.setattr(configfiles.core, 'qVersion', lambda: '5.6.7')
qtwe_version_patcher('7.8.9', chromium_version='123.4.5.6')
statefile = data_tmpdir / 'state'
@@ -214,7 +214,7 @@ def qtwe_version_patcher(monkeypatch):
])
def test_qt_version_changed(state_writer, monkeypatch,
old_version, new_version, changed):
- monkeypatch.setattr(configfiles, 'qVersion', lambda: new_version)
+ monkeypatch.setattr(configfiles.core, 'qVersion', lambda: new_version)
if old_version is not None:
state_writer('qt_version', old_version)
diff --git a/tests/unit/config/test_qtargs.py b/tests/unit/config/test_qtargs.py
index da422062d..22a23d437 100644
--- a/tests/unit/config/test_qtargs.py
+++ b/tests/unit/config/test_qtargs.py
@@ -110,9 +110,7 @@ def test_no_webengine_available(monkeypatch, config_stub, parser, stubs):
here.
"""
monkeypatch.setattr(qtargs.objects, 'backend', usertypes.Backend.QtWebEngine)
-
- fake = stubs.ImportFake({'qutebrowser.browser.webengine': False}, monkeypatch)
- fake.patch()
+ monkeypatch.setattr(qtargs, 'webengine', None)
parsed = parser.parse_args([])
args = qtargs.qt_args(parsed)
@@ -474,7 +472,7 @@ class TestWebEngineArgs:
return 'de-CH'
monkeypatch.setattr(qtargs.utils, 'is_linux', True) # patched in reduce_args
- monkeypatch.setattr(qtargs, 'QLocale', FakeLocale)
+ monkeypatch.setattr(qtargs.core, 'QLocale', FakeLocale)
version_patcher('5.15.3')
config_stub.val.qt.workarounds.locale = True
diff --git a/tests/unit/keyinput/test_keyutils.py b/tests/unit/keyinput/test_keyutils.py
index 748c87299..2a476972a 100644
--- a/tests/unit/keyinput/test_keyutils.py
+++ b/tests/unit/keyinput/test_keyutils.py
@@ -137,7 +137,7 @@ class TestKeyToString:
@pytest.mark.skipif(machinery.IS_QT6, reason="Can't delete enum members on PyQt 6")
def test_missing(self, monkeypatch):
- monkeypatch.delattr(keyutils.Qt, 'Key_AltGr')
+ monkeypatch.delattr(keyutils.core.Qt, 'Key_AltGr')
# We don't want to test the key which is actually missing - we only
# want to know if the mapping still behaves properly.
assert keyutils._key_to_string(core.Qt.Key.Key_A) == 'A'
diff --git a/tests/unit/misc/test_editor.py b/tests/unit/misc/test_editor.py
index 1c04eaad9..93f022277 100644
--- a/tests/unit/misc/test_editor.py
+++ b/tests/unit/misc/test_editor.py
@@ -34,7 +34,7 @@ from qutebrowser.utils import usertypes
@pytest.fixture(autouse=True)
def patch_fake_process(config_stub, monkeypatch, stubs):
- monkeypatch.setattr(editormod.guiprocess, 'QProcess', stubs.FakeProcess)
+ monkeypatch.setattr(editormod.guiprocess.core, 'QProcess', stubs.FakeProcess)
@pytest.fixture(params=[True, False])
diff --git a/tests/unit/misc/test_ipc.py b/tests/unit/misc/test_ipc.py
index 5a7489e38..9e789bb57 100644
--- a/tests/unit/misc/test_ipc.py
+++ b/tests/unit/misc/test_ipc.py
@@ -300,7 +300,7 @@ class TestListen:
def test_error(self, ipc_server, monkeypatch):
"""Simulate an error while listening."""
- monkeypatch.setattr(ipc.QLocalServer, 'removeServer',
+ monkeypatch.setattr(ipc.network.QLocalServer, 'removeServer',
lambda self: True)
monkeypatch.setattr(ipc_server, '_socketname', None)
with pytest.raises(ipc.ListenError):
@@ -308,7 +308,7 @@ class TestListen:
@pytest.mark.posix
def test_in_use(self, qlocalserver, ipc_server, monkeypatch):
- monkeypatch.setattr(ipc.QLocalServer, 'removeServer',
+ monkeypatch.setattr(ipc.network.QLocalServer, 'removeServer',
lambda self: True)
qlocalserver.listen('qute-test')
with pytest.raises(ipc.AddressInUseError):
@@ -654,7 +654,7 @@ class TestSendOrListen:
@pytest.fixture
def qlocalserver_mock(self, mocker):
- m = mocker.patch('qutebrowser.misc.ipc.QLocalServer', autospec=True)
+ m = mocker.patch('qutebrowser.misc.ipc.network.QLocalServer', autospec=True)
m().errorString.return_value = "Error string"
m.SocketOption = network.QLocalServer.SocketOption
m().newConnection = stubs.FakeSignal()
@@ -662,7 +662,7 @@ class TestSendOrListen:
@pytest.fixture
def qlocalsocket_mock(self, mocker):
- m = mocker.patch('qutebrowser.misc.ipc.QLocalSocket', autospec=True)
+ m = mocker.patch('qutebrowser.misc.ipc.network.QLocalSocket', autospec=True)
m().errorString.return_value = "Error string"
m.LocalSocketError = network.QLocalSocket.LocalSocketError
m.LocalSocketState = network.QLocalSocket.LocalSocketState
diff --git a/tests/unit/utils/test_qtutils.py b/tests/unit/utils/test_qtutils.py
index 5cd978d43..d730ebd53 100644
--- a/tests/unit/utils/test_qtutils.py
+++ b/tests/unit/utils/test_qtutils.py
@@ -85,10 +85,10 @@ def test_version_check(monkeypatch, qversion, compiled, pyqt, version, exact,
exact: Use exact comparing (==)
expected: The expected result.
"""
- monkeypatch.setattr(qtutils, 'qVersion', lambda: qversion)
+ monkeypatch.setattr(qtutils.core, 'qVersion', lambda: qversion)
if compiled is not None:
- monkeypatch.setattr(qtutils, 'QT_VERSION_STR', compiled)
- monkeypatch.setattr(qtutils, 'PYQT_VERSION_STR', pyqt)
+ monkeypatch.setattr(qtutils.core, 'QT_VERSION_STR', compiled)
+ monkeypatch.setattr(qtutils.core, 'PYQT_VERSION_STR', pyqt)
compiled_arg = True
else:
compiled_arg = False
@@ -372,7 +372,7 @@ class TestSavefileOpen:
@pytest.fixture
def qsavefile_mock(self, mocker):
"""Mock for QSaveFile."""
- m = mocker.patch('qutebrowser.utils.qtutils.QSaveFile')
+ m = mocker.patch('qutebrowser.utils.qtutils.core.QSaveFile')
instance = m()
yield instance
instance.commit.assert_called_once_with()
diff --git a/tests/unit/utils/test_standarddir.py b/tests/unit/utils/test_standarddir.py
index c61648686..7330d3fd8 100644
--- a/tests/unit/utils/test_standarddir.py
+++ b/tests/unit/utils/test_standarddir.py
@@ -80,7 +80,7 @@ def test_unset_organization(qapp, orgname, expected):
def test_unset_organization_no_qapp(monkeypatch):
"""Without a QApplication, _unset_organization should do nothing."""
- monkeypatch.setattr(standarddir.QApplication, 'instance', lambda: None)
+ monkeypatch.setattr(standarddir.widgets.QApplication, 'instance', lambda: None)
with standarddir._unset_organization():
pass
@@ -99,7 +99,7 @@ def test_fake_mac_config(tmp_path, fake_home_envvar):
@pytest.mark.fake_os('windows')
def test_fake_windows(tmpdir, monkeypatch, what):
"""Make sure the config/data/cache dirs are correct on a fake Windows."""
- monkeypatch.setattr(standarddir.QStandardPaths, 'writableLocation',
+ monkeypatch.setattr(standarddir.core.QStandardPaths, 'writableLocation',
lambda typ: str(tmpdir / APPNAME))
standarddir._init_config(args=None)
@@ -117,7 +117,7 @@ def test_fake_haiku(tmpdir, monkeypatch):
core.QStandardPaths.StandardLocation.AppDataLocation: '',
core.QStandardPaths.StandardLocation.ConfigLocation: str(tmpdir / 'config' / APPNAME),
}
- monkeypatch.setattr(standarddir.QStandardPaths, 'writableLocation',
+ monkeypatch.setattr(standarddir.core.QStandardPaths, 'writableLocation',
locations.get)
monkeypatch.setattr(standarddir.sys, 'platform', 'haiku1')
@@ -132,7 +132,7 @@ class TestWritableLocation:
def test_empty(self, monkeypatch):
"""Test QStandardPaths returning an empty value."""
monkeypatch.setattr(
- 'qutebrowser.utils.standarddir.QStandardPaths.writableLocation',
+ 'qutebrowser.utils.standarddir.core.QStandardPaths.writableLocation',
lambda typ: '')
with pytest.raises(standarddir.EmptyValueError):
standarddir._writable_location(core.QStandardPaths.StandardLocation.AppDataLocation)
@@ -214,7 +214,7 @@ class TestStandardDir:
@pytest.mark.fake_os('windows')
def test_runtimedir_empty_tempdir(self, monkeypatch, tmpdir):
"""With an empty tempdir on non-Linux, we should raise."""
- monkeypatch.setattr(standarddir.QStandardPaths, 'writableLocation',
+ monkeypatch.setattr(standarddir.core.QStandardPaths, 'writableLocation',
lambda typ: '')
with pytest.raises(standarddir.EmptyValueError):
standarddir._init_runtime(args=None)
diff --git a/tests/unit/utils/test_urlutils.py b/tests/unit/utils/test_urlutils.py
index 2ba6b7566..ab2b3b6e3 100644
--- a/tests/unit/utils/test_urlutils.py
+++ b/tests/unit/utils/test_urlutils.py
@@ -89,7 +89,7 @@ def fake_dns(monkeypatch):
fromname_mock will be called without answer being set.
"""
dns = FakeDNS()
- monkeypatch.setattr(urlutils.QHostInfo, 'fromName', dns.fromname_mock)
+ monkeypatch.setattr(urlutils.network.QHostInfo, 'fromName', dns.fromname_mock)
return dns
diff --git a/tests/unit/utils/test_utils.py b/tests/unit/utils/test_utils.py
index 06da02e75..8d57f6098 100644
--- a/tests/unit/utils/test_utils.py
+++ b/tests/unit/utils/test_utils.py
@@ -665,7 +665,7 @@ class TestGetSetClipboard:
@pytest.fixture(autouse=True)
def clipboard_mock(self, mocker):
- m = mocker.patch('qutebrowser.utils.utils.QApplication.clipboard',
+ m = mocker.patch('qutebrowser.utils.utils.widgets.QApplication.clipboard',
autospec=True)
clipboard = m()
clipboard.text.return_value = 'mocked clipboard text'
diff --git a/tests/unit/utils/test_version.py b/tests/unit/utils/test_version.py
index b44a26359..3f2e7d7ad 100644
--- a/tests/unit/utils/test_version.py
+++ b/tests/unit/utils/test_version.py
@@ -1079,7 +1079,7 @@ class TestChromiumVersion:
def defaultProfile(self):
raise AssertionError("Should not be called")
- monkeypatch.setattr(webenginesettings, 'QWebEngineProfile', FakeProfile())
+ monkeypatch.setattr(webenginesettings.webenginecore, 'QWebEngineProfile', FakeProfile())
version.qtwebengine_versions()
@@ -1253,11 +1253,11 @@ def test_version_info(params, stubs, monkeypatch, config_stub):
'platform.python_implementation': lambda: 'PYTHON IMPLEMENTATION',
'platform.python_version': lambda: 'PYTHON VERSION',
'sys.executable': 'EXECUTABLE PATH',
- 'PYQT_VERSION_STR': 'PYQT VERSION',
+ 'core.PYQT_VERSION_STR': 'PYQT VERSION',
'earlyinit.qt_version': lambda: 'QT VERSION',
'_module_versions': lambda: ['MODULE VERSION 1', 'MODULE VERSION 2'],
'_pdfjs_version': lambda: 'PDFJS VERSION',
- 'QSslSocket': FakeQSslSocket('SSL VERSION', params.ssl_support),
+ 'QtNetwork.QSslSocket': FakeQSslSocket('SSL VERSION', params.ssl_support),
'platform.platform': lambda: 'PLATFORM',
'platform.architecture': lambda: ('ARCHITECTURE', ''),
'_os_info': lambda: ['OS INFO 1', 'OS INFO 2'],
@@ -1360,7 +1360,7 @@ def test_version_info(params, stubs, monkeypatch, config_stub):
""".lstrip('\n'))
expected = template.rstrip('\n').format(**substitutions)
- assert version.version_info() == expected
+ assert version.version_info().split() == expected.split()
class TestOpenGLInfo: