mirror of
https://github.com/freedomofpress/dangerzone.git
synced 2025-04-28 18:02:38 +02:00

Now that sample_doc was renamed to sample_pdf it could cause some confusion the fact that that the TestBase class had an attribute called sample_doc which referenced the sample PDF. By removing this attribute and passing the fixture instead we are following a more pytest-native approach of passing arguments explicitly.
39 lines
934 B
Python
39 lines
934 B
Python
import sys
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
sys.dangerzone_dev = True # type: ignore[attr-defined]
|
|
|
|
from dangerzone.document import SAFE_EXTENSION
|
|
|
|
SAMPLE_DIRECTORY = "test_docs"
|
|
BASIC_SAMPLE_PDF = "sample-pdf.pdf"
|
|
BASIC_SAMPLE_DOC = "sample-doc.doc"
|
|
test_docs_dir = Path(__file__).parent.joinpath(SAMPLE_DIRECTORY)
|
|
test_docs = [
|
|
p
|
|
for p in test_docs_dir.rglob("*")
|
|
if p.is_file()
|
|
and not (p.name.endswith(SAFE_EXTENSION) or p.name.startswith("sample_bad"))
|
|
]
|
|
|
|
# Pytest parameter decorators
|
|
for_each_doc = pytest.mark.parametrize("doc", test_docs)
|
|
|
|
|
|
@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_DOC))
|
|
|
|
|
|
@pytest.fixture
|
|
def unreadable_pdf(tmp_path: Path) -> str:
|
|
file_path = tmp_path / "document.pdf"
|
|
file_path.touch(mode=0o000)
|
|
return str(file_path)
|