summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortoofar <toofar@spalge.com>2023-02-06 18:53:56 +1300
committertoofar <toofar@spalge.com>2023-02-06 18:53:56 +1300
commitff8dbc45805013b5a119a0d6b2c943308faeca8e (patch)
treec3c3d2337d797267b2c248dbbfae85c24adfbb1c
parent7dacc89d2ad4cf31010f69e2a40847d7a2b34fc4 (diff)
downloadqutebrowser-ff8dbc45805013b5a119a0d6b2c943308faeca8e.tar.gz
qutebrowser-ff8dbc45805013b5a119a0d6b2c943308faeca8e.zip
lint: broad-exception-raised
Mostly pretty lazy fixes. Most of the places in the tests we were already matching on error message, a couple of places we weren't. The tick-tock one was the only one that wasn't being used right where it was raised. Some of them I just changed to RuntimeError because it was shorter than adding the pylint directive.
-rw-r--r--qutebrowser/components/misccommands.py1
-rw-r--r--qutebrowser/utils/standarddir.py6
-rwxr-xr-xscripts/dev/build_release.py5
-rwxr-xr-xscripts/dev/src2asciidoc.py1
-rwxr-xr-xscripts/dev/update_3rdparty.py2
-rw-r--r--tests/conftest.py2
-rw-r--r--tests/end2end/fixtures/quteprocess.py2
-rw-r--r--tests/helpers/stubs.py6
-rw-r--r--tests/unit/browser/test_history.py2
-rw-r--r--tests/unit/components/test_misccommands.py2
-rw-r--r--tests/unit/extensions/test_loader.py2
-rw-r--r--tests/unit/misc/test_ipc.py2
-rw-r--r--tests/unit/misc/test_sql.py6
-rw-r--r--tests/unit/utils/test_utils.py10
14 files changed, 32 insertions, 17 deletions
diff --git a/qutebrowser/components/misccommands.py b/qutebrowser/components/misccommands.py
index bf9f80745..98eb5c8f4 100644
--- a/qutebrowser/components/misccommands.py
+++ b/qutebrowser/components/misccommands.py
@@ -405,6 +405,7 @@ def debug_crash(typ: str = 'exception') -> None:
Args:
typ: either 'exception' or 'segfault'.
"""
+ # pylint: disable=broad-exception-raised
if typ == 'segfault':
os.kill(os.getpid(), signal.SIGSEGV)
raise Exception("Segfault failed (wat.)")
diff --git a/qutebrowser/utils/standarddir.py b/qutebrowser/utils/standarddir.py
index c753e9de6..60d14dc79 100644
--- a/qutebrowser/utils/standarddir.py
+++ b/qutebrowser/utils/standarddir.py
@@ -330,8 +330,10 @@ def _create(path: str) -> None:
for k, v in os.environ.items():
if k == 'HOME' or k.startswith('XDG_'):
log.init.debug(f"{k} = {v}")
- raise Exception("Trying to create directory inside /home during "
- "tests, this should not happen.")
+ raise AssertionError(
+ "Trying to create directory inside /home during "
+ "tests, this should not happen."
+ )
os.makedirs(path, 0o700, exist_ok=True)
diff --git a/scripts/dev/build_release.py b/scripts/dev/build_release.py
index 39c730472..18658f920 100755
--- a/scripts/dev/build_release.py
+++ b/scripts/dev/build_release.py
@@ -223,7 +223,7 @@ def smoke_test(executable: pathlib.Path, debug: bool) -> None:
"",
]
- raise Exception("\n".join(lines))
+ raise Exception("\n".join(lines)) # pylint: disable=broad-exception-raised
def verify_windows_exe(exe_path: pathlib.Path) -> None:
@@ -598,7 +598,7 @@ def read_github_token(
if optional:
return None
else:
- raise Exception(
+ raise Exception( # pylint: disable=broad-exception-raised
"GitHub token needed, but ~/.gh_token not found, "
"and --gh-token not given.")
@@ -614,6 +614,7 @@ def github_upload(artifacts: List[Artifact], tag: str, gh_token: str) -> None:
tag: The name of the release tag
gh_token: The GitHub token to use
"""
+ # pylint: disable=broad-exception-raised
import github3
import github3.exceptions
utils.print_title("Uploading to github...")
diff --git a/scripts/dev/src2asciidoc.py b/scripts/dev/src2asciidoc.py
index 1267a278a..732b01f26 100755
--- a/scripts/dev/src2asciidoc.py
+++ b/scripts/dev/src2asciidoc.py
@@ -499,6 +499,7 @@ def _format_block(filename, what, data):
what: What to change (authors, options, etc.)
data; A list of strings which is the new data.
"""
+ # pylint: disable=broad-exception-raised
what = what.upper()
oshandle, tmpname = tempfile.mkstemp()
try:
diff --git a/scripts/dev/update_3rdparty.py b/scripts/dev/update_3rdparty.py
index b1991fa1f..71d7ae7b5 100755
--- a/scripts/dev/update_3rdparty.py
+++ b/scripts/dev/update_3rdparty.py
@@ -66,6 +66,7 @@ def download_nsis_plugins():
def find_pdfjs_asset(assets, legacy):
"""Find the PDF.js asset to use."""
+ # pylint: disable=broad-exception-raised
for asset in assets:
name = asset["name"]
if (
@@ -82,6 +83,7 @@ def get_latest_pdfjs_url(gh_token, legacy):
Returns a (version, url)-tuple.
"""
+ # pylint: disable=broad-exception-raised
github_api = 'https://api.github.com'
endpoint = 'repos/mozilla/pdf.js/releases/latest'
request = urllib.request.Request(f'{github_api}/{endpoint}')
diff --git a/tests/conftest.py b/tests/conftest.py
index 65f76aacc..193b5bb5f 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -289,7 +289,7 @@ def pytest_report_header(config):
@pytest.fixture(scope='session', autouse=True)
def check_display(request):
if utils.is_linux and not os.environ.get('DISPLAY', ''):
- raise Exception("No display and no Xvfb available!")
+ raise RuntimeError("No display and no Xvfb available!")
@pytest.fixture(autouse=True)
diff --git a/tests/end2end/fixtures/quteprocess.py b/tests/end2end/fixtures/quteprocess.py
index 6e47814fd..6b99d5bf0 100644
--- a/tests/end2end/fixtures/quteprocess.py
+++ b/tests/end2end/fixtures/quteprocess.py
@@ -523,7 +523,7 @@ class QuteProc(testprocess.Process):
profile = self.request.config.getoption('--qute-profile-subprocs')
if hasattr(sys, 'frozen'):
if profile:
- raise Exception("Can't profile with sys.frozen!")
+ raise RuntimeError("Can't profile with sys.frozen!")
executable = str(pathlib.Path(sys.executable).parent / 'qutebrowser')
args = []
else:
diff --git a/tests/helpers/stubs.py b/tests/helpers/stubs.py
index 6998958b8..b71e0f3cf 100644
--- a/tests/helpers/stubs.py
+++ b/tests/helpers/stubs.py
@@ -630,6 +630,10 @@ class FakeDownloadManager:
return False
+class FakeHistoryTick(Exception):
+ pass
+
+
class FakeHistoryProgress:
"""Fake for a WebHistoryProgress object."""
@@ -648,7 +652,7 @@ class FakeHistoryProgress:
def tick(self):
if self._raise_on_tick:
- raise Exception('tick-tock')
+ raise FakeHistoryTick('tick-tock')
self._value += 1
def finish(self):
diff --git a/tests/unit/browser/test_history.py b/tests/unit/browser/test_history.py
index 51a9effb8..268f21a08 100644
--- a/tests/unit/browser/test_history.py
+++ b/tests/unit/browser/test_history.py
@@ -471,7 +471,7 @@ class TestRebuild:
# Trigger a completion rebuild
monkeypatch.setattr(web_history.database, 'user_version_changed', lambda: True)
- with pytest.raises(Exception, match='tick-tock'):
+ with pytest.raises(stubs.FakeHistoryTick, match='tick-tock'):
history.WebHistory(web_history.database, progress=progress)
assert web_history.metainfo['force_rebuild']
diff --git a/tests/unit/components/test_misccommands.py b/tests/unit/components/test_misccommands.py
index 342b39f64..3a4118fb4 100644
--- a/tests/unit/components/test_misccommands.py
+++ b/tests/unit/components/test_misccommands.py
@@ -78,7 +78,7 @@ def test_debug_trace_exception(mocker):
"""Check that exceptions thrown by hunter.trace are handled."""
def _mock_exception():
"""Side effect for testing debug_trace's reraise."""
- raise Exception('message')
+ raise Exception('message') # pylint: disable=broad-exception-raised
hunter_mock = mocker.patch.object(misccommands, 'hunter')
hunter_mock.trace.side_effect = _mock_exception
diff --git a/tests/unit/extensions/test_loader.py b/tests/unit/extensions/test_loader.py
index e9b8055aa..488c3edc2 100644
--- a/tests/unit/extensions/test_loader.py
+++ b/tests/unit/extensions/test_loader.py
@@ -91,7 +91,7 @@ class _Hook:
def __call__(self, *args):
if self.raising:
- raise Exception("Should not be called!")
+ raise AssertionError("Should not be called!")
self.called = True
diff --git a/tests/unit/misc/test_ipc.py b/tests/unit/misc/test_ipc.py
index 51d7c6343..eea4f9bb5 100644
--- a/tests/unit/misc/test_ipc.py
+++ b/tests/unit/misc/test_ipc.py
@@ -262,7 +262,7 @@ class TestSocketName:
elif utils.is_linux:
pass
else:
- raise Exception("Unexpected platform!")
+ raise AssertionError("Unexpected platform!")
class TestExceptions:
diff --git a/tests/unit/misc/test_sql.py b/tests/unit/misc/test_sql.py
index 80ab7513c..42207177e 100644
--- a/tests/unit/misc/test_sql.py
+++ b/tests/unit/misc/test_sql.py
@@ -406,7 +406,9 @@ class TestTransaction:
with database.transaction():
my_table.insert({'column': 1})
my_table.insert({'column': 2})
- raise Exception('something went horribly wrong')
- except Exception:
+ raise RuntimeError(
+ 'something went horribly wrong and the transaction will be aborted'
+ )
+ except RuntimeError:
pass
assert database.query('select count(*) from my_table').run().value() == 0
diff --git a/tests/unit/utils/test_utils.py b/tests/unit/utils/test_utils.py
index aa063b7c6..4f81783c2 100644
--- a/tests/unit/utils/test_utils.py
+++ b/tests/unit/utils/test_utils.py
@@ -425,7 +425,7 @@ class TestPreventExceptions:
@utils.prevent_exceptions(42)
def func_raising(self):
- raise Exception
+ raise RuntimeError("something went wrong")
def test_raising(self, caplog):
"""Test with a raising function."""
@@ -434,6 +434,7 @@ class TestPreventExceptions:
assert ret == 42
expected = 'Error in test_utils.TestPreventExceptions.func_raising'
assert caplog.messages == [expected]
+ assert caplog.records[0].exc_info[1].args[0] == "something went wrong"
@utils.prevent_exceptions(42)
def func_not_raising(self):
@@ -448,7 +449,7 @@ class TestPreventExceptions:
@utils.prevent_exceptions(42, True)
def func_predicate_true(self):
- raise Exception("its-true")
+ raise RuntimeError("its-true")
def test_predicate_true(self, caplog):
"""Test with a True predicate."""
@@ -456,15 +457,16 @@ class TestPreventExceptions:
ret = self.func_predicate_true()
assert ret == 42
assert len(caplog.records) == 1
+ assert caplog.records[0].exc_info[1].args[0] == "its-true"
@utils.prevent_exceptions(42, False)
def func_predicate_false(self):
- raise Exception("its-false")
+ raise RuntimeError("its-false")
def test_predicate_false(self, caplog):
"""Test with a False predicate."""
with caplog.at_level(logging.ERROR, 'misc'):
- with pytest.raises(Exception, match="its-false"):
+ with pytest.raises(RuntimeError, match="its-false"):
self.func_predicate_false()
assert not caplog.records