Files
paperless-ngx/src/paperless_testing/assertions.py
T
Trenton H 03ac4aed7e Chore: Move the cross-app test helpers into the shared layer and add a progress fixture (#14221)
Test modules in paperless, paperless_mail and documents imported filesystem assertions, the migration test base, the retry helper and the streaming-response reader out of documents/tests/utils.py, which kept each app's tests coupled to another app's test package.

They now live in paperless_testing, and the progress manager fake is renamed FakeProgressManager and now subclasses the real ProgressManager, overriding only the transport, so the payload it records is built by the production code. The twenty places that patched documents.tasks.ProgressManager by hand now use a fake_progress_manager fixture.
2026-09-22 08:02:17 -07:00

38 lines
1.3 KiB
Python

"""Filesystem assertions for unittest-style tests."""
from __future__ import annotations
from pathlib import Path
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from os import PathLike
class FileSystemAssertsMixin:
def assertIsFile(self, path: PathLike[str] | str) -> None:
if not Path(path).resolve().is_file():
raise AssertionError(f"File does not exist: {path}")
def assertIsNotFile(self, path: PathLike[str] | str) -> None:
if Path(path).resolve().is_file():
raise AssertionError(f"File does exist: {path}")
def assertIsDir(self, path: PathLike[str] | str) -> None:
if not Path(path).resolve().is_dir():
raise AssertionError(f"Dir does not exist: {path}")
def assertIsNotDir(self, path: PathLike[str] | str) -> None:
if Path(path).resolve().is_dir():
raise AssertionError(f"Dir does exist: {path}")
def assertFileCountInDir(self, path: PathLike[str] | str, count: int) -> None:
path = Path(path).resolve()
if not path.is_dir():
raise AssertionError(f"Path {path} is not a directory")
found = len([x for x in path.iterdir() if x.is_file()])
if found != count:
raise AssertionError(
f"Path {path} contains {found} files instead of {count} files",
)