From ac9d67cce0dbecdde14c474db855243e9746ba04 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Thu, 26 Aug 2021 16:47:12 +0200 Subject: Automatically rewrite enums See #5904 --- tests/end2end/fixtures/notificationserver.py | 10 +- tests/end2end/fixtures/quteprocess.py | 2 +- tests/end2end/fixtures/test_testprocess.py | 2 +- tests/end2end/fixtures/testprocess.py | 4 +- tests/end2end/test_invocations.py | 4 +- tests/helpers/fixtures.py | 4 +- tests/helpers/stubs.py | 2 +- tests/unit/browser/test_pdfjs.py | 2 +- tests/unit/browser/webengine/test_webenginetab.py | 12 +- .../browser/webkit/network/test_networkreply.py | 16 +- tests/unit/browser/webkit/network/test_pac.py | 6 +- tests/unit/browser/webkit/test_certificateerror.py | 6 +- tests/unit/browser/webkit/test_webkitelem.py | 2 +- tests/unit/completion/test_completiondelegate.py | 8 +- tests/unit/completion/test_models.py | 4 +- tests/unit/components/test_braveadblock.py | 2 +- tests/unit/config/test_config.py | 2 +- tests/unit/config/test_configtypes.py | 44 +-- .../position_caret/test_position_caret.py | 6 +- tests/unit/javascript/test_js_execution.py | 12 +- tests/unit/keyinput/key_data.py | 2 +- tests/unit/keyinput/test_basekeyparser.py | 86 +++--- tests/unit/keyinput/test_bindingtrie.py | 28 +- tests/unit/keyinput/test_keyutils.py | 314 ++++++++++----------- tests/unit/keyinput/test_modeman.py | 8 +- tests/unit/keyinput/test_modeparsers.py | 22 +- tests/unit/mainwindow/statusbar/test_textbase.py | 8 +- tests/unit/mainwindow/test_messageview.py | 8 +- tests/unit/mainwindow/test_prompt.py | 8 +- tests/unit/misc/test_editor.py | 22 +- tests/unit/misc/test_guiprocess.py | 8 +- tests/unit/misc/test_ipc.py | 50 ++-- tests/unit/misc/test_miscwidgets.py | 16 +- tests/unit/misc/test_msgbox.py | 16 +- tests/unit/misc/test_sql.py | 4 +- tests/unit/utils/test_debug.py | 22 +- tests/unit/utils/test_error.py | 4 +- tests/unit/utils/test_qtutils.py | 98 +++---- tests/unit/utils/test_standarddir.py | 8 +- tests/unit/utils/test_urlutils.py | 16 +- tests/unit/utils/test_utils.py | 2 +- 41 files changed, 450 insertions(+), 450 deletions(-) (limited to 'tests') diff --git a/tests/end2end/fixtures/notificationserver.py b/tests/end2end/fixtures/notificationserver.py index abadde794..d11ab616f 100644 --- a/tests/end2end/fixtures/notificationserver.py +++ b/tests/end2end/fixtures/notificationserver.py @@ -82,7 +82,7 @@ class TestNotificationServer(QObject): notification.DBusNotificationAdapter.PATH, notification.DBusNotificationAdapter.INTERFACE, self, - QDBusConnection.ExportAllSlots, + QDBusConnection.RegisterOption.ExportAllSlots, ) return True @@ -151,7 +151,7 @@ class TestNotificationServer(QObject): assert channel_count == (4 if has_alpha else 3) assert bytes_per_line >= width * channel_count - qimage_format = QImage.Format_RGBA8888 if has_alpha else QImage.Format_RGB888 + qimage_format = QImage.Format.Format_RGBA8888 if has_alpha else QImage.Format.Format_RGB888 img = QImage(data, width, height, bytes_per_line, qimage_format) assert not img.isNull() assert img.width() == width @@ -196,7 +196,7 @@ class TestNotificationServer(QObject): @pyqtSlot(QDBusMessage, result="uint") def Notify(self, dbus_message: QDBusMessage) -> QDBusArgument: assert dbus_message.signature() == 'susssasa{sv}i' - assert dbus_message.type() == QDBusMessage.MethodCallMessage + assert dbus_message.type() == QDBusMessage.MessageType.MethodCallMessage message = self._parse_notify_args(*dbus_message.arguments()) @@ -213,7 +213,7 @@ class TestNotificationServer(QObject): def GetCapabilities(self, message: QDBusMessage) -> List[str]: assert not message.signature() assert not message.arguments() - assert message.type() == QDBusMessage.MethodCallMessage + assert message.type() == QDBusMessage.MessageType.MethodCallMessage capabilities = ["actions", "x-kde-origin-name"] if self.supports_body_markup: @@ -224,7 +224,7 @@ class TestNotificationServer(QObject): @pyqtSlot(QDBusMessage) def CloseNotification(self, dbus_message: QDBusMessage) -> None: assert dbus_message.signature() == 'u' - assert dbus_message.type() == QDBusMessage.MethodCallMessage + assert dbus_message.type() == QDBusMessage.MessageType.MethodCallMessage message_id = dbus_message.arguments()[0] self.messages[message_id].closed_via_web = True diff --git a/tests/end2end/fixtures/quteprocess.py b/tests/end2end/fixtures/quteprocess.py index 1552f51b4..0420548e2 100644 --- a/tests/end2end/fixtures/quteprocess.py +++ b/tests/end2end/fixtures/quteprocess.py @@ -853,7 +853,7 @@ class QuteProc(testprocess.Process): # We really need the same representation that the webview uses in # its __repr__ - url = utils.elide(qurl.toDisplayString(QUrl.EncodeUnicode), 100) + url = utils.elide(qurl.toDisplayString(QUrl.ComponentFormattingOption.EncodeUnicode), 100) assert url pattern = re.compile( diff --git a/tests/end2end/fixtures/test_testprocess.py b/tests/end2end/fixtures/test_testprocess.py index 0cf5e6041..1bcdb4a3c 100644 --- a/tests/end2end/fixtures/test_testprocess.py +++ b/tests/end2end/fixtures/test_testprocess.py @@ -53,7 +53,7 @@ class PythonProcess(testprocess.Process): def __init__(self, request): super().__init__(request) - self.proc.setReadChannel(QProcess.StandardOutput) + self.proc.setReadChannel(QProcess.ProcessChannel.StandardOutput) self.code = None def _parse_line(self, line): diff --git a/tests/end2end/fixtures/testprocess.py b/tests/end2end/fixtures/testprocess.py index c74a1a2b8..5a623fb7c 100644 --- a/tests/end2end/fixtures/testprocess.py +++ b/tests/end2end/fixtures/testprocess.py @@ -151,7 +151,7 @@ class Process(QObject): self._invalid = [] self._data = [] self.proc = QProcess() - self.proc.setReadChannel(QProcess.StandardError) + self.proc.setReadChannel(QProcess.ProcessChannel.StandardError) self.exit_expected = None # Not started at all yet def _log(self, line): @@ -325,7 +325,7 @@ class Process(QObject): def is_running(self): """Check if the process is currently running.""" - return self.proc.state() == QProcess.Running + return self.proc.state() == QProcess.ProcessState.Running def _match_data(self, value, expected): """Helper for wait_for to match a given value. diff --git a/tests/end2end/test_invocations.py b/tests/end2end/test_invocations.py index 3b8b2f1c8..c3219c701 100644 --- a/tests/end2end/test_invocations.py +++ b/tests/end2end/test_invocations.py @@ -262,7 +262,7 @@ def test_version(request): # can't use quteproc_new here because it's confused by # early process termination proc = QProcess() - proc.setProcessChannelMode(QProcess.SeparateChannels) + proc.setProcessChannelMode(QProcess.ProcessChannelMode.SeparateChannels) proc.start(sys.executable, args) ok = proc.waitForStarted(2000) @@ -275,7 +275,7 @@ def test_version(request): print(stderr) assert ok - assert proc.exitStatus() == QProcess.NormalExit + assert proc.exitStatus() == QProcess.ExitStatus.NormalExit match = re.search(r'^qutebrowser\s+v\d+(\.\d+)', stdout, re.MULTILINE) assert match is not None diff --git a/tests/helpers/fixtures.py b/tests/helpers/fixtures.py index 82159233c..cd58fb3e4 100644 --- a/tests/helpers/fixtures.py +++ b/tests/helpers/fixtures.py @@ -126,7 +126,7 @@ class FakeStatusBar(QWidget): self.hbox = QHBoxLayout(self) self.hbox.addStretch() self.hbox.setContentsMargins(0, 0, 0, 0) - self.setAttribute(Qt.WA_StyledBackground, True) + self.setAttribute(Qt.WidgetAttribute.WA_StyledBackground, True) self.setStyleSheet('background-color: red;') def minimumSizeHint(self): @@ -434,7 +434,7 @@ def qnam(qapp): """Session-wide QNetworkAccessManager.""" from PyQt6.QtNetwork import QNetworkAccessManager nam = QNetworkAccessManager() - nam.setNetworkAccessible(QNetworkAccessManager.NotAccessible) + nam.setNetworkAccessible(QNetworkAccessManager.NetworkAccessibility.NotAccessible) return nam diff --git a/tests/helpers/stubs.py b/tests/helpers/stubs.py index e4cf9bcc7..233fe848b 100644 --- a/tests/helpers/stubs.py +++ b/tests/helpers/stubs.py @@ -135,7 +135,7 @@ class FakeNetworkReply: """QNetworkReply stub which provides a Content-Disposition header.""" KNOWN_HEADERS = { - QNetworkRequest.ContentTypeHeader: 'Content-Type', + QNetworkRequest.KnownHeaders.ContentTypeHeader: 'Content-Type', } def __init__(self, headers=None, url=None): diff --git a/tests/unit/browser/test_pdfjs.py b/tests/unit/browser/test_pdfjs.py index eb3317d01..611bdba3e 100644 --- a/tests/unit/browser/test_pdfjs.py +++ b/tests/unit/browser/test_pdfjs.py @@ -52,7 +52,7 @@ def test_generate_pdfjs_page(available, snippet, monkeypatch): assert snippet in content -# Note that we got double protection, once because we use QUrl.FullyEncoded and +# Note that we got double protection, once because we use QUrl.ComponentFormattingOption.FullyEncoded and # because we use qutebrowser.utils.javascript.to_js. Characters like " are # already replaced by QUrl. @pytest.mark.parametrize('filename, expected', [ diff --git a/tests/unit/browser/webengine/test_webenginetab.py b/tests/unit/browser/webengine/test_webenginetab.py index 92705a3aa..c5712571b 100644 --- a/tests/unit/browser/webengine/test_webenginetab.py +++ b/tests/unit/browser/webengine/test_webenginetab.py @@ -131,17 +131,17 @@ class TestWebengineScripts: scripts_helper.inject(scripts) script = scripts_helper.get_script() - assert script.injectionPoint() == QWebEngineScript.DocumentReady + assert script.injectionPoint() == QWebEngineScript.InjectionPoint.DocumentReady @pytest.mark.parametrize('run_at, expected', [ # UserScript::DocumentElementCreation - ('document-start', QWebEngineScript.DocumentCreation), + ('document-start', QWebEngineScript.InjectionPoint.DocumentCreation), # UserScript::DocumentLoadFinished - ('document-end', QWebEngineScript.DocumentReady), + ('document-end', QWebEngineScript.InjectionPoint.DocumentReady), # UserScript::AfterLoad - ('document-idle', QWebEngineScript.Deferred), + ('document-idle', QWebEngineScript.InjectionPoint.Deferred), # default according to https://wiki.greasespot.net/Metadata_Block#.40run-at - (None, QWebEngineScript.DocumentReady), + (None, QWebEngineScript.InjectionPoint.DocumentReady), ]) def test_greasemonkey_run_at_values(self, scripts_helper, run_at, expected): if run_at is None: @@ -207,7 +207,7 @@ class TestWebengineScripts: def test_notification_permission_workaround(): """Make sure the value for QWebEnginePage::Notifications is correct.""" try: - notifications = QWebEnginePage.Notifications + notifications = QWebEnginePage.Feature.Notifications except AttributeError: pytest.skip("No Notifications member") diff --git a/tests/unit/browser/webkit/network/test_networkreply.py b/tests/unit/browser/webkit/network/test_networkreply.py index a64f45589..8e3320e9c 100644 --- a/tests/unit/browser/webkit/network/test_networkreply.py +++ b/tests/unit/browser/webkit/network/test_networkreply.py @@ -38,11 +38,11 @@ class TestFixedDataNetworkReply: reply = networkreply.FixedDataNetworkReply(req, b'', 'test/foo') assert reply.request() == req assert reply.url() == req.url() - assert reply.openMode() == QIODevice.ReadOnly - assert reply.header(QNetworkRequest.ContentTypeHeader) == 'test/foo' - http_code = reply.attribute(QNetworkRequest.HttpStatusCodeAttribute) + assert reply.openMode() == QIODevice.OpenModeFlag.ReadOnly + assert reply.header(QNetworkRequest.KnownHeaders.ContentTypeHeader) == 'test/foo' + http_code = reply.attribute(QNetworkRequest.Attribute.HttpStatusCodeAttribute) http_reason = reply.attribute( - QNetworkRequest.HttpReasonPhraseAttribute) + QNetworkRequest.Attribute.HttpReasonPhraseAttribute) assert http_code == 200 assert http_reason == 'OK' assert reply.isFinished() @@ -76,7 +76,7 @@ class TestFixedDataNetworkReply: def test_error_network_reply(qtbot, req): reply = networkreply.ErrorNetworkReply( - req, "This is an error", QNetworkReply.UnknownNetworkError) + req, "This is an error", QNetworkReply.NetworkError.UnknownNetworkError) with qtbot.wait_signals([reply.error, reply.finished], order='strict'): pass @@ -84,12 +84,12 @@ def test_error_network_reply(qtbot, req): reply.abort() # shouldn't do anything assert reply.request() == req assert reply.url() == req.url() - assert reply.openMode() == QIODevice.ReadOnly + assert reply.openMode() == QIODevice.OpenModeFlag.ReadOnly assert reply.isFinished() assert not reply.isRunning() assert reply.bytesAvailable() == 0 assert reply.readData(1) == b'' - assert reply.error() == QNetworkReply.UnknownNetworkError + assert reply.error() == QNetworkReply.NetworkError.UnknownNetworkError assert reply.errorString() == "This is an error" @@ -97,5 +97,5 @@ def test_redirect_network_reply(): url = QUrl('https://www.example.com/') reply = networkreply.RedirectNetworkReply(url) assert reply.readData(1) == b'' - assert reply.attribute(QNetworkRequest.RedirectionTargetAttribute) == url + assert reply.attribute(QNetworkRequest.Attribute.RedirectionTargetAttribute) == url reply.abort() # shouldn't do anything diff --git a/tests/unit/browser/webkit/network/test_pac.py b/tests/unit/browser/webkit/network/test_pac.py index 8849e011c..a13cbba4e 100644 --- a/tests/unit/browser/webkit/network/test_pac.py +++ b/tests/unit/browser/webkit/network/test_pac.py @@ -44,11 +44,11 @@ def _pac_common_test(test_str): res = pac.PACResolver(fun_str) proxies = res.resolve(QNetworkProxyQuery(QUrl("https://example.com/test"))) assert len(proxies) == 3 - assert proxies[0].type() == QNetworkProxy.NoProxy - assert proxies[1].type() == QNetworkProxy.HttpProxy + assert proxies[0].type() == QNetworkProxy.ProxyType.NoProxy + assert proxies[1].type() == QNetworkProxy.ProxyType.HttpProxy assert proxies[1].hostName() == "127.0.0.1" assert proxies[1].port() == 8080 - assert proxies[2].type() == QNetworkProxy.Socks5Proxy + assert proxies[2].type() == QNetworkProxy.ProxyType.Socks5Proxy assert proxies[2].hostName() == "192.168.1.1" assert proxies[2].port() == 4444 diff --git a/tests/unit/browser/webkit/test_certificateerror.py b/tests/unit/browser/webkit/test_certificateerror.py index 0f298a030..e1165ca67 100644 --- a/tests/unit/browser/webkit/test_certificateerror.py +++ b/tests/unit/browser/webkit/test_certificateerror.py @@ -34,13 +34,13 @@ class FakeError: @pytest.mark.parametrize('errors, expected', [ ( - [QSslError(QSslError.UnableToGetIssuerCertificate)], + [QSslError(QSslError.SslError.UnableToGetIssuerCertificate)], ['

The issuer certificate could not be found

'], ), ( [ - QSslError(QSslError.UnableToGetIssuerCertificate), - QSslError(QSslError.UnableToDecryptCertificateSignature), + QSslError(QSslError.SslError.UnableToGetIssuerCertificate), + QSslError(QSslError.SslError.UnableToDecryptCertificateSignature), ], [ '