diff --git a/tests/__init__.py b/tests/__init__.py index 7b35b37..cb2009e 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -8,8 +8,8 @@ sys.dangerzone_dev = True # type: ignore[attr-defined] from dangerzone.document import SAFE_EXTENSION SAMPLE_DIRECTORY = "test_docs" -BASIC_SAMPLE = "sample-pdf.pdf" -BASIC_SAMPLE2 = "sample-doc.doc" +BASIC_SAMPLE_PDF = "sample-pdf.pdf" +BASIC_SAMPLE_DOC = "sample-doc.doc" test_docs_dir = Path(__file__).parent.joinpath(SAMPLE_DIRECTORY) test_docs = [ p @@ -23,17 +23,17 @@ for_each_doc = pytest.mark.parametrize("doc", test_docs) class TestBase: - sample_doc = str(test_docs_dir.joinpath(BASIC_SAMPLE)) + sample_doc = str(test_docs_dir.joinpath(BASIC_SAMPLE_PDF)) + + +@pytest.fixture +def sample_pdf() -> str: + return str(test_docs_dir.joinpath(BASIC_SAMPLE_PDF)) @pytest.fixture def sample_doc() -> str: - return str(test_docs_dir.joinpath(BASIC_SAMPLE)) - - -@pytest.fixture -def sample_doc2() -> str: - return str(test_docs_dir.joinpath(BASIC_SAMPLE2)) + return str(test_docs_dir.joinpath(BASIC_SAMPLE_DOC)) @pytest.fixture diff --git a/tests/gui/test_main_window.py b/tests/gui/test_main_window.py index d4e05a3..2aab557 100644 --- a/tests/gui/test_main_window.py +++ b/tests/gui/test_main_window.py @@ -8,7 +8,7 @@ from dangerzone.gui.main_window import * from dangerzone.gui.updater import UpdateReport, UpdaterThread from dangerzone.util import get_version -from .. import sample_doc, sample_doc2 +from .. import sample_pdf, sample_doc from . import qt_updater, updater from .test_updater import default_updater_settings @@ -106,12 +106,12 @@ def test_change_document_button( content_widget: ContentWidget, qtbot: QtBot, mocker: MockerFixture, + sample_pdf: str, sample_doc: str, - sample_doc2: str, ) -> None: # Setup first doc selection file_dialog_mock = mocker.MagicMock() - file_dialog_mock.selectedFiles.return_value = (sample_doc,) + file_dialog_mock.selectedFiles.return_value = (sample_pdf,) content_widget.doc_selection_widget.file_dialog = file_dialog_mock # Select first file @@ -123,7 +123,7 @@ def test_change_document_button( file_dialog_mock.accept() # Setup doc change - file_dialog_mock.selectedFiles.return_value = (sample_doc2,) + file_dialog_mock.selectedFiles.return_value = (sample_doc,) # When clicking on "select docs" button with qtbot.waitSignal(content_widget.documents_added): @@ -143,4 +143,4 @@ def test_change_document_button( for doc in content_widget.dangerzone.get_unconverted_documents() ] assert len(docs) is 1 - assert docs[0] == sample_doc2 + assert docs[0] == sample_doc diff --git a/tests/test_document.py b/tests/test_document.py index df3550a..23a9061 100644 --- a/tests/test_document.py +++ b/tests/test_document.py @@ -10,20 +10,20 @@ import pytest from dangerzone import errors from dangerzone.document import ARCHIVE_SUBDIR, SAFE_EXTENSION, Document -from . import sample_doc, unreadable_pdf +from . import sample_pdf, unreadable_pdf -def test_input_sample_init(sample_doc: str) -> None: - Document(sample_doc) +def test_input_sample_init(sample_pdf: str) -> None: + Document(sample_pdf) -def test_input_sample_init_archive(sample_doc: str) -> None: - Document(sample_doc, archive=True) +def test_input_sample_init_archive(sample_pdf: str) -> None: + Document(sample_pdf, archive=True) -def test_input_sample_after(sample_doc: str) -> None: +def test_input_sample_after(sample_pdf: str) -> None: d = Document() - d.input_filename = sample_doc + d.input_filename = sample_pdf def test_input_file_none() -> None: @@ -50,12 +50,12 @@ def test_input_file_unreadable(unreadable_pdf: str) -> None: @pytest.mark.skipif(platform.system() == "Windows", reason="Unix-specific") -def test_output_file_unwriteable_dir(sample_doc: str, tmp_path: Path) -> None: +def test_output_file_unwriteable_dir(sample_pdf: str, tmp_path: Path) -> None: # make parent dir unwriteable - sample_doc_safe = str(tmp_path / "document-safe.pdf") + sample_pdf_safe = str(tmp_path / "document-safe.pdf") os.chmod(tmp_path, 0o400) with pytest.raises(errors.UnwriteableOutputDirException) as e: - d = Document(sample_doc, sample_doc_safe) + d = Document(sample_pdf, sample_pdf_safe) def test_output(tmp_path: Path) -> None: @@ -84,7 +84,7 @@ def test_output_file_not_pdf(tmp_path: Path) -> None: @pytest.mark.skipif(platform.system() == "Windows", reason="Unix-specific") -def test_archive_unwriteable_dir(sample_doc: str, tmp_path: Path) -> None: +def test_archive_unwriteable_dir(tmp_path: Path) -> None: doc = tmp_path / "doc.pdf" Path.touch(doc) d = Document(str(doc)) @@ -117,37 +117,37 @@ def test_archive(mocker: MagicMock, tmp_path: Path) -> None: assert f.read() == test_string -def test_set_output_dir(sample_doc: str, tmp_path: Path) -> None: - d = Document(sample_doc) +def test_set_output_dir(sample_pdf: str, tmp_path: Path) -> None: + d = Document(sample_pdf) d.set_output_dir(str(tmp_path)) assert os.path.dirname(d.output_filename) == str(tmp_path) -def test_set_output_dir_non_existant(sample_doc: str, tmp_path: Path) -> None: +def test_set_output_dir_non_existant(sample_pdf: str, tmp_path: Path) -> None: non_existant_path = str(tmp_path / "fake-dir") - d = Document(sample_doc) + d = Document(sample_pdf) with pytest.raises(errors.NonExistantOutputDirException): d.set_output_dir(non_existant_path) -def test_set_output_dir_is_file(sample_doc: str, tmp_path: Path) -> None: +def test_set_output_dir_is_file(sample_pdf: str, tmp_path: Path) -> None: # create a file file_path = str(tmp_path / "file") with open(file_path, "w"): pass - d = Document(sample_doc) + d = Document(sample_pdf) with pytest.raises(errors.OutputDirIsNotDirException): d.set_output_dir(file_path) -def test_default_output_filename(sample_doc: str) -> None: - d = Document(sample_doc) +def test_default_output_filename(sample_pdf: str) -> None: + d = Document(sample_pdf) assert d.output_filename.endswith(SAFE_EXTENSION) -def test_set_output_filename_suffix(sample_doc: str) -> None: - d = Document(sample_doc) +def test_set_output_filename_suffix(sample_pdf: str) -> None: + d = Document(sample_pdf) safe_extension = "-trusted.pdf" d.suffix = safe_extension assert d.output_filename.endswith(safe_extension) @@ -157,27 +157,27 @@ def test_set_output_filename_suffix(sample_doc: str) -> None: d.suffix = "-new-trusted.pdf" -def test_is_unconverted_by_default(sample_doc: str) -> None: - d = Document(sample_doc) +def test_is_unconverted_by_default(sample_pdf: str) -> None: + d = Document(sample_pdf) assert d.is_unconverted() -def test_mark_as_safe(sample_doc: str) -> None: - d = Document(sample_doc) +def test_mark_as_safe(sample_pdf: str) -> None: + d = Document(sample_pdf) d.mark_as_safe() assert d.is_safe() assert not d.is_failed() assert not d.is_unconverted() -def test_mark_as_converting(sample_doc: str) -> None: - d = Document(sample_doc) +def test_mark_as_converting(sample_pdf: str) -> None: + d = Document(sample_pdf) d.mark_as_converting() assert d.is_converting() -def test_mark_as_failed(sample_doc: str) -> None: - d = Document(sample_doc) +def test_mark_as_failed(sample_pdf: str) -> None: + d = Document(sample_pdf) d.mark_as_failed() assert d.is_failed() assert not d.is_safe()