chore: minor linting

A few minor changes about when to use `==` and when to use `is`.
Basically, this uses `is` for booleans, and `==` for other values.

With a few other changes about coding style which was enforced by
`ruff`.
This commit is contained in:
Alexis Métaireau 2024-05-22 15:18:53 +02:00
parent cbbd6afcc1
commit 65a8827daa
No known key found for this signature in database
GPG key ID: C65C7A89A8FFC56E
6 changed files with 23 additions and 24 deletions

View file

@ -95,7 +95,7 @@ class SuffixNotApplicableException(DocumentFilenameException):
def handle_document_errors(func: F) -> F:
"""Log document-related errors and exit gracefully."""
"""Decorator to log document-related errors and exit gracefully."""
@functools.wraps(func)
def wrapper(*args, **kwargs): # type: ignore

View file

@ -55,7 +55,7 @@ class IsolationProvider(ABC):
"""
def __init__(self) -> None:
if getattr(sys, "dangerzone_dev", False) == True:
if getattr(sys, "dangerzone_dev", False) is True:
self.proc_stderr = subprocess.PIPE
else:
self.proc_stderr = subprocess.DEVNULL

View file

@ -51,7 +51,7 @@ class Qubes(IsolationProvider):
return 1
def start_doc_to_pixels_proc(self, document: Document) -> subprocess.Popen:
dev_mode = getattr(sys, "dangerzone_dev", False) == True
dev_mode = getattr(sys, "dangerzone_dev", False) is True
if dev_mode:
# Use dz.ConvertDev RPC call instead, if we are in development mode.
# Basically, the change is that we also transfer the necessary Python

View file

@ -58,7 +58,7 @@ def test_default_menu(
toggle_updates_action.trigger()
assert not toggle_updates_action.isChecked()
assert updater.dangerzone.settings.get("updater_check") == False
assert updater.dangerzone.settings.get("updater_check") is False
def test_no_update(
@ -365,13 +365,13 @@ def test_change_document_button(
file_dialog_mock.accept()
# Then two dialogs should have been open
assert file_dialog_mock.exec.call_count is 2
assert file_dialog_mock.selectedFiles.call_count is 2
assert file_dialog_mock.exec.call_count == 2
assert file_dialog_mock.selectedFiles.call_count == 2
# Then the final document should be only the second one
docs = [
doc.input_filename
for doc in content_widget.dangerzone.get_unconverted_documents()
]
assert len(docs) is 1
assert len(docs) == 1
assert docs[0] == str(tmp_sample_doc)

View file

@ -114,7 +114,7 @@ def test_linux_no_check(updater: UpdaterThread, monkeypatch: MonkeyPatch) -> Non
# XXX: Simulate Dangerzone installed via package manager.
monkeypatch.delattr(sys, "dangerzone_dev")
assert updater.should_check_for_updates() == False
assert updater.should_check_for_updates() is False
assert updater.dangerzone.settings.get_updater_settings() == expected_settings
@ -129,7 +129,7 @@ def test_user_prompts(
expected_settings = default_updater_settings()
expected_settings["updater_check"] = None
expected_settings["updater_last_check"] = 0
assert updater.should_check_for_updates() == False
assert updater.should_check_for_updates() is False
assert updater.dangerzone.settings.get_updater_settings() == expected_settings
# Second run
@ -143,14 +143,14 @@ def test_user_prompts(
# Check disabling update checks.
prompt_mock().launch.return_value = False # type: ignore [attr-defined]
expected_settings["updater_check"] = False
assert updater.should_check_for_updates() == False
assert updater.should_check_for_updates() is False
assert updater.dangerzone.settings.get_updater_settings() == expected_settings
# Reset the "updater_check" field and check enabling update checks.
updater.dangerzone.settings.set("updater_check", None)
prompt_mock().launch.return_value = True # type: ignore [attr-defined]
expected_settings["updater_check"] = True
assert updater.should_check_for_updates() == True
assert updater.should_check_for_updates() is True
assert updater.dangerzone.settings.get_updater_settings() == expected_settings
# Third run
@ -232,7 +232,7 @@ def test_update_checks_cooldown(updater: UpdaterThread, mocker: MockerFixture) -
timestamp_mock.return_value = curtime
report = updater.check_for_updates()
assert cooldown_spy.spy_return == False
assert cooldown_spy.spy_return is False
assert updater.dangerzone.settings.get("updater_last_check") == curtime
assert_report_equal(report, UpdateReport("99.9.9", "<p>changelog</p>"))
@ -246,7 +246,7 @@ def test_update_checks_cooldown(updater: UpdaterThread, mocker: MockerFixture) -
updater.dangerzone.settings.set("updater_latest_changelog", None)
report = updater.check_for_updates()
assert cooldown_spy.spy_return == True
assert cooldown_spy.spy_return is True
assert updater.dangerzone.settings.get("updater_last_check") == curtime - 1
assert_report_equal(report, UpdateReport())
@ -257,7 +257,7 @@ def test_update_checks_cooldown(updater: UpdaterThread, mocker: MockerFixture) -
requests_mock.side_effect = None # type: ignore [attr-defined]
report = updater.check_for_updates()
assert cooldown_spy.spy_return == False
assert cooldown_spy.spy_return is False
assert updater.dangerzone.settings.get("updater_last_check") == curtime
assert_report_equal(report, UpdateReport("99.9.9", "<p>changelog</p>"))
@ -272,7 +272,7 @@ def test_update_checks_cooldown(updater: UpdaterThread, mocker: MockerFixture) -
requests_mock.side_effect = Exception("failed") # type: ignore [attr-defined]
report = updater.check_for_updates()
assert cooldown_spy.spy_return == False
assert cooldown_spy.spy_return is False
assert updater.dangerzone.settings.get("updater_last_check") == curtime
error_msg = (
f"Encountered an exception while checking {updater.GH_RELEASE_URL}: failed"
@ -388,7 +388,7 @@ def test_update_check_prompt(
QtCore.QTimer.singleShot(500, check_button_labels)
res = qt_updater.should_check_for_updates()
assert res == True
assert res is True
# Test 2 - Check that when the user chooses to enable update checks, we
# store that decision in the settings.
@ -401,8 +401,8 @@ def test_update_check_prompt(
QtCore.QTimer.singleShot(500, click_ok)
res = qt_updater.should_check_for_updates()
assert res == True
assert qt_updater.check == True
assert res is True
assert qt_updater.check is True
# Test 3 - Same as the previous test, but check that clicking on cancel stores the
# opposite decision.
@ -415,8 +415,8 @@ def test_update_check_prompt(
QtCore.QTimer.singleShot(500, click_cancel)
res = qt_updater.should_check_for_updates()
assert res == False
assert qt_updater.check == False
assert res is False
assert qt_updater.check is False
# Test 4 - Same as the previous test, but check that clicking on "X" does not store
# any decision.
@ -429,5 +429,5 @@ def test_update_check_prompt(
QtCore.QTimer.singleShot(500, click_x)
res = qt_updater.should_check_for_updates()
assert res == False
assert qt_updater.check == None
assert res is False
assert qt_updater.check is None

View file

@ -35,11 +35,10 @@ def provider_wait() -> DummyWait:
@pytest.mark.skipif(
os.environ.get("DUMMY_CONVERSION", False) == False,
os.environ.get("DUMMY_CONVERSION", False) is False,
reason="can only run for dummy conversions",
)
class TestDummyTermination(IsolationProviderTermination):
def test_failed(
self,
provider_wait: IsolationProvider,