manim/tests/test_ipython_magic.py
NotWearingPants 206db54af5
Migrate more os.path to pathlib in tests (#2991)
* Migrate more `os.path` to `pathlib` in tests

* Convert test fixtures to pathlib

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* fix mypy errors in tests

* migrate another pathlib instance

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Benjamin Hackl <devel@benjamin-hackl.at>
2022-10-26 19:51:38 +02:00

31 lines
1.1 KiB
Python

from __future__ import annotations
import re
from manim import tempconfig
from manim.utils.ipython_magic import _generate_file_name
def test_jupyter_file_naming():
"""Check the format of file names for jupyter"""
scene_name = "SimpleScene"
expected_pattern = r"[0-9a-zA-Z_]+[@_-]\d\d\d\d-\d\d-\d\d[@_-]\d\d-\d\d-\d\d"
with tempconfig({"scene_names": [scene_name]}):
file_name = _generate_file_name()
match = re.match(expected_pattern, file_name)
assert scene_name in file_name, (
"Expected file to contain " + scene_name + " but got " + file_name
)
assert match, "file name does not match expected pattern " + expected_pattern
def test_jupyter_file_output(tmp_path):
"""Check the jupyter file naming is valid and can be created"""
scene_name = "SimpleScene"
with tempconfig({"scene_names": [scene_name]}):
file_name = _generate_file_name()
actual_path = tmp_path.with_name(file_name)
with actual_path.open("w") as outfile:
outfile.write("")
assert actual_path.exists()
assert actual_path.is_file()