Compare commits

...

2 Commits

Author SHA1 Message Date
5461a20257 chore(version): bump 4.16.0 to 4.16.1 2023-08-24 13:16:13 +02:00
5e3603b40b fix(lib): correctly format enums on Python>=3.11
Closes #256

fix(tests): update tests and fix

chore(lib): simplify fix and more tests

chore(docs): document patch
2023-08-24 13:14:27 +02:00
6 changed files with 150 additions and 25 deletions

View File

@ -1,5 +1,5 @@
[bumpversion]
current_version = 4.16.0
current_version = 4.16.1
commit = True
message = chore(version): bump {current_version} to {new_version}

View File

@ -29,4 +29,4 @@ keywords:
- PowerPoint
- Python
license: MIT
version: v4.16.0
version: v4.16.1

View File

@ -1 +1 @@
__version__ = "4.16.0"
__version__ = "4.16.1"

View File

@ -140,43 +140,48 @@ class Str(str):
def __str__(self) -> str:
"""Ensures that the string is correctly quoted."""
if self in ["true", "false", "null"]:
return super().__str__()
return self
else:
return f"'{super().__str__()}'"
class StrEnum(Enum):
def __str__(self) -> str:
return str(self.value)
Function = str # Basically, anything
class JsTrue(str, Enum):
class JsTrue(str, StrEnum):
true = "true"
class JsFalse(str, Enum):
class JsFalse(str, StrEnum):
false = "false"
class JsBool(Str, Enum): # type: ignore
class JsBool(Str, StrEnum): # type: ignore
true = "true"
false = "false"
class JsNull(Str, Enum): # type: ignore
class JsNull(Str, StrEnum): # type: ignore
null = "null"
class ControlsLayout(Str, Enum): # type: ignore
class ControlsLayout(Str, StrEnum): # type: ignore
edges = "edges"
bottom_right = "bottom-right"
class ControlsBackArrows(Str, Enum): # type: ignore
class ControlsBackArrows(Str, StrEnum): # type: ignore
faded = "faded"
hidden = "hidden"
visibly = "visibly"
class SlideNumber(Str, Enum): # type: ignore
class SlideNumber(Str, StrEnum): # type: ignore
true = "true"
false = "false"
hdotv = "h.v"
@ -185,24 +190,24 @@ class SlideNumber(Str, Enum): # type: ignore
candt = "c/t"
class ShowSlideNumber(Str, Enum): # type: ignore
class ShowSlideNumber(Str, StrEnum): # type: ignore
all = "all"
print = "print"
speaker = "speaker"
class KeyboardCondition(Str, Enum): # type: ignore
class KeyboardCondition(Str, StrEnum): # type: ignore
null = "null"
focused = "focused"
class NavigationMode(Str, Enum): # type: ignore
class NavigationMode(Str, StrEnum): # type: ignore
default = "default"
linear = "linear"
grid = "grid"
class AutoPlayMedia(Str, Enum): # type: ignore
class AutoPlayMedia(Str, StrEnum): # type: ignore
null = "null"
true = "true"
false = "false"
@ -211,25 +216,25 @@ class AutoPlayMedia(Str, Enum): # type: ignore
PreloadIframes = AutoPlayMedia
class AutoAnimateMatcher(Str, Enum): # type: ignore
class AutoAnimateMatcher(Str, StrEnum): # type: ignore
null = "null"
class AutoAnimateEasing(Str, Enum): # type: ignore
class AutoAnimateEasing(Str, StrEnum): # type: ignore
ease = "ease"
AutoSlide = Union[PositiveInt, JsFalse]
class AutoSlideMethod(Str, Enum): # type: ignore
class AutoSlideMethod(Str, StrEnum): # type: ignore
null = "null"
MouseWheel = Union[JsNull, float]
class Transition(Str, Enum): # type: ignore
class Transition(Str, StrEnum): # type: ignore
none = "none"
fade = "fade"
slide = "slide"
@ -238,13 +243,13 @@ class Transition(Str, Enum): # type: ignore
zoom = "zoom"
class TransitionSpeed(Str, Enum): # type: ignore
class TransitionSpeed(Str, StrEnum): # type: ignore
default = "default"
fast = "fast"
slow = "slow"
class BackgroundSize(Str, Enum): # type: ignore
class BackgroundSize(Str, StrEnum): # type: ignore
# From: https://developer.mozilla.org/en-US/docs/Web/CSS/background-size
# TODO: support more background size
contain = "contain"
@ -254,11 +259,11 @@ class BackgroundSize(Str, Enum): # type: ignore
BackgroundTransition = Transition
class Display(Str, Enum): # type: ignore
class Display(Str, StrEnum): # type: ignore
block = "block"
class RevealTheme(str, Enum):
class RevealTheme(str, StrEnum):
black = "black"
white = "white"
league = "league"

View File

@ -43,7 +43,7 @@ packages = [
]
readme = "README.md"
repository = "https://github.com/jeertmans/manim-slides"
version = "4.16.0"
version = "4.16.1"
[tool.poetry.dependencies]
click = "^8.1.3"

View File

@ -1,6 +1,126 @@
from enum import EnumMeta
import pytest
from manim_slides.convert import PDF, Converter, PowerPoint, RevealJS
from manim_slides.convert import (
PDF,
AutoAnimateEasing,
AutoAnimateMatcher,
AutoPlayMedia,
AutoSlideMethod,
BackgroundSize,
BackgroundTransition,
ControlsBackArrows,
ControlsLayout,
Converter,
Display,
JsBool,
JsFalse,
JsNull,
JsTrue,
KeyboardCondition,
NavigationMode,
PowerPoint,
PreloadIframes,
RevealJS,
RevealTheme,
ShowSlideNumber,
SlideNumber,
Transition,
TransitionSpeed,
)
@pytest.mark.parametrize(
("enum_type",),
[
(JsTrue,),
(JsFalse,),
(JsBool,),
(JsNull,),
(ControlsLayout,),
(ControlsBackArrows,),
(SlideNumber,),
(ShowSlideNumber,),
(KeyboardCondition,),
(NavigationMode,),
(AutoPlayMedia,),
(PreloadIframes,),
(AutoAnimateMatcher,),
(AutoAnimateEasing,),
(AutoSlideMethod,),
(Transition,),
(TransitionSpeed,),
(BackgroundSize,),
(BackgroundTransition,),
(Display,),
(RevealTheme,),
],
)
def test_format_enum(enum_type: EnumMeta) -> None:
for enum in enum_type: # type: ignore[var-annotated]
expected = str(enum)
got = f"{enum}"
assert expected == got
got = "{enum}".format(enum=enum)
assert expected == got
got = format(enum, "")
assert expected == got
@pytest.mark.parametrize(
("enum_type",),
[
(ControlsLayout,),
(ControlsBackArrows,),
(SlideNumber,),
(ShowSlideNumber,),
(KeyboardCondition,),
(NavigationMode,),
(AutoPlayMedia,),
(PreloadIframes,),
(AutoAnimateMatcher,),
(AutoAnimateEasing,),
(AutoSlideMethod,),
(Transition,),
(TransitionSpeed,),
(BackgroundSize,),
(BackgroundTransition,),
(Display,),
],
)
def test_quoted_enum(enum_type: EnumMeta) -> None:
for enum in enum_type: # type: ignore[var-annotated]
if enum in ["true", "false", "null"]:
continue
expected = "'" + enum.value + "'"
got = str(enum)
assert expected == got
@pytest.mark.parametrize(
("enum_type",),
[
(JsTrue,),
(JsFalse,),
(JsBool,),
(JsNull,),
(RevealTheme,),
],
)
def test_unquoted_enum(enum_type: EnumMeta) -> None:
for enum in enum_type: # type: ignore[var-annotated]
expected = enum.value
got = str(enum)
assert expected == got
class TestConverter: