Video editing with Python
Add tests for rotate FX behaviour when Pillow is not installed (#1544)
Álvaro Mondéjarf3c6342fac71
diff --git a/moviepy/video/fx/rotate.py b/moviepy/video/fx/rotate.pyindex 2ad41502..d30b6c45 100644--- a/moviepy/video/fx/rotate.py+++ b/moviepy/video/fx/rotate.py@@ -26,7 +26,7 @@ try:Image = PIL.Image-except ImportError:+except ImportError: # pragma: no coverImage = Nonediff --git a/setup.cfg b/setup.cfgindex 87a4d563..980f1be4 100644--- a/setup.cfg+++ b/setup.cfg@@ -47,3 +47,7 @@ include_trailing_comma = Truepy_version = 36known_tests = testssections = STDLIB,THIRDPARTY,FIRSTPARTY,TESTS,LOCALFOLDER++[coverage:report]+exclude_lines =+ pragma: no coverdiff --git a/tests/test_fx.py b/tests/test_fx.pyindex 30d75fa9..2fabf11a 100644--- a/tests/test_fx.py+++ b/tests/test_fx.py@@ -1,4 +1,5 @@import decimal+import importlibimport mathimport numbersimport os@@ -759,6 +760,7 @@ def test_resize(# Run several times to ensure that adding 360 to rotation angles has no effect[email protected]("PIL_installed", (True, False))@pytest.mark.parametrize("angle_offset", [-360, 0, 360, 720])@pytest.mark.parametrize("unit", ["deg", "rad"])@pytest.mark.parametrize("resample", ["bilinear", "nearest", "bicubic", "unknown"])@@ -839,6 +841,7 @@ def test_resize(),)def test_rotate(+ PIL_installed,angle_offset,angle,unit,@@ -847,6 +850,7 @@ def test_rotate(center,bg_color,expected_frames,+ monkeypatch,):"""Check ``rotate`` FX behaviour against possible combinations of arguments."""original_frames = [["AAAA", "BBBB", "CCCC"], ["ABCD", "BCDE", "CDEA"]]@@ -875,11 +879,40 @@ def test_rotate("'resample' argument must be either 'bilinear', 'nearest' or 'bicubic'") == str(exc.value)return++ # if the scenario implies that PIL is not installed, monkeypatch the+ # module in which 'rotate' function resides+ if not PIL_installed:+ rotate_module = importlib.import_module("moviepy.video.fx.rotate")+ monkeypatch.setattr(rotate_module, "Image", None)+ rotate_func = rotate_module.rotate+ else:+ rotate_func = rotate++ # resolve the angle, because if it is a multiple of 90, the rotation+ # can be computed event without an available PIL installation+ if hasattr(_angle, "__call__"):+ _resolved_angle = _angle(0)+ else:+ _resolved_angle = _angle+ if unit == "rad":+ _resolved_angle = math.degrees(_resolved_angle)++ if not PIL_installed and (+ (_resolved_angle % 90 != 0) or center or translate or bg_color+ ):+ with pytest.raises(ValueError) as exc:+ rotated_clip = clip.fx(rotate_func, _angle, **kwargs)++ assert (+ 'Without "Pillow" installed, only angles that are a multiple of 90'+ ) in str(exc.value)+else:- rotated_clip = clip.rotate(_angle, **kwargs)+ rotated_clip = clip.fx(rotate_func, _angle, **kwargs)+ expected_clip = BitmapClip(expected_frames, fps=1)- expected_clip = BitmapClip(expected_frames, fps=1)- assert rotated_clip.to_bitmap() == expected_clip.to_bitmap()+ assert rotated_clip.to_bitmap() == expected_clip.to_bitmap()def test_rotate_nonstandard_angles():