diff --git a/dangerzone/cli.py b/dangerzone/cli.py index 3e2352e..8f68e62 100644 --- a/dangerzone/cli.py +++ b/dangerzone/cli.py @@ -13,8 +13,6 @@ from .isolation_provider.qubes import Qubes, is_qubes_native_conversion from .logic import DangerzoneCore from .util import get_version, replace_control_chars -F = TypeVar("F", bound=Callable[..., Any]) - def print_header(s: str) -> None: click.echo("") diff --git a/dangerzone/conversion/doc_to_pixels.py b/dangerzone/conversion/doc_to_pixels.py index f2fba61..4780e37 100644 --- a/dangerzone/conversion/doc_to_pixels.py +++ b/dangerzone/conversion/doc_to_pixels.py @@ -217,7 +217,6 @@ class DocumentToPixels(DangerzoneConverter): raise errors.MaxPagesException() await self.write_page_count(doc.page_count) - page_base = "/tmp/page" for page in doc.pages(): # TODO check if page.number is doc-controlled page_num = page.number + 1 # pages start in 1 diff --git a/dangerzone/gui/updater.py b/dangerzone/gui/updater.py index 21bb459..396de21 100644 --- a/dangerzone/gui/updater.py +++ b/dangerzone/gui/updater.py @@ -232,13 +232,13 @@ class UpdaterThread(QtCore.QThread): try: info = res.json() - except json.JSONDecodeError as e: + except json.JSONDecodeError: raise ValueError(f"Received a non-JSON response from {self.GH_RELEASE_URL}") try: version = info["tag_name"].lstrip("v") changelog = markdown.markdown(info["body"]) - except KeyError as e: + except KeyError: raise ValueError( f"Missing required fields in JSON response from {self.GH_RELEASE_URL}" ) diff --git a/dangerzone/isolation_provider/base.py b/dangerzone/isolation_provider/base.py index 4a8ff40..5b05789 100644 --- a/dangerzone/isolation_provider/base.py +++ b/dangerzone/isolation_provider/base.py @@ -100,7 +100,7 @@ class IsolationProvider(ABC): assert p.stdin is not None p.stdin.write(f.read()) p.stdin.close() - except BrokenPipeError as e: + except BrokenPipeError: raise errors.ConverterProcException() assert p.stdout diff --git a/dangerzone/isolation_provider/qubes.py b/dangerzone/isolation_provider/qubes.py index 34e76ed..5a2395d 100644 --- a/dangerzone/isolation_provider/qubes.py +++ b/dangerzone/isolation_provider/qubes.py @@ -114,9 +114,6 @@ class Qubes(IsolationProvider): with zipfile.ZipFile(temp_file, "w") as z: z.mkdir("dangerzone/") z.writestr("dangerzone/__init__.py", "") - import dangerzone.conversion - - conv_path = Path(dangerzone.conversion.__file__).parent for root, _, files in os.walk(_conv_path): for file in files: if file.endswith(".py"): diff --git a/dangerzone/logic.py b/dangerzone/logic.py index 0f3e346..21182a9 100644 --- a/dangerzone/logic.py +++ b/dangerzone/logic.py @@ -33,9 +33,7 @@ class DangerzoneCore(object): # Load settings self.settings = Settings(self) - self.documents: List[Document] = [] - self.isolation_provider = isolation_provider def add_document_from_filename( diff --git a/tests/gui/test_main_window.py b/tests/gui/test_main_window.py index 6ee524b..b649dc7 100644 --- a/tests/gui/test_main_window.py +++ b/tests/gui/test_main_window.py @@ -86,7 +86,7 @@ def test_no_update( menu_actions_before = window.hamburger_button.menu().actions() - with qtbot.waitSignal(updater.finished) as blocker: + with qtbot.waitSignal(updater.finished): updater.start() # Check that the callback function gets an empty report. @@ -126,7 +126,7 @@ def test_update_detected( menu_actions_before = window.hamburger_button.menu().actions() - with qtbot.waitSignal(updater.finished) as blocker: + with qtbot.waitSignal(updater.finished): updater.start() menu_actions_after = window.hamburger_button.menu().actions() @@ -190,7 +190,7 @@ def test_update_detected( # Collapse the "What's New" section and ensure that the dialog's height # increases. - with qtbot.waitSignal(collapsible_box.toggle_animation.finished) as blocker: + with qtbot.waitSignal(collapsible_box.toggle_animation.finished): collapsible_box.toggle_button.click() assert dialog.sizeHint().height() > height_initial @@ -198,7 +198,7 @@ def test_update_detected( # Uncollapse the "What's New" section, and ensure that the dialog's height gets # back to the original value. - with qtbot.waitSignal(collapsible_box.toggle_animation.finished) as blocker: + with qtbot.waitSignal(collapsible_box.toggle_animation.finished): collapsible_box.toggle_button.click() assert dialog.sizeHint().height() == height_initial @@ -236,7 +236,7 @@ def test_update_error( menu_actions_before = window.hamburger_button.menu().actions() - with qtbot.waitSignal(updater.finished) as blocker: + with qtbot.waitSignal(updater.finished): updater.start() menu_actions_after = window.hamburger_button.menu().actions() @@ -262,7 +262,7 @@ def test_update_error( # Test 2 - Check that the second error does not notify the user either. updater.dangerzone.settings.set("updater_last_check", 0) - with qtbot.waitSignal(updater.finished) as blocker: + with qtbot.waitSignal(updater.finished): updater.start() assert load_svg_spy.call_count == 0 @@ -279,7 +279,7 @@ def test_update_error( # Test 3 - Check that a third error shows a new menu entry. updater.dangerzone.settings.set("updater_last_check", 0) - with qtbot.waitSignal(updater.finished) as blocker: + with qtbot.waitSignal(updater.finished): updater.start() menu_actions_after = window.hamburger_button.menu().actions() diff --git a/tests/isolation_provider/test_qubes.py b/tests/isolation_provider/test_qubes.py index f876369..45c5107 100644 --- a/tests/isolation_provider/test_qubes.py +++ b/tests/isolation_provider/test_qubes.py @@ -85,7 +85,7 @@ class TestQubes(IsolationProviderTest): stderr=subprocess.PIPE, shell=True, ) - with pytest.raises(errors.ConverterProcException) as e: + with pytest.raises(errors.ConverterProcException): doc = Document(sample_doc) provider.doc_to_pixels(doc, tmpdir, proc) assert provider.get_proc_exception(proc) == errors.QubesQrexecFailed diff --git a/tests/test_cli.py b/tests/test_cli.py index cb615ea..1e37887 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -306,8 +306,6 @@ class TestCliConversion(TestCliBasic): result.assert_failure() def test_archive(self, tmp_path: Path, sample_pdf: str) -> None: - test_string = "original file" - original_doc_path = str(tmp_path / "doc.pdf") safe_doc_path = str(tmp_path / f"doc{SAFE_EXTENSION}") archived_doc_path = str(tmp_path / ARCHIVE_SUBDIR / "doc.pdf") @@ -322,7 +320,7 @@ class TestCliConversion(TestCliBasic): assert os.path.exists(safe_doc_path) def test_dummy_conversion(self, tmp_path: Path, sample_pdf: str) -> None: - result = self.run_cli([sample_pdf, "--unsafe-dummy-conversion"]) + self.run_cli([sample_pdf, "--unsafe-dummy-conversion"]) def test_dummy_conversion_bulk(self, tmp_path: Path, sample_pdf: str) -> None: filenames = ["1.pdf", "2.pdf", "3.pdf"] diff --git a/tests/test_document.py b/tests/test_document.py index 46aaf18..80a3964 100644 --- a/tests/test_document.py +++ b/tests/test_document.py @@ -29,12 +29,12 @@ def test_input_file_none() -> None: Attempts to read a document's filename when no doc has been set """ d = Document() - with pytest.raises(errors.NotSetInputFilenameException) as e: + with pytest.raises(errors.NotSetInputFilenameException): d.input_filename def test_input_file_non_existing() -> None: - with pytest.raises(errors.InputFileNotFoundException) as e: + with pytest.raises(errors.InputFileNotFoundException): Document("non-existing-file.pdf") @@ -43,7 +43,7 @@ def test_input_file_non_existing() -> None: # https://stackoverflow.com/questions/72528318/what-file-permissions-make-a-file-unreadable-by-owner-in-windows @pytest.mark.skipif(platform.system() == "Windows", reason="Unix-specific") def test_input_file_unreadable(unreadable_pdf: str) -> None: - with pytest.raises(errors.InputFileNotReadableException) as e: + with pytest.raises(errors.InputFileNotReadableException): Document(unreadable_pdf) @@ -52,8 +52,8 @@ def test_output_file_unwriteable_dir(sample_pdf: str, tmp_path: Path) -> None: # make parent dir unwriteable sample_pdf_safe = str(tmp_path / "document-safe.pdf") os.chmod(tmp_path, 0o400) - with pytest.raises(errors.UnwriteableOutputDirException) as e: - d = Document(sample_pdf, sample_pdf_safe) + with pytest.raises(errors.UnwriteableOutputDirException): + Document(sample_pdf, sample_pdf_safe) def test_output(tmp_path: Path) -> None: @@ -67,7 +67,7 @@ def test_output_file_none() -> None: Attempts to read a document's filename when no doc has been set """ d = Document() - with pytest.raises(errors.NotSetOutputFilenameException) as e: + with pytest.raises(errors.NotSetOutputFilenameException): d.output_filename @@ -75,7 +75,7 @@ def test_output_file_not_pdf(tmp_path: Path) -> None: docx_file = str(tmp_path / "document.docx") d = Document() - with pytest.raises(errors.NonPDFOutputFileException) as e: + with pytest.raises(errors.NonPDFOutputFileException): d.output_filename = docx_file assert not os.path.exists(docx_file) @@ -90,7 +90,7 @@ def test_archive_unwriteable_dir(tmp_path: Path) -> None: # make archive directory unreadable os.chmod(tmp_path, 0o400) - with pytest.raises(errors.UnwriteableArchiveDirException) as e: + with pytest.raises(errors.UnwriteableArchiveDirException): d.validate_default_archive_dir() @@ -155,7 +155,7 @@ def test_set_output_filename_suffix(sample_pdf: str) -> None: assert d.output_filename.endswith(safe_extension) d.output_filename = "something_else.pdf" - with pytest.raises(errors.SuffixNotApplicableException) as e: + with pytest.raises(errors.SuffixNotApplicableException): d.suffix = "-new-trusted.pdf"