diff --git a/dangerzone/errors.py b/dangerzone/errors.py index 63dc4e7..dbbcb4b 100644 --- a/dangerzone/errors.py +++ b/dangerzone/errors.py @@ -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 diff --git a/dangerzone/isolation_provider/base.py b/dangerzone/isolation_provider/base.py index 5b05789..308a05e 100644 --- a/dangerzone/isolation_provider/base.py +++ b/dangerzone/isolation_provider/base.py @@ -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 diff --git a/dangerzone/isolation_provider/qubes.py b/dangerzone/isolation_provider/qubes.py index 5a2395d..aa59006 100644 --- a/dangerzone/isolation_provider/qubes.py +++ b/dangerzone/isolation_provider/qubes.py @@ -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 diff --git a/tests/gui/test_main_window.py b/tests/gui/test_main_window.py index b649dc7..23e0da9 100644 --- a/tests/gui/test_main_window.py +++ b/tests/gui/test_main_window.py @@ -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) diff --git a/tests/gui/test_updater.py b/tests/gui/test_updater.py index e6f76c2..8572ad7 100644 --- a/tests/gui/test_updater.py +++ b/tests/gui/test_updater.py @@ -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", "
changelog
")) @@ -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", "changelog
")) @@ -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 diff --git a/tests/isolation_provider/test_dummy.py b/tests/isolation_provider/test_dummy.py index 04ccf97..9d4041b 100644 --- a/tests/isolation_provider/test_dummy.py +++ b/tests/isolation_provider/test_dummy.py @@ -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,