diff --git a/src/documents/tests/test_management_exporter.py b/src/documents/tests/test_management_exporter.py index 71f2f351e..ec6a21b77 100644 --- a/src/documents/tests/test_management_exporter.py +++ b/src/documents/tests/test_management_exporter.py @@ -828,10 +828,7 @@ class TestExportImport( def _export_import_barcodes(self, *, split_manifest: bool) -> None: shutil.rmtree(Path(self.dirs.media_dir) / "documents") - shutil.copytree( - Path(__file__).parent / "samples" / "documents", - Path(self.dirs.media_dir) / "documents", - ) + install_document_samples(Path(self.dirs.media_dir) / "documents") DocumentBarcodeFactory(document=self.d1, value="https://example.com") DocumentBarcodeFactory(document=self.d2, page=2, value="DE8937") diff --git a/src/documents/tests/test_tasks.py b/src/documents/tests/test_tasks.py index 61e7772d9..a5def0944 100644 --- a/src/documents/tests/test_tasks.py +++ b/src/documents/tests/test_tasks.py @@ -279,14 +279,7 @@ class TestUpdateContent(DirectoriesMixin, TestCase): def _create_root_with_version(self) -> tuple[Document, Document]: sample1 = self.dirs.scratch_dir / "sample.pdf" - shutil.copy( - Path(__file__).parent - / "samples" - / "documents" - / "originals" - / "0000001.pdf", - sample1, - ) + shutil.copy(SIMPLE_DIGITAL_PDF, sample1) root = DocumentFactory(content="root content", mime_type="application/pdf") version = DocumentFactory( content="my document", diff --git a/src/paperless/tests/parsers/conftest.py b/src/paperless/tests/parsers/conftest.py index 2175e3667..5e834e959 100644 --- a/src/paperless/tests/parsers/conftest.py +++ b/src/paperless/tests/parsers/conftest.py @@ -456,6 +456,18 @@ def simple_png_file(tesseract_samples_dir: Path) -> Path: return tesseract_samples_dir / "simple.png" +@pytest.fixture(scope="session") +def rotated_pdf_file(tesseract_samples_dir: Path) -> Path: + """Path to a landscape (rotated) PDF sample file. + + Returns + ------- + Path + Absolute path to ``tesseract/rotated.pdf``. + """ + return tesseract_samples_dir / "rotated.pdf" + + # ------------------------------------------------------------------ # Tesseract parser instance and settings helpers # ------------------------------------------------------------------ diff --git a/src/paperless/tests/parsers/test_tesseract_parser.py b/src/paperless/tests/parsers/test_tesseract_parser.py index ff451dbeb..a44d23bec 100644 --- a/src/paperless/tests/parsers/test_tesseract_parser.py +++ b/src/paperless/tests/parsers/test_tesseract_parser.py @@ -282,17 +282,17 @@ class TestGetThumbnail: assert thumb.is_file() @pytest.mark.parametrize( - ("filename", "expected_height"), + ("sample_fixture", "expected_height"), [ - pytest.param("simple-digital.pdf", 647, id="portrait-letter"), - pytest.param("rotated.pdf", 386, id="landscape"), + pytest.param("simple_digital_pdf_file", 647, id="portrait-letter"), + pytest.param("rotated_pdf_file", 386, id="landscape"), ], ) def test_thumbnail_is_correct_format_and_size( self, tesseract_parser: RasterisedDocumentParser, - tesseract_samples_dir: Path, - filename: str, + request: pytest.FixtureRequest, + sample_fixture: str, expected_height: int, ) -> None: """ @@ -304,7 +304,7 @@ class TestGetThumbnail: - A 500px wide WebP keeping the page's aspect ratio """ thumb = tesseract_parser.get_thumbnail( - tesseract_samples_dir / filename, + request.getfixturevalue(sample_fixture), "application/pdf", ) with Image.open(thumb) as im: diff --git a/src/paperless/tests/test_parser_utils.py b/src/paperless/tests/test_parser_utils.py index a56d0ac9e..ed20a024b 100644 --- a/src/paperless/tests/test_parser_utils.py +++ b/src/paperless/tests/test_parser_utils.py @@ -93,7 +93,7 @@ class TestGetPdfFirstPageSizePoints: pdf.save(path) return path - def test_letter_sample(self) -> None: + def test_letter_sample(self, simple_digital_pdf_file: Path) -> None: """ GIVEN: - A US Letter sample PDF with no CropBox and no rotation @@ -102,7 +102,7 @@ class TestGetPdfFirstPageSizePoints: THEN: - The MediaBox size in points is returned """ - assert get_pdf_first_page_size_points(SAMPLES / "simple-digital.pdf") == ( + assert get_pdf_first_page_size_points(simple_digital_pdf_file) == ( 612.0, 792.0, ) @@ -197,6 +197,7 @@ class TestGetPdfFirstPageSizePoints: def test_pdfinfo_not_installed_returns_none( self, mocker: MockerFixture, + simple_digital_pdf_file: Path, ) -> None: """ GIVEN: @@ -207,7 +208,7 @@ class TestGetPdfFirstPageSizePoints: - None is returned and nothing is raised """ mocker.patch("subprocess.run", side_effect=FileNotFoundError("pdfinfo")) - assert get_pdf_first_page_size_points(SAMPLES / "simple-digital.pdf") is None + assert get_pdf_first_page_size_points(simple_digital_pdf_file) is None def test_degenerate_box_returns_none(self, tmp_path: Path) -> None: """ @@ -249,7 +250,7 @@ class TestGetPdfFirstPageSizePoints: bad.write_bytes(b"not a pdf") assert get_pdf_first_page_size_points(bad) is None - def test_encrypted_pdf_returns_none(self) -> None: + def test_encrypted_pdf_returns_none(self, parser_samples_dir: Path) -> None: """ GIVEN: - A password protected PDF @@ -258,7 +259,8 @@ class TestGetPdfFirstPageSizePoints: THEN: - None is returned and nothing is raised """ - assert get_pdf_first_page_size_points(SAMPLES / "encrypted.pdf") is None + encrypted = parser_samples_dir / "tesseract" / "encrypted.pdf" + assert get_pdf_first_page_size_points(encrypted) is None class TestPostProcessText: