chore(tests): add tests for converter methods (#283)

* chore(tests): add tests for converter methods

* chore(tests): update ppt converter test

---------

Co-authored-by: Jérome Eertmans <jeertmans@icloud.com>
This commit is contained in:
taiyeoguns
2023-10-17 21:33:01 +01:00
committed by GitHub
parent c075904a27
commit 860ab231b5
3 changed files with 38 additions and 3 deletions

View File

@ -528,7 +528,7 @@ class PowerPoint(Converter):
mime_type=mime_type,
)
if self.auto_play_media:
auto_play_media(movie, loop=slide_config.is_loop())
auto_play_media(movie, loop=slide_config.loop)
dest.parent.mkdir(parents=True, exist_ok=True)
prs.save(dest)

View File

@ -1,7 +1,10 @@
from enum import EnumMeta
from pathlib import Path
import pytest
from pydantic import ValidationError
from manim_slides.config import PresentationConfig
from manim_slides.convert import (
PDF,
AutoAnimateEasing,
@ -129,3 +132,31 @@ class TestConverter:
)
def test_from_string(self, name: str, converter: type) -> None:
assert Converter.from_string(name) == converter
def test_revealjs_converter(
self, tmp_path: Path, presentation_config: PresentationConfig
) -> None:
out_file = tmp_path / "slides.html"
RevealJS(presentation_configs=[presentation_config]).convert_to(out_file)
assert out_file.exists()
assert Path(tmp_path / "slides_assets").is_dir()
file_contents = Path(out_file).read_text()
assert "manim" in file_contents.casefold()
def test_pdf_converter(
self, tmp_path: Path, presentation_config: PresentationConfig
) -> None:
out_file = tmp_path / "slides.pdf"
PDF(presentation_configs=[presentation_config]).convert_to(out_file)
assert out_file.exists()
def test_converter_no_presentation_config(self) -> None:
with pytest.raises(ValidationError):
Converter(presentation_configs=[])
def test_pptx_converter(
self, tmp_path: Path, presentation_config: PresentationConfig
) -> None:
out_file = tmp_path / "slides.pptx"
PowerPoint(presentation_configs=[presentation_config]).convert_to(out_file)
assert out_file.exists()

View File

@ -1,5 +1,6 @@
from pathlib import Path
import pytest
from click.testing import CliRunner
from manim_slides.__main__ import cli
@ -38,7 +39,8 @@ def test_present(slides_folder: Path) -> None:
assert results.exit_code == 0
def test_convert(slides_folder: Path) -> None:
@pytest.mark.parametrize(("extension",), [("html",), ("pdf",), ("pptx",)])
def test_convert(slides_folder: Path, extension: str) -> None:
runner = CliRunner()
with runner.isolated_filesystem():
@ -47,9 +49,11 @@ def test_convert(slides_folder: Path) -> None:
[
"convert",
"BasicSlide",
"basic_example.html",
f"basic_example.{extension}",
"--folder",
str(slides_folder),
"--to",
extension,
],
)