From 85b9819ddd0d0908c5d2b91d7a2210e39d079063 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Mond=C3=A9jar?= Date: Thu, 15 Apr 2021 20:40:58 +0200 Subject: [PATCH 1/4] Add test for supported 'rotate' kwargs by PIL version --- moviepy/video/fx/rotate.py | 7 ++-- tests/test_fx.py | 66 +++++++++++++++++++++++++++++++++++++- 2 files changed, 69 insertions(+), 4 deletions(-) diff --git a/moviepy/video/fx/rotate.py b/moviepy/video/fx/rotate.py index d30b6c451..51593e031 100644 --- a/moviepy/video/fx/rotate.py +++ b/moviepy/video/fx/rotate.py @@ -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 '{PIL_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, ) diff --git a/tests/test_fx.py b/tests/test_fx.py index 2fabf11af..378ac5518 100644 --- a/tests/test_fx.py +++ b/tests/test_fx.py @@ -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"]) @@ -934,6 +933,71 @@ def test_rotate_mask(): assert clip.get_frame(0)[1][1] != 0 +@pytest.mark.parametrize( + ("unsupported_kwargs",), + ( + (["fillcolor"],), + (["center"],), + (["translate"],), + (["translate", "center"],), + (["center", "fillcolor", "translate"],), + ), + ids=( + "fillcolor", + "center", + "translate", + "translate,center", + "center,fillcolor,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 = {} + for kwarg, support_data in rotate_module.PIL_rotate_kwargs_supported.items(): + support_data[1] = kwarg not in unsupported_kwargs + new_PIL_rotate_kwargs_supported[kwarg] = support_data + + monkeypatch.setattr( + rotate_module, + "PIL_rotate_kwargs_supported", + new_PIL_rotate_kwargs_supported, + ) + + with pytest.warns(UserWarning) as records: + 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(records.list) == len(unsupported_kwargs) + + # assert messages contents + messages = [] + for record in records.list: + messages.append(record.message.args[0]) + + for unsupported_kwarg in unsupported_kwargs: + min_version_required = ".".join( + str(n) for n in new_PIL_rotate_kwargs_supported[unsupported_kwarg][2] + ) + 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_required}" + ) + assert expected_message in messages + + def test_scroll(): pass From fb3070ded953d1904c48ca032ee1b0908cefc72f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Mond=C3=A9jar?= Date: Thu, 15 Apr 2021 20:49:00 +0200 Subject: [PATCH 2/4] Fix argument name error --- moviepy/video/fx/rotate.py | 2 +- tests/test_fx.py | 24 ++++++++++++++++-------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/moviepy/video/fx/rotate.py b/moviepy/video/fx/rotate.py index 51593e031..592553cfe 100644 --- a/moviepy/video/fx/rotate.py +++ b/moviepy/video/fx/rotate.py @@ -137,7 +137,7 @@ def filter(get_frame, t): else: if kw_value is not None: # if not default value warnings.warn( - f"rotate '{PIL_rotate_kw_name}' argument is not supported" + 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)}", diff --git a/tests/test_fx.py b/tests/test_fx.py index 378ac5518..281acb6bf 100644 --- a/tests/test_fx.py +++ b/tests/test_fx.py @@ -936,18 +936,18 @@ def test_rotate_mask(): @pytest.mark.parametrize( ("unsupported_kwargs",), ( - (["fillcolor"],), + (["bg_color"],), (["center"],), (["translate"],), (["translate", "center"],), - (["center", "fillcolor", "translate"],), + (["center", "bg_color", "translate"],), ), ids=( - "fillcolor", + "bg_color", "center", "translate", "translate,center", - "center,fillcolor,translate", + "center,bg_color,translate", ), ) def test_rotate_supported_PIL_kwargs( @@ -959,9 +959,17 @@ def test_rotate_supported_PIL_kwargs( # patch supported kwargs data by PIL version new_PIL_rotate_kwargs_supported = {} - for kwarg, support_data in rotate_module.PIL_rotate_kwargs_supported.items(): - support_data[1] = kwarg not in unsupported_kwargs - new_PIL_rotate_kwargs_supported[kwarg] = support_data + + 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] = min_version monkeypatch.setattr( rotate_module, @@ -988,7 +996,7 @@ def test_rotate_supported_PIL_kwargs( for unsupported_kwarg in unsupported_kwargs: min_version_required = ".".join( - str(n) for n in new_PIL_rotate_kwargs_supported[unsupported_kwarg][2] + str(n) for n in min_version_by_kwarg_name[unsupported_kwarg] ) expected_message = ( f"rotate '{unsupported_kwarg}' argument is not supported by your" From 377f7d3652eb8abec37a8b4e83ae8c5c3a8a4299 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Mond=C3=A9jar?= Date: Thu, 15 Apr 2021 20:53:51 +0200 Subject: [PATCH 3/4] Simplify test --- tests/test_fx.py | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/tests/test_fx.py b/tests/test_fx.py index 281acb6bf..26aa9fd24 100644 --- a/tests/test_fx.py +++ b/tests/test_fx.py @@ -958,9 +958,7 @@ def test_rotate_supported_PIL_kwargs( 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 = {} + new_PIL_rotate_kwargs_supported, min_version_by_kwarg_name = ({}, {}) for kwarg, ( kw_name, supported, @@ -969,7 +967,7 @@ def test_rotate_supported_PIL_kwargs( 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] = min_version + min_version_by_kwarg_name[kw_name] = ".".join(str(n) for n in min_version) monkeypatch.setattr( rotate_module, @@ -995,13 +993,10 @@ def test_rotate_supported_PIL_kwargs( messages.append(record.message.args[0]) for unsupported_kwarg in unsupported_kwargs: - min_version_required = ".".join( - str(n) for n in min_version_by_kwarg_name[unsupported_kwarg] - ) 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_required}" + f" required: v{min_version_by_kwarg_name[unsupported_kwarg]}" ) assert expected_message in messages From d48443db747b9b47c99f56a666fd9ce0449c128d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Mond=C3=A9jar?= Date: Thu, 15 Apr 2021 21:06:43 +0200 Subject: [PATCH 4/4] Change variable name --- tests/test_fx.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/test_fx.py b/tests/test_fx.py index 26aa9fd24..c06823692 100644 --- a/tests/test_fx.py +++ b/tests/test_fx.py @@ -975,7 +975,7 @@ def test_rotate_supported_PIL_kwargs( new_PIL_rotate_kwargs_supported, ) - with pytest.warns(UserWarning) as records: + with pytest.warns(UserWarning) as record: BitmapClip([["R", "G", "B"]], fps=1).fx( rotate_module.rotate, 45, @@ -985,12 +985,12 @@ def test_rotate_supported_PIL_kwargs( ) # assert number of warnings - assert len(records.list) == len(unsupported_kwargs) + assert len(record.list) == len(unsupported_kwargs) # assert messages contents messages = [] - for record in records.list: - messages.append(record.message.args[0]) + for warning in record.list: + messages.append(warning.message.args[0]) for unsupported_kwarg in unsupported_kwargs: expected_message = (