summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJimmy <jimmy@spalge.com>2022-04-17 16:56:02 +1200
committerJimmy <jimmy@spalge.com>2022-04-30 19:30:49 +1200
commit81e802faaf08b0e6712b2092741c3e837e9f5af5 (patch)
treea5b6ecb5d7b964ed61c4deceed53e70516792d0b
parentcf1388db20b0f1bc4fb13e5824fb18026a920364 (diff)
downloadqutebrowser-81e802faaf08b0e6712b2092741c3e837e9f5af5.tar.gz
qutebrowser-81e802faaf08b0e6712b2092741c3e837e9f5af5.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.
-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.py7
-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.py12
12 files changed, 30 insertions, 33 deletions
diff --git a/tests/unit/completion/test_completer.py b/tests/unit/completion/test_completer.py
index 637c154b7..2eca88939 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.QtCore, '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 0a96e229c..b5affbd47 100644
--- a/tests/unit/completion/test_models.py
+++ b/tests/unit/completion/test_models.py
@@ -1476,7 +1476,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.QtCore, '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 9aaacae74..a6ef85e84 100644
--- a/tests/unit/config/test_configfiles.py
+++ b/tests/unit/config/test_configfiles.py
@@ -131,7 +131,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.QtCore, 'qVersion', lambda: '5.6.7')
qtwe_version_patcher('7.8.9')
statefile = data_tmpdir / 'state'
@@ -194,7 +194,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.QtCore, 'qVersion', lambda: new_version)
if old_version is not None:
state_writer('qt_version', old_version)
@@ -221,8 +221,7 @@ def test_qtwe_version_changed(state_writer, qtwe_version_patcher,
def test_qtwe_version_changed_webkit(stubs, monkeypatch, state_writer):
- fake = stubs.ImportFake({'qutebrowser.qt.QtWebEngineWidgets': False}, monkeypatch)
- fake.patch()
+ monkeypatch.setattr(configfiles, 'QtWebEngineWidgets', None)
state_writer('qtwe_version', 'no')
state = configfiles.StateConfig()
diff --git a/tests/unit/config/test_qtargs.py b/tests/unit/config/test_qtargs.py
index 2f6625690..93b346d62 100644
--- a/tests/unit/config/test_qtargs.py
+++ b/tests/unit/config/test_qtargs.py
@@ -111,9 +111,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, 'QtWebEngine', None)
parsed = parser.parse_args([])
args = qtargs.qt_args(parsed)
@@ -536,7 +534,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.QtCore, '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 70d7f4aa2..9756290a3 100644
--- a/tests/unit/keyinput/test_keyutils.py
+++ b/tests/unit/keyinput/test_keyutils.py
@@ -139,7 +139,7 @@ class TestKeyToString:
assert keyutils._modifiers_to_string(qt_mod.member) == expected
def test_missing(self, monkeypatch):
- monkeypatch.delattr(keyutils.Qt, 'Key_AltGr')
+ monkeypatch.delattr(keyutils.QtCore.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(QtCore.Qt.Key_A) == 'A'
diff --git a/tests/unit/misc/test_editor.py b/tests/unit/misc/test_editor.py
index ded4c5a8f..dc24cbc32 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.QtCore, '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 a268b924c..7e0ffb98b 100644
--- a/tests/unit/misc/test_ipc.py
+++ b/tests/unit/misc/test_ipc.py
@@ -301,7 +301,7 @@ class TestListen:
def test_error(self, ipc_server, monkeypatch):
"""Simulate an error while listening."""
- monkeypatch.setattr(ipc.QLocalServer, 'removeServer',
+ monkeypatch.setattr(ipc.QtNetwork.QLocalServer, 'removeServer',
lambda self: True)
monkeypatch.setattr(ipc_server, '_socketname', None)
with pytest.raises(ipc.ListenError):
@@ -309,7 +309,7 @@ class TestListen:
@pytest.mark.posix
def test_in_use(self, qlocalserver, ipc_server, monkeypatch):
- monkeypatch.setattr(ipc.QLocalServer, 'removeServer',
+ monkeypatch.setattr(ipc.QtNetwork.QLocalServer, 'removeServer',
lambda self: True)
qlocalserver.listen('qute-test')
with pytest.raises(ipc.AddressInUseError):
@@ -654,14 +654,14 @@ class TestSendOrListen:
@pytest.fixture
def qlocalserver_mock(self, mocker):
- m = mocker.patch('qutebrowser.misc.ipc.QLocalServer', autospec=True)
+ m = mocker.patch('qutebrowser.misc.ipc.QtNetwork.QLocalServer', autospec=True)
m().errorString.return_value = "Error string"
m().newConnection = stubs.FakeSignal()
return m
@pytest.fixture
def qlocalsocket_mock(self, mocker):
- m = mocker.patch('qutebrowser.misc.ipc.QLocalSocket', autospec=True)
+ m = mocker.patch('qutebrowser.misc.ipc.QtNetwork.QLocalSocket', autospec=True)
m().errorString.return_value = "Error string"
for name in ['UnknownSocketError', 'UnconnectedState',
'ConnectionRefusedError', 'ServerNotFoundError',
diff --git a/tests/unit/utils/test_qtutils.py b/tests/unit/utils/test_qtutils.py
index 6b298831b..f868e70f0 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.QtCore, '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.QtCore, 'QT_VERSION_STR', compiled)
+ monkeypatch.setattr(qtutils.QtCore, 'PYQT_VERSION_STR', pyqt)
compiled_arg = True
else:
compiled_arg = False
@@ -373,7 +373,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.QtCore.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 44d7f53d2..e1c0a3f6d 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.QtWidgets.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.QtCore.QStandardPaths, 'writableLocation',
lambda typ: str(tmpdir / APPNAME))
standarddir._init_config(args=None)
@@ -117,7 +117,7 @@ def test_fake_haiku(tmpdir, monkeypatch):
QtCore.QStandardPaths.AppDataLocation: '',
QtCore.QStandardPaths.ConfigLocation: str(tmpdir / 'config' / APPNAME),
}
- monkeypatch.setattr(standarddir.QStandardPaths, 'writableLocation',
+ monkeypatch.setattr(standarddir.QtCore.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.QtCore.QStandardPaths.writableLocation',
lambda typ: '')
with pytest.raises(standarddir.EmptyValueError):
standarddir._writable_location(QtCore.QStandardPaths.AppDataLocation)
@@ -229,7 +229,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.QtCore.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 6a3060573..110be1ee5 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.QtNetwork.QHostInfo, 'fromName', dns.fromname_mock)
return dns
diff --git a/tests/unit/utils/test_utils.py b/tests/unit/utils/test_utils.py
index 1738738a8..94d48ae40 100644
--- a/tests/unit/utils/test_utils.py
+++ b/tests/unit/utils/test_utils.py
@@ -648,7 +648,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.QtWidgets.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 c063efffe..929d69d99 100644
--- a/tests/unit/utils/test_version.py
+++ b/tests/unit/utils/test_version.py
@@ -1078,7 +1078,7 @@ class TestChromiumVersion:
def defaultProfile(self):
raise AssertionError("Should not be called")
- monkeypatch.setattr(webenginesettings, 'QWebEngineProfile', FakeProfile())
+ monkeypatch.setattr(webenginesettings.QtWebEngineWidgets, 'QWebEngineProfile', FakeProfile())
version.qtwebengine_versions()
@@ -1097,7 +1097,7 @@ class TestChromiumVersion:
@pytest.fixture
def patch_old_pyqt(self, monkeypatch):
"""Simulate an old PyQt without PYQT_WEBENGINE_VERSION_STR."""
- monkeypatch.setattr(version, 'PYQT_WEBENGINE_VERSION_STR', None)
+ monkeypatch.setattr(version.QtWebEngine, 'PYQT_WEBENGINE_VERSION_STR', None)
@pytest.fixture
def patch_no_importlib(self, monkeypatch, stubs):
@@ -1223,18 +1223,18 @@ 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',
+ 'QtCore.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'],
'_path_info': lambda: {'PATH DESC': 'PATH NAME'},
'objects.qapp': (stubs.FakeQApplication(style='STYLE', platform_name='PLATFORM')
if params.qapp else None),
- 'QLibraryInfo.location': (lambda _loc: 'QT PATH'),
+ 'QtCore.QLibraryInfo.location': (lambda _loc: 'QT PATH'),
'sql.version': lambda: 'SQLITE VERSION',
'_uptime': lambda: datetime.timedelta(hours=1, minutes=23, seconds=45),
'config.instance.yaml_loaded': params.autoconfig_loaded,
@@ -1330,7 +1330,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: