Creates a mix-in for asserting file system states

This commit is contained in:
Trenton Holmes
2023-02-19 18:00:45 -08:00
committed by Trenton H
parent 1718cf6504
commit 0df91c31f1
14 changed files with 275 additions and 253 deletions

View File

@@ -3,6 +3,9 @@ import shutil
import tempfile
from collections import namedtuple
from contextlib import contextmanager
from os import PathLike
from pathlib import Path
from typing import Union
from unittest import mock
from django.apps import apps
@@ -87,6 +90,24 @@ class DirectoriesMixin:
remove_dirs(self.dirs)
class FileSystemAssertsMixin:
def assertIsFile(self, path: Union[PathLike, str]):
if not Path(path).resolve().is_file():
raise AssertionError(f"File does not exist: {path}")
def assertIsNotFile(self, path: Union[PathLike, str]):
if Path(path).resolve().is_file():
raise AssertionError(f"File does exist: {path}")
def assertIsDir(self, path: Union[PathLike, str]):
if not Path(path).resolve().is_dir():
raise AssertionError(f"Dir does not exist: {path}")
def assertIsNotDir(self, path: Union[PathLike, str]):
if Path(path).resolve().is_dir():
raise AssertionError(f"Dir does exist: {path}")
class ConsumerProgressMixin:
def setUp(self) -> None:
self.send_progress_patcher = mock.patch(