From 860ab231b51c40ad945f31595f46f07068333c40 Mon Sep 17 00:00:00 2001 From: taiyeoguns Date: Tue, 17 Oct 2023 21:33:01 +0100 Subject: [PATCH] chore(tests): add tests for converter methods (#283) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * chore(tests): add tests for converter methods * chore(tests): update ppt converter test --------- Co-authored-by: Jérome Eertmans --- manim_slides/convert.py | 2 +- tests/test_convert.py | 31 +++++++++++++++++++++++++++++++ tests/test_main.py | 8 ++++++-- 3 files changed, 38 insertions(+), 3 deletions(-) diff --git a/manim_slides/convert.py b/manim_slides/convert.py index 992e04f..c0f57e8 100644 --- a/manim_slides/convert.py +++ b/manim_slides/convert.py @@ -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) diff --git a/tests/test_convert.py b/tests/test_convert.py index e3b2c83..e566a11 100644 --- a/tests/test_convert.py +++ b/tests/test_convert.py @@ -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() diff --git a/tests/test_main.py b/tests/test_main.py index 196c1b0..6435299 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -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, ], )