dangerzone/tests/__init__.py
deeplow 0b738ba490
Do not create outfile files when checking if writeable
Checking if files were writeable created files in the process. In the
case where someone adds a list of N files to dangerzone but exits before
converting, they would be left with N 0-byte files for the -safe
version. Now they don't.

Fixes #214
2022-11-14 09:04:54 +00:00

37 lines
832 B
Python

import os
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 = "sample.pdf"
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)
]
# Pytest parameter decorators
for_each_doc = pytest.mark.parametrize("doc", test_docs)
class TestBase:
sample_doc = str(test_docs_dir.joinpath(BASIC_SAMPLE))
@pytest.fixture
def sample_doc() -> str:
return str(test_docs_dir.joinpath(BASIC_SAMPLE))
@pytest.fixture
def unreadable_pdf(tmp_path: Path) -> str:
file_path = tmp_path / "document.pdf"
file_path.touch(mode=0o000)
return str(file_path)