Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test 'rotate' FX supported arguments by PIL version #1545

Merged
merged 4 commits into from
Apr 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions moviepy/video/fx/rotate.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,10 @@ def filter(get_frame, t):
else:
if kw_value is not None: # if not default value
warnings.warn(
f"rotate '{kw_name}' argument not supported by your"
" Pillow version and is being ignored. Minimum Pillow version"
f" required: v{'.'.join(str(n) for n in min_version)}",
f"rotate '{kw_name}' argument is not supported"
" by your Pillow version and is being ignored. Minimum"
" Pillow version required:"
f" v{'.'.join(str(n) for n in min_version)}",
UserWarning,
)

Expand Down
69 changes: 68 additions & 1 deletion tests/test_fx.py
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,6 @@ def test_resize(
assert len(mask_frame) == expected_height


# Run several times to ensure that adding 360 to rotation angles has no effect
@pytest.mark.parametrize("PIL_installed", (True, False))
@pytest.mark.parametrize("angle_offset", [-360, 0, 360, 720])
@pytest.mark.parametrize("unit", ["deg", "rad"])
Expand Down Expand Up @@ -934,6 +933,74 @@ def test_rotate_mask():
assert clip.get_frame(0)[1][1] != 0


@pytest.mark.parametrize(
("unsupported_kwargs",),
(
(["bg_color"],),
(["center"],),
(["translate"],),
(["translate", "center"],),
(["center", "bg_color", "translate"],),
),
ids=(
"bg_color",
"center",
"translate",
"translate,center",
"center,bg_color,translate",
),
)
def test_rotate_supported_PIL_kwargs(
unsupported_kwargs,
monkeypatch,
):
"""Test supported 'rotate' FX arguments by PIL version."""
rotate_module = importlib.import_module("moviepy.video.fx.rotate")

# patch supported kwargs data by PIL version
new_PIL_rotate_kwargs_supported, min_version_by_kwarg_name = ({}, {})
for kwarg, (
kw_name,
supported,
min_version,
) in rotate_module.PIL_rotate_kwargs_supported.items():
supported = kw_name not in unsupported_kwargs
new_PIL_rotate_kwargs_supported[kwarg] = [kw_name, supported, min_version]

min_version_by_kwarg_name[kw_name] = ".".join(str(n) for n in min_version)

monkeypatch.setattr(
rotate_module,
"PIL_rotate_kwargs_supported",
new_PIL_rotate_kwargs_supported,
)

with pytest.warns(UserWarning) as record:
BitmapClip([["R", "G", "B"]], fps=1).fx(
rotate_module.rotate,
45,
bg_color=(10, 10, 10),
center=(1, 1),
translate=(1, 0),
)

# assert number of warnings
assert len(record.list) == len(unsupported_kwargs)

# assert messages contents
messages = []
for warning in record.list:
messages.append(warning.message.args[0])

for unsupported_kwarg in unsupported_kwargs:
expected_message = (
f"rotate '{unsupported_kwarg}' argument is not supported by your"
" Pillow version and is being ignored. Minimum Pillow version"
f" required: v{min_version_by_kwarg_name[unsupported_kwarg]}"
)
assert expected_message in messages


def test_scroll():
pass

Expand Down