From de5eb1155648b00f732dce36918e9b9b7858fa48 Mon Sep 17 00:00:00 2001 From: Pedro Valois Date: Sat, 30 Sep 2023 14:11:00 +0900 Subject: [PATCH 01/12] basic trim tests --- tests/test_trim.py | 56 +++++++++++++++++++++++++++++++++++++++------- 1 file changed, 48 insertions(+), 8 deletions(-) diff --git a/tests/test_trim.py b/tests/test_trim.py index 60fb4f7..b2fd9e9 100644 --- a/tests/test_trim.py +++ b/tests/test_trim.py @@ -1,22 +1,62 @@ -import src as pyclip +""" +Tests for the trim method of the Video class. -import pytest +References: + - https://zulko.github.io/moviepy/ref/Clip.html?highlight=subclip#moviepy.Clip.Clip.subclip -def test_sanity(): - assert 1 == 1 +""" + +import src as pyclip +from src import Trim +import pytest @pytest.fixture -def mock_video(): +def mock_video() -> pyclip.Video: + """Fixture to generate a mock video for testing.""" return pyclip.RandomVideo() -def test_trim(mock_video): +def test_sanity(): + """Test sanity check.""" + assert 1 == 1 + +def test_trim(mock_video: pyclip.Video): + """Test trimming a video using seconds as unit.""" video = mock_video.trim(50, 1000) assert video.duration == 950 -def test_trim_by_frames(mock_video): +def test_trim_by_frames(mock_video: pyclip.Video): + """Test trimming a video using frames as unit.""" assert mock_video.trim(50, 100, unit="f") == mock_video[50:100] -def test_trim_negative(mock_video): +def test_trim_negative(mock_video: pyclip.Video): + """Test trimming with negative start frame raises a ValueError.""" with pytest.raises(ValueError): mock_video.trim(-100, 1000, unit="f") +def test_trim_class_operation(mock_video: pyclip.Video): + """Test using Trim class operation to trim a video.""" + transforms = [ + Trim(50, 100, unit="f") + ] + + assert mock_video.apply(transforms) == mock_video.trim(50, 100, unit="f") + +def test_trim_start_greater_than_end(mock_video: pyclip.Video): + """Test trimming with start time greater than end time raises a ValueError.""" + with pytest.raises(ValueError): + mock_video.trim(1000, 100) + +def test_trim_exceed_duration(mock_video: pyclip.Video): + """Test trimming with time range exceeding video duration raises an IndexError.""" + with pytest.raises(IndexError): + mock_video.trim(0, mock_video.duration + 1000) + +def test_trim_invalid_unit(mock_video: pyclip.Video): + """Test trimming with invalid unit raises a ValueError.""" + with pytest.raises(ValueError): + mock_video.trim(0, 100, unit="z") + +def test_trim_without_end(mock_video: pyclip.Video): + """Test trimming without specifying end trims to the end of the video.""" + trimmed = mock_video.trim(50) + assert trimmed.duration == mock_video.duration - 50 From e3ca2c2142c264244c0d30e81ef856a08c1b9c20 Mon Sep 17 00:00:00 2001 From: Pedro Valois Date: Fri, 6 Oct 2023 15:37:11 +0900 Subject: [PATCH 02/12] comments addressed on test_sanity --- tests/test_trim.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/tests/test_trim.py b/tests/test_trim.py index b2fd9e9..4ca8f2b 100644 --- a/tests/test_trim.py +++ b/tests/test_trim.py @@ -15,10 +15,6 @@ def mock_video() -> pyclip.Video: """Fixture to generate a mock video for testing.""" return pyclip.RandomVideo() -def test_sanity(): - """Test sanity check.""" - assert 1 == 1 - def test_trim(mock_video: pyclip.Video): """Test trimming a video using seconds as unit.""" video = mock_video.trim(50, 1000) From cf9d1dd702bbeca755877c9fa126f02f3d4486cd Mon Sep 17 00:00:00 2001 From: Pedro Valois Date: Fri, 6 Oct 2023 15:58:15 +0900 Subject: [PATCH 03/12] adding more typing and def to trim method --- pyclip/__init__.py | 2 ++ pyclip/core/video.py | 10 +++++++++- tests/test_trim.py | 1 + 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/pyclip/__init__.py b/pyclip/__init__.py index e69de29..073fed9 100644 --- a/pyclip/__init__.py +++ b/pyclip/__init__.py @@ -0,0 +1,2 @@ + +from .core.video import Video \ No newline at end of file diff --git a/pyclip/core/video.py b/pyclip/core/video.py index df6cab8..3fda223 100644 --- a/pyclip/core/video.py +++ b/pyclip/core/video.py @@ -1,7 +1,15 @@ +from __future__ import annotations + +class Model: + pass class Video(Model): - def trim(self): + def trim(self, t_start: float, t_end: float | None = None, unit: str = "s") -> Video: + """ + Returns a clip playing the content of the current clip + between times ``t_start`` and ``t_end`` + """ ... def mute(self, channels: int | list[int] | None = None): diff --git a/tests/test_trim.py b/tests/test_trim.py index b7d6687..e97551e 100644 --- a/tests/test_trim.py +++ b/tests/test_trim.py @@ -8,6 +8,7 @@ import pyclip from pyclip import Trim + import pytest @pytest.fixture From 7a217abfec39151e994d1acd4ed5998d9a9239d6 Mon Sep 17 00:00:00 2001 From: Pedro Valois Date: Fri, 6 Oct 2023 16:16:19 +0900 Subject: [PATCH 04/12] minor tweaks --- pyclip/core/video.py | 10 ++++++++-- tests/test_trim.py | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/pyclip/core/video.py b/pyclip/core/video.py index 3fda223..7a94e4d 100644 --- a/pyclip/core/video.py +++ b/pyclip/core/video.py @@ -5,10 +5,10 @@ class Model: class Video(Model): - def trim(self, t_start: float, t_end: float | None = None, unit: str = "s") -> Video: + def trim(self, start: float, end: float | None = None, unit: str = "ms") -> Video: """ Returns a clip playing the content of the current clip - between times ``t_start`` and ``t_end`` + between times `start` and `end` """ ... @@ -19,4 +19,10 @@ def resize(self, **kwargs): ... def upscale(self, **kwargs): + ... + + def rand(self): + ... + + def save(self, path: str | Path): ... \ No newline at end of file diff --git a/tests/test_trim.py b/tests/test_trim.py index e97551e..d404b96 100644 --- a/tests/test_trim.py +++ b/tests/test_trim.py @@ -14,7 +14,7 @@ @pytest.fixture def mock_video() -> pyclip.Video: """Fixture to generate a mock video for testing.""" - return pyclip.RandomVideo() + return pyclip.Video.rand() def test_trim(mock_video: pyclip.Video): """Test trimming a video using seconds as unit.""" From 31a20e44fd813266de26bfa35de520734aa47692 Mon Sep 17 00:00:00 2001 From: Pedro Valois Date: Fri, 6 Oct 2023 16:16:42 +0900 Subject: [PATCH 05/12] conversion tests --- tests/test_conversion.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 tests/test_conversion.py diff --git a/tests/test_conversion.py b/tests/test_conversion.py new file mode 100644 index 0000000..262fe49 --- /dev/null +++ b/tests/test_conversion.py @@ -0,0 +1,15 @@ +"""Conversion operation tests + +References: + - https://pillow.readthedocs.io/en/stable/reference/Image.html#PIL.Image.Image.save + +""" + +from pyclip import Video +import tempfile + +def test_convert_to_mp4(mock_video: Video): + with tempfile.NamedTemporaryFile(suffix=".mp4") as f: + mock_video.save(f.name) + + assert Video.from_file(f.name) == mock_video \ No newline at end of file From c32a47998bed62f541704b033004a60e361d018e Mon Sep 17 00:00:00 2001 From: Pedro Valois Date: Fri, 13 Oct 2023 14:55:30 +0900 Subject: [PATCH 06/12] fixes --- pyclip/core/video.py | 5 +++++ tests/test_conversion.py | 10 ++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/pyclip/core/video.py b/pyclip/core/video.py index 7a94e4d..0597972 100644 --- a/pyclip/core/video.py +++ b/pyclip/core/video.py @@ -1,5 +1,7 @@ from __future__ import annotations +from pathlib import Path + class Model: pass @@ -24,5 +26,8 @@ def upscale(self, **kwargs): def rand(self): ... + def open(self, path: str | Path): + ... + def save(self, path: str | Path): ... \ No newline at end of file diff --git a/tests/test_conversion.py b/tests/test_conversion.py index 262fe49..a94a8f6 100644 --- a/tests/test_conversion.py +++ b/tests/test_conversion.py @@ -8,8 +8,10 @@ from pyclip import Video import tempfile -def test_convert_to_mp4(mock_video: Video): - with tempfile.NamedTemporaryFile(suffix=".mp4") as f: - mock_video.save(f.name) +import pytest - assert Video.from_file(f.name) == mock_video \ No newline at end of file +@pytest.mark.parametrize("file_format", [("mp4"), ("avi")]) +def test_video_conversion(mock_video: Video, file_format: str): + with tempfile.NamedTemporaryFile(suffix=f".{file_format}") as f: + mock_video.save(f.name, format=file_format.upper()) + assert Video.open(f.name) == mock_video \ No newline at end of file From 054fea0775a2f3d06f5e21b6b0137ae5b9b1e236 Mon Sep 17 00:00:00 2001 From: Pedro Valois Date: Fri, 13 Oct 2023 14:57:46 +0900 Subject: [PATCH 07/12] test file created --- tests/test_rotate.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 tests/test_rotate.py diff --git a/tests/test_rotate.py b/tests/test_rotate.py new file mode 100644 index 0000000..e69de29 From 347ecc560ef42a54b80dcdaf78693505a72d2993 Mon Sep 17 00:00:00 2001 From: Pedro Valois Date: Fri, 13 Oct 2023 15:23:48 +0900 Subject: [PATCH 08/12] tests made --- tests/test_flip.py | 84 ++++++++++++++++++++++++++++++++++++++++++++ tests/test_rotate.py | 76 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 160 insertions(+) create mode 100644 tests/test_flip.py diff --git a/tests/test_flip.py b/tests/test_flip.py new file mode 100644 index 0000000..c43b47e --- /dev/null +++ b/tests/test_flip.py @@ -0,0 +1,84 @@ +"""Tests for the rotate and flip methods of the Video class. + +References: + - https://kornia.readthedocs.io/en/latest/geometry.transform.html#kornia.geometry.transform.hflip + - https://kornia.readthedocs.io/en/latest/geometry.transform.html#kornia.geometry.transform.vflip + +""" + +import pyclip +import pytest + +def test_flip_horizontal(mock_video: pyclip.Video): + """Test flipping a video horizontally.""" + flipped_once = mock_video.fliph() + assert flipped_once != mock_video + + flipped_twice = flipped_once.fliph() + assert flipped_twice == mock_video + +def test_flip_vertical(mock_video: pyclip.Video): + """Test flipping a video vertically.""" + flipped_once = mock_video.flipv() + assert flipped_once != mock_video + + flipped_twice = flipped_once.flipv() + assert flipped_twice == mock_video + +def test_flip_both(mock_video: pyclip.Video): + """Test flipping a video both horizontally and vertically.""" + assert mock_video.flip(horizontal=True, vertical=True) == mock_video.flipv().fliph() == mock_video.fliph().flipv() + +def test_flip_without_args(mock_video: pyclip.Video): + """Test flipping without any arguments should raise a ValueError.""" + with pytest.raises(ValueError): + mock_video.flip() + +def test_flip_audio_sync(mock_video: pyclip.Video): + """Test audio synchronization after flipping.""" + flipped = mock_video.fliph() + assert flipped.audio == mock_video.audio + +def test_flip_horizontal_and_vertical(mock_video: pyclip.Video): + """Test flipping a video horizontally and then vertically should equal flipping both at once.""" + flipped_sequentially = mock_video.fliph().flipv() + flipped_simultaneously = mock_video.flip(horizontal=True, vertical=True) + assert flipped_sequentially == flipped_simultaneously + +def test_flip_vertical_audio_sync(mock_video: pyclip.Video): + """Test audio synchronization after vertical flipping.""" + flipped = mock_video.flipv() + assert flipped.audio == mock_video.audio + +def test_flip_invalid_arguments(mock_video: pyclip.Video): + """Test flipping with an invalid argument type should raise a TypeError.""" + with pytest.raises(TypeError): + mock_video.flip(horizontal="True", vertical=True) + +def test_fliph_method_vs_flip_function(mock_video: pyclip.Video): + """Test equivalence of fliph method vs flip function with horizontal=True.""" + assert mock_video.fliph() == mock_video.flip(horizontal=True) + +def test_flipv_method_vs_flip_function(mock_video: pyclip.Video): + """Test equivalence of flipv method vs flip function with vertical=True.""" + assert mock_video.flipv() == mock_video.flip(vertical=True) + +def test_flip_with_both_false(mock_video: pyclip.Video): + """Test flipping with both horizontal and vertical set to False should return the original.""" + assert mock_video.flip(horizontal=False, vertical=False) == mock_video + +def test_flip_idempotence(mock_video: pyclip.Video): + """Test that flipping twice in any direction should return the original video.""" + assert mock_video.flip(horizontal=True, vertical=True).flip(horizontal=True, vertical=True) == mock_video.fliph().fliph() == mock_video.flipv().flipv() == mock_video + +def test_flip_chain_operations(mock_video: pyclip.Video): + """Test chaining multiple flip operations.""" + result = mock_video.fliph().flipv().fliph() + assert result == mock_video.flipv() + +def test_flip_no_audio(mock_video: pyclip.Video): + """Test flipping a video with no audio.""" + # Assuming the Video class has a method to remove audio + video_no_audio = mock_video.remove_audio() + flipped = video_no_audio.fliph() + assert flipped.audio is None diff --git a/tests/test_rotate.py b/tests/test_rotate.py index e69de29..7a61d95 100644 --- a/tests/test_rotate.py +++ b/tests/test_rotate.py @@ -0,0 +1,76 @@ +"""Tests for the rotate and flip methods of the Video class. + +References: + - https://kornia.readthedocs.io/en/latest/geometry.transform.html#kornia.geometry.transform.rotate + +""" + +import pyclip +import pytest + +def test_rotate_90_degrees(mock_video: pyclip.Video): + """Test rotating a video 90 degrees counter-clockwise.""" + rotated = mock_video.rotate(90) + assert rotated.width == mock_video.height + assert rotated.height == mock_video.width + +def test_rotate_with_center(mock_video: pyclip.Video): + """Test rotating a video about a specific center.""" + center = [mock_video.width // 2, mock_video.height // 2] + assert mock_video.rotate(45, center=center) == mock_video.rotate(45) + +def test_rotate_with_non_centered_axis(mock_video: pyclip.Video): + """Test rotating a video about a specific axis.""" + rotated = mock_video.rotate(45, center=[0, 0]) + +def test_rotate_180_degrees(mock_video: pyclip.Video): + """Test rotating a video 180 degrees counter-clockwise and checking its properties.""" + assert mock_video.rotate(180) == mock_video.flipv() + +def test_rotate_360_degrees(mock_video: pyclip.Video): + """Test rotating a video 360 degrees should be equal to the original.""" + assert mock_video.rotate(360) == mock_video + +def test_rotate_with_interpolation(mock_video: pyclip.Video): + """Test rotating a video with a specific interpolation.""" + rotated_bilinear = mock_video.rotate(45, mode='bilinear') + rotated_nearest = mock_video.rotate(45, mode='nearest') + + assert rotated_bilinear != rotated_nearest + assert rotated_bilinear.is_close(rotated_nearest) + +def test_rotate_with_padding_mode(mock_video: pyclip.Video): + """Test rotating a video with different padding modes.""" + rotated_zeros = mock_video.rotate(45, padding_mode='zeros') + rotated_border = mock_video.rotate(45, padding_mode='border') + rotated_reflection = mock_video.rotate(45, padding_mode='reflection') + + # Assuming Video class has a method to compare video content, e.g., is_close() + assert not rotated_zeros.is_close(rotated_border) + assert not rotated_zeros.is_close(rotated_reflection) + assert not rotated_border.is_close(rotated_reflection) + +def test_rotate_audio_sync(mock_video: pyclip.Video): + """Test audio synchronization after rotation.""" + rotated = mock_video.rotate(45) + assert rotated.audio == mock_video.audio + +def test_rotate_invalid_angle(mock_video: pyclip.Video): + """Test rotating with an invalid angle type should raise a TypeError.""" + with pytest.raises(TypeError): + mock_video.rotate("invalid_angle") + +def test_rotate_invalid_interpolation(mock_video: pyclip.Video): + """Test rotating with an invalid interpolation mode should raise a ValueError.""" + with pytest.raises(ValueError): + mock_video.rotate(45, mode='invalid_mode') + +def test_rotate_invalid_padding_mode(mock_video: pyclip.Video): + """Test rotating with an invalid padding mode should raise a ValueError.""" + with pytest.raises(ValueError): + mock_video.rotate(45, padding_mode='invalid_padding') + +def test_rotate_invalid_center(mock_video: pyclip.Video): + """Test rotating with an invalid center type should raise a TypeError.""" + with pytest.raises(TypeError): + mock_video.rotate(45, center="invalid_center") From 0136a3b7080f89be1f758e7bcd3781c14634255f Mon Sep 17 00:00:00 2001 From: Pedro Valois Date: Fri, 13 Oct 2023 16:15:50 +0900 Subject: [PATCH 09/12] reviewed in meeting --- tests/test_rotate.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/tests/test_rotate.py b/tests/test_rotate.py index 7a61d95..a3fa488 100644 --- a/tests/test_rotate.py +++ b/tests/test_rotate.py @@ -11,18 +11,14 @@ def test_rotate_90_degrees(mock_video: pyclip.Video): """Test rotating a video 90 degrees counter-clockwise.""" rotated = mock_video.rotate(90) - assert rotated.width == mock_video.height - assert rotated.height == mock_video.width + assert rotated.width == mock_video.width + assert rotated.height == mock_video.height def test_rotate_with_center(mock_video: pyclip.Video): """Test rotating a video about a specific center.""" center = [mock_video.width // 2, mock_video.height // 2] assert mock_video.rotate(45, center=center) == mock_video.rotate(45) -def test_rotate_with_non_centered_axis(mock_video: pyclip.Video): - """Test rotating a video about a specific axis.""" - rotated = mock_video.rotate(45, center=[0, 0]) - def test_rotate_180_degrees(mock_video: pyclip.Video): """Test rotating a video 180 degrees counter-clockwise and checking its properties.""" assert mock_video.rotate(180) == mock_video.flipv() From 28af4dcf20161fdb9fe92acab6e0e82bc895eab4 Mon Sep 17 00:00:00 2001 From: Pedro Valois Date: Fri, 13 Oct 2023 14:57:46 +0900 Subject: [PATCH 10/12] test file created --- tests/test_rotate.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 tests/test_rotate.py diff --git a/tests/test_rotate.py b/tests/test_rotate.py new file mode 100644 index 0000000..e69de29 From c6aa21f55d30034c050601fd2391a6c25e485ed7 Mon Sep 17 00:00:00 2001 From: Pedro Valois Date: Fri, 13 Oct 2023 15:23:48 +0900 Subject: [PATCH 11/12] tests made --- tests/test_flip.py | 84 ++++++++++++++++++++++++++++++++++++++++++++ tests/test_rotate.py | 76 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 160 insertions(+) create mode 100644 tests/test_flip.py diff --git a/tests/test_flip.py b/tests/test_flip.py new file mode 100644 index 0000000..c43b47e --- /dev/null +++ b/tests/test_flip.py @@ -0,0 +1,84 @@ +"""Tests for the rotate and flip methods of the Video class. + +References: + - https://kornia.readthedocs.io/en/latest/geometry.transform.html#kornia.geometry.transform.hflip + - https://kornia.readthedocs.io/en/latest/geometry.transform.html#kornia.geometry.transform.vflip + +""" + +import pyclip +import pytest + +def test_flip_horizontal(mock_video: pyclip.Video): + """Test flipping a video horizontally.""" + flipped_once = mock_video.fliph() + assert flipped_once != mock_video + + flipped_twice = flipped_once.fliph() + assert flipped_twice == mock_video + +def test_flip_vertical(mock_video: pyclip.Video): + """Test flipping a video vertically.""" + flipped_once = mock_video.flipv() + assert flipped_once != mock_video + + flipped_twice = flipped_once.flipv() + assert flipped_twice == mock_video + +def test_flip_both(mock_video: pyclip.Video): + """Test flipping a video both horizontally and vertically.""" + assert mock_video.flip(horizontal=True, vertical=True) == mock_video.flipv().fliph() == mock_video.fliph().flipv() + +def test_flip_without_args(mock_video: pyclip.Video): + """Test flipping without any arguments should raise a ValueError.""" + with pytest.raises(ValueError): + mock_video.flip() + +def test_flip_audio_sync(mock_video: pyclip.Video): + """Test audio synchronization after flipping.""" + flipped = mock_video.fliph() + assert flipped.audio == mock_video.audio + +def test_flip_horizontal_and_vertical(mock_video: pyclip.Video): + """Test flipping a video horizontally and then vertically should equal flipping both at once.""" + flipped_sequentially = mock_video.fliph().flipv() + flipped_simultaneously = mock_video.flip(horizontal=True, vertical=True) + assert flipped_sequentially == flipped_simultaneously + +def test_flip_vertical_audio_sync(mock_video: pyclip.Video): + """Test audio synchronization after vertical flipping.""" + flipped = mock_video.flipv() + assert flipped.audio == mock_video.audio + +def test_flip_invalid_arguments(mock_video: pyclip.Video): + """Test flipping with an invalid argument type should raise a TypeError.""" + with pytest.raises(TypeError): + mock_video.flip(horizontal="True", vertical=True) + +def test_fliph_method_vs_flip_function(mock_video: pyclip.Video): + """Test equivalence of fliph method vs flip function with horizontal=True.""" + assert mock_video.fliph() == mock_video.flip(horizontal=True) + +def test_flipv_method_vs_flip_function(mock_video: pyclip.Video): + """Test equivalence of flipv method vs flip function with vertical=True.""" + assert mock_video.flipv() == mock_video.flip(vertical=True) + +def test_flip_with_both_false(mock_video: pyclip.Video): + """Test flipping with both horizontal and vertical set to False should return the original.""" + assert mock_video.flip(horizontal=False, vertical=False) == mock_video + +def test_flip_idempotence(mock_video: pyclip.Video): + """Test that flipping twice in any direction should return the original video.""" + assert mock_video.flip(horizontal=True, vertical=True).flip(horizontal=True, vertical=True) == mock_video.fliph().fliph() == mock_video.flipv().flipv() == mock_video + +def test_flip_chain_operations(mock_video: pyclip.Video): + """Test chaining multiple flip operations.""" + result = mock_video.fliph().flipv().fliph() + assert result == mock_video.flipv() + +def test_flip_no_audio(mock_video: pyclip.Video): + """Test flipping a video with no audio.""" + # Assuming the Video class has a method to remove audio + video_no_audio = mock_video.remove_audio() + flipped = video_no_audio.fliph() + assert flipped.audio is None diff --git a/tests/test_rotate.py b/tests/test_rotate.py index e69de29..7a61d95 100644 --- a/tests/test_rotate.py +++ b/tests/test_rotate.py @@ -0,0 +1,76 @@ +"""Tests for the rotate and flip methods of the Video class. + +References: + - https://kornia.readthedocs.io/en/latest/geometry.transform.html#kornia.geometry.transform.rotate + +""" + +import pyclip +import pytest + +def test_rotate_90_degrees(mock_video: pyclip.Video): + """Test rotating a video 90 degrees counter-clockwise.""" + rotated = mock_video.rotate(90) + assert rotated.width == mock_video.height + assert rotated.height == mock_video.width + +def test_rotate_with_center(mock_video: pyclip.Video): + """Test rotating a video about a specific center.""" + center = [mock_video.width // 2, mock_video.height // 2] + assert mock_video.rotate(45, center=center) == mock_video.rotate(45) + +def test_rotate_with_non_centered_axis(mock_video: pyclip.Video): + """Test rotating a video about a specific axis.""" + rotated = mock_video.rotate(45, center=[0, 0]) + +def test_rotate_180_degrees(mock_video: pyclip.Video): + """Test rotating a video 180 degrees counter-clockwise and checking its properties.""" + assert mock_video.rotate(180) == mock_video.flipv() + +def test_rotate_360_degrees(mock_video: pyclip.Video): + """Test rotating a video 360 degrees should be equal to the original.""" + assert mock_video.rotate(360) == mock_video + +def test_rotate_with_interpolation(mock_video: pyclip.Video): + """Test rotating a video with a specific interpolation.""" + rotated_bilinear = mock_video.rotate(45, mode='bilinear') + rotated_nearest = mock_video.rotate(45, mode='nearest') + + assert rotated_bilinear != rotated_nearest + assert rotated_bilinear.is_close(rotated_nearest) + +def test_rotate_with_padding_mode(mock_video: pyclip.Video): + """Test rotating a video with different padding modes.""" + rotated_zeros = mock_video.rotate(45, padding_mode='zeros') + rotated_border = mock_video.rotate(45, padding_mode='border') + rotated_reflection = mock_video.rotate(45, padding_mode='reflection') + + # Assuming Video class has a method to compare video content, e.g., is_close() + assert not rotated_zeros.is_close(rotated_border) + assert not rotated_zeros.is_close(rotated_reflection) + assert not rotated_border.is_close(rotated_reflection) + +def test_rotate_audio_sync(mock_video: pyclip.Video): + """Test audio synchronization after rotation.""" + rotated = mock_video.rotate(45) + assert rotated.audio == mock_video.audio + +def test_rotate_invalid_angle(mock_video: pyclip.Video): + """Test rotating with an invalid angle type should raise a TypeError.""" + with pytest.raises(TypeError): + mock_video.rotate("invalid_angle") + +def test_rotate_invalid_interpolation(mock_video: pyclip.Video): + """Test rotating with an invalid interpolation mode should raise a ValueError.""" + with pytest.raises(ValueError): + mock_video.rotate(45, mode='invalid_mode') + +def test_rotate_invalid_padding_mode(mock_video: pyclip.Video): + """Test rotating with an invalid padding mode should raise a ValueError.""" + with pytest.raises(ValueError): + mock_video.rotate(45, padding_mode='invalid_padding') + +def test_rotate_invalid_center(mock_video: pyclip.Video): + """Test rotating with an invalid center type should raise a TypeError.""" + with pytest.raises(TypeError): + mock_video.rotate(45, center="invalid_center") From 458bd93c900d10a064eed86e94c08ff7ce4017f6 Mon Sep 17 00:00:00 2001 From: Pedro Valois Date: Fri, 13 Oct 2023 16:15:50 +0900 Subject: [PATCH 12/12] reviewed in meeting --- tests/test_rotate.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/tests/test_rotate.py b/tests/test_rotate.py index 7a61d95..a3fa488 100644 --- a/tests/test_rotate.py +++ b/tests/test_rotate.py @@ -11,18 +11,14 @@ def test_rotate_90_degrees(mock_video: pyclip.Video): """Test rotating a video 90 degrees counter-clockwise.""" rotated = mock_video.rotate(90) - assert rotated.width == mock_video.height - assert rotated.height == mock_video.width + assert rotated.width == mock_video.width + assert rotated.height == mock_video.height def test_rotate_with_center(mock_video: pyclip.Video): """Test rotating a video about a specific center.""" center = [mock_video.width // 2, mock_video.height // 2] assert mock_video.rotate(45, center=center) == mock_video.rotate(45) -def test_rotate_with_non_centered_axis(mock_video: pyclip.Video): - """Test rotating a video about a specific axis.""" - rotated = mock_video.rotate(45, center=[0, 0]) - def test_rotate_180_degrees(mock_video: pyclip.Video): """Test rotating a video 180 degrees counter-clockwise and checking its properties.""" assert mock_video.rotate(180) == mock_video.flipv()