Skip to content

Commit

Permalink
chore(tests): add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jeertmans committed Oct 30, 2024
1 parent 3144ba6 commit f924b8e
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 6 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
(unreleased)=
## [Unreleased](https://github.com/jeertmans/manim-slides/compare/v5.1.9...HEAD)

(unreleased-added)=
### Added

- Added `--offline` option to `manim-slides convert` for offline
HTML presentations.
[#440](https://github.com/jeertmans/manim-slides/pull/440)

(v5.1.9)=
## [v5.1.9](https://github.com/jeertmans/manim-slides/compare/v5.1.8...v5.1.9)

Expand Down
24 changes: 19 additions & 5 deletions manim_slides/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ def load_template(self) -> str:
def open(self, file: Path) -> None:
webbrowser.open(file.absolute().as_uri())

def convert_to(self, dest: Path) -> None:
def convert_to(self, dest: Path) -> None: # noqa: C901
"""
Convert this configuration into a RevealJS HTML presentation, saved to
DEST.
Expand Down Expand Up @@ -616,7 +616,7 @@ def xpath(el: etree.Element, query: str) -> etree.XPath:


def show_config_options(function: Callable[..., Any]) -> Callable[..., Any]:
"""Wrap a function to add a `--show-config` option."""
"""Wrap a function to add a '--show-config' option."""

def callback(ctx: Context, param: Parameter, value: bool) -> None:
if not value or ctx.resilient_parsing:
Expand Down Expand Up @@ -647,7 +647,7 @@ def callback(ctx: Context, param: Parameter, value: bool) -> None:


def show_template_option(function: Callable[..., Any]) -> Callable[..., Any]:
"""Wrap a function to add a `--show-template` option."""
"""Wrap a function to add a '--show-template' option."""

def callback(ctx: Context, param: Parameter, value: bool) -> None:
if not value or ctx.resilient_parsing:
Expand Down Expand Up @@ -699,15 +699,21 @@ def callback(ctx: Context, param: Parameter, value: bool) -> None:
multiple=True,
callback=validate_config_option,
help="Configuration options passed to the converter. "
"E.g., pass ``-cslide_number=true`` to display slide numbers.",
"E.g., pass '-cslide_number=true' to display slide numbers.",
)
@click.option(
"--use-template",
"template",
metavar="FILE",
type=click.Path(exists=True, dir_okay=False, path_type=Path),
help="Use the template given by FILE instead of default one. "
"To echo the default template, use ``--show-template``.",
"To echo the default template, use '--show-template'.",
)
@click.option(
"--offline",
is_flag=True,
help="Download any remote content and store it in the assets folder. "
"The is a convenient alias to '-coffline=true'.",
)
@show_template_option
@show_config_options
Expand All @@ -720,6 +726,7 @@ def convert(
open_result: bool,
config_options: dict[str, str],
template: Optional[Path],
offline: bool,
) -> None:
"""Convert SCENE(s) into a given format and writes the result in DEST."""
presentation_configs = get_scenes_presentation_config(scenes, folder)
Expand All @@ -737,6 +744,13 @@ def convert(
else:
cls = Converter.from_string(to)

if (
offline
and issubclass(cls, (RevealJS, HtmlZip))
and "offline" not in config_options
):
config_options["offline"] = "true"

converter = cls(
presentation_configs=presentation_configs,
template=template,
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ classifiers = [
]
dependencies = [
"av>=9.0.0",
"beautifulsoup4>=4.12.3",
"click>=8.1.3",
"click-default-group>=1.2.2",
"jinja2>=3.1.2",
Expand Down
18 changes: 18 additions & 0 deletions tests/test_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,24 @@ def test_revealjs_converter(
file_contents = out_file.read_text()
assert "manim" in file_contents.casefold()

def test_revealjs_offline_converter(
self, tmp_path: Path, presentation_config: PresentationConfig
) -> None:
out_file = tmp_path / "slides.html"
RevealJS(presentation_configs=[presentation_config], offline=True).convert_to(
out_file
)
assert out_file.exists()
assets_dir = Path(tmp_path / "slides_assets")
assert assets_dir.is_dir()
for file in [
"black.min.css",
"reveal.min.css",
"reveal.min.js",
"zenbun.min.css",
]:
assert (assets_dir / file).exists()

def test_htmlzip_converter(
self, tmp_path: Path, presentation_config: PresentationConfig
) -> None:
Expand Down
4 changes: 3 additions & 1 deletion uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f924b8e

Please sign in to comment.