manim/tests/assert_utils.py
Hugues Devimeux 21ad14ed14
Fixed issue when an animation is cached, manim can't merge the partial movie files. (#1192)
* fixed issue

* fixed tests

* Update manim/renderer/cairo_renderer.py

Co-authored-by: Darylgolden <darylgolden@gmail.com>

* added tests

* imrpoved test

* fixed logic

* added new test

* check if the file has been outputed

* added test when caching is enabled

* fixed tests on windows

* black

* Update manim/renderer/cairo_renderer.py

Co-authored-by: Naveen M K <naveen@syrusdark.website>

* Update tests/assert_utils.py

Co-authored-by: Naveen M K <naveen@syrusdark.website>

Co-authored-by: KingWampy <9156604+WampyCakes@users.noreply.github.com>
Co-authored-by: Darylgolden <darylgolden@gmail.com>
Co-authored-by: Naveen M K <naveen@syrusdark.website>
2021-03-31 20:23:43 +05:30

25 lines
860 B
Python

import typing
from os import PathLike
from pathlib import Path
from pprint import pformat
def assert_file_exists(filepath: typing.Union[str, PathLike]) -> None:
"""Assert if filepath points to an existing file. Print all the elements (files and dir) of the parent dir of the given filepath.
This is mostly to have better assert message than using a raw assert os.path.isfile(filepath).
Parameters
----------
filepath
Filepath to check.
Raises
------
AssertionError
If filepath does not point to a file (if the file does not exist or it's a dir).
"""
path = Path(filepath)
if not path.is_file():
message = f"{path.absolute()} is not a file. Other elements in the parent directory are \n{pformat([path.name for path in list(path.parent.iterdir())])}"
raise AssertionError(message)