mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2026-11-03 13:35:37 +00:00
Chore: Use shared samples in tests that arrived from dev
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
505740c39f
commit
49972c096b
6 files changed
+29
-24
No files matched your search
@@ -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
|
||||
# ------------------------------------------------------------------
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in new issue
Block a user