From 3097122f36d1b717c2e428173cf539c5e4c65a2c Mon Sep 17 00:00:00 2001 From: jxnior01 Date: Thu, 15 Jun 2023 17:54:32 +0200 Subject: [PATCH 1/9] added @property width and height that returns the width and height of the image in pixels respectively --- src/safeds/data/image/containers/_image.py | 24 ++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/safeds/data/image/containers/_image.py b/src/safeds/data/image/containers/_image.py index cd72d43a7..792e5ba60 100644 --- a/src/safeds/data/image/containers/_image.py +++ b/src/safeds/data/image/containers/_image.py @@ -82,6 +82,30 @@ def format(self) -> ImageFormat: """ return self._format + @property + def width(self) -> int: + """ + Get the width of the image in pixels. + + Returns + ------- + width : int + The width of the image. + """ + return self._image.width + + @property + def height(self) -> int: + """ + Get the height of the image in pixels. + + Returns + ------- + height : int + The height of the image. + """ + return self._image.height + # ------------------------------------------------------------------------------------------------------------------ # Conversion # ------------------------------------------------------------------------------------------------------------------ From 52f5f6bd3605c752652ce11e77291d5d5fbab84f Mon Sep 17 00:00:00 2001 From: jxnior01 Date: Fri, 16 Jun 2023 09:32:52 +0200 Subject: [PATCH 2/9] Added test for width and height properties --- .../safeds/data/image/containers/test_image.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tests/safeds/data/image/containers/test_image.py b/tests/safeds/data/image/containers/test_image.py index ec8cf6ee0..1c218db27 100644 --- a/tests/safeds/data/image/containers/test_image.py +++ b/tests/safeds/data/image/containers/test_image.py @@ -152,3 +152,21 @@ def test_should_return_bytes_if_image_is_png(self, image: Image) -> None: ) def test_should_return_none_if_image_is_not_png(self, image: Image) -> None: assert image._repr_png_() is None + + +class TestProperties: + @pytest.mark.parametrize( + ("image", "width", "height"), + [ + ( + Image.from_jpeg_file(resolve_resource_path("image/white_square.jpg")), + 1, + 1, + ), + ], + ids=[".jpg"], + ) + def test_should_return_image_properties(self, image: Image, width: int, height: int) -> None: + assert image._image.width == width + assert image._image.height == height + From 8567f400ce7c5af47934abf7dfa2edb7882b4215 Mon Sep 17 00:00:00 2001 From: megalinter-bot <129584137+megalinter-bot@users.noreply.github.com> Date: Fri, 16 Jun 2023 07:39:22 +0000 Subject: [PATCH 3/9] style: apply automated linter fixes --- tests/safeds/data/image/containers/test_image.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/safeds/data/image/containers/test_image.py b/tests/safeds/data/image/containers/test_image.py index 1c218db27..a94aae7c4 100644 --- a/tests/safeds/data/image/containers/test_image.py +++ b/tests/safeds/data/image/containers/test_image.py @@ -169,4 +169,3 @@ class TestProperties: def test_should_return_image_properties(self, image: Image, width: int, height: int) -> None: assert image._image.width == width assert image._image.height == height - From c3b21e35f3e490bfb01bb385776a031643e1b337 Mon Sep 17 00:00:00 2001 From: jxnior01 Date: Fri, 16 Jun 2023 09:45:49 +0200 Subject: [PATCH 4/9] removed ._image for code coverage issues --- tests/safeds/data/image/containers/test_image.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/safeds/data/image/containers/test_image.py b/tests/safeds/data/image/containers/test_image.py index 1c218db27..e8a587474 100644 --- a/tests/safeds/data/image/containers/test_image.py +++ b/tests/safeds/data/image/containers/test_image.py @@ -167,6 +167,6 @@ class TestProperties: ids=[".jpg"], ) def test_should_return_image_properties(self, image: Image, width: int, height: int) -> None: - assert image._image.width == width - assert image._image.height == height + assert image.width == width + assert image.height == height From 22b57c474a42bc9faa9237962314569afbc46275 Mon Sep 17 00:00:00 2001 From: jxnior01 Date: Fri, 16 Jun 2023 09:47:09 +0200 Subject: [PATCH 5/9] removed ._image for code coverage issues --- tests/safeds/data/image/containers/test_image.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/safeds/data/image/containers/test_image.py b/tests/safeds/data/image/containers/test_image.py index a94aae7c4..556ca73a1 100644 --- a/tests/safeds/data/image/containers/test_image.py +++ b/tests/safeds/data/image/containers/test_image.py @@ -167,5 +167,5 @@ class TestProperties: ids=[".jpg"], ) def test_should_return_image_properties(self, image: Image, width: int, height: int) -> None: - assert image._image.width == width - assert image._image.height == height + assert image.width == width + assert image.height == height From 6c0c60849c2bf187b5a3ed044f476cb1ff13c591 Mon Sep 17 00:00:00 2001 From: jxnior01 Date: Fri, 16 Jun 2023 10:09:25 +0200 Subject: [PATCH 6/9] tested .png image to compare different pixels --- tests/safeds/data/image/containers/test_image.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tests/safeds/data/image/containers/test_image.py b/tests/safeds/data/image/containers/test_image.py index 556ca73a1..877132b24 100644 --- a/tests/safeds/data/image/containers/test_image.py +++ b/tests/safeds/data/image/containers/test_image.py @@ -163,8 +163,13 @@ class TestProperties: 1, 1, ), + ( + Image.from_png_file(resolve_resource_path("image/snapshot_boxplot.png")), + 640, + 480, + ), ], - ids=[".jpg"], + ids=["[1,1].jpg", "[640,480].png"], ) def test_should_return_image_properties(self, image: Image, width: int, height: int) -> None: assert image.width == width From c05318ae550b8578132bb26dee3b977057f7c74e Mon Sep 17 00:00:00 2001 From: jxnior01 Date: Fri, 16 Jun 2023 10:41:58 +0200 Subject: [PATCH 7/9] resolved conflicts resulting from main into branch merge --- .../data/image/containers/test_image.py | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/safeds/data/image/containers/test_image.py b/tests/safeds/data/image/containers/test_image.py index e4b0a87c9..29164d27f 100644 --- a/tests/safeds/data/image/containers/test_image.py +++ b/tests/safeds/data/image/containers/test_image.py @@ -54,6 +54,28 @@ def test_should_return_correct_format(self, image: Image, format_: ImageFormat) assert image.format == format_ +class TestProperties: + @pytest.mark.parametrize( + ("image", "width", "height"), + [ + ( + Image.from_jpeg_file(resolve_resource_path("image/white_square.jpg")), + 1, + 1, + ), + ( + Image.from_png_file(resolve_resource_path("image/snapshot_boxplot.png")), + 640, + 480, + ), + ], + ids=["[1,1].jpg", "[640,480].png"], + ) + def test_should_return_image_properties(self, image: Image, width: int, height: int) -> None: + assert image.width == width + assert image.height == height + + class TestToJpegFile: @pytest.mark.parametrize( "path", From 6a436a0d99e3d500852dab5c80d2e121e71309ce Mon Sep 17 00:00:00 2001 From: jxnior01 Date: Fri, 16 Jun 2023 12:57:22 +0200 Subject: [PATCH 8/9] is code-cov down? --- tests/safeds/data/image/containers/test_image.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/safeds/data/image/containers/test_image.py b/tests/safeds/data/image/containers/test_image.py index 29164d27f..40d258526 100644 --- a/tests/safeds/data/image/containers/test_image.py +++ b/tests/safeds/data/image/containers/test_image.py @@ -194,6 +194,7 @@ class TestResize: ), ], ids=[".jpg", ".png"], + ) def test_should_return_resized_image( self, From 4df40f717d26c6511c29813e8ef28cc78478b69b Mon Sep 17 00:00:00 2001 From: megalinter-bot <129584137+megalinter-bot@users.noreply.github.com> Date: Fri, 16 Jun 2023 10:59:18 +0000 Subject: [PATCH 9/9] style: apply automated linter fixes --- tests/safeds/data/image/containers/test_image.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/safeds/data/image/containers/test_image.py b/tests/safeds/data/image/containers/test_image.py index 40d258526..29164d27f 100644 --- a/tests/safeds/data/image/containers/test_image.py +++ b/tests/safeds/data/image/containers/test_image.py @@ -194,7 +194,6 @@ class TestResize: ), ], ids=[".jpg", ".png"], - ) def test_should_return_resized_image( self,