Skip to content

Commit

Permalink
style: apply automated linter fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
megalinter-bot committed Apr 4, 2023
1 parent f623c1f commit 29a2ee3
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 42 deletions.
2 changes: 1 addition & 1 deletion src/safeds/data/image/containers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
from ._image import Image

__all__ = [
'Image',
"Image",
]
3 changes: 2 additions & 1 deletion src/safeds/data/image/containers/_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
from pathlib import Path
from typing import BinaryIO

from PIL.Image import open as open_image, Image as PillowImage
from PIL.Image import Image as PillowImage
from PIL.Image import open as open_image

from safeds.data.image.typing import ImageFormat

Expand Down
2 changes: 1 addition & 1 deletion src/safeds/data/image/typing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
from ._image_format import ImageFormat

__all__ = [
'ImageFormat',
"ImageFormat",
]
5 changes: 3 additions & 2 deletions src/safeds/data/image/typing/_image_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@

class ImageFormat(Enum):
"""Images formats supported by us."""
JPEG = 'jpeg'
PNG = 'png'

JPEG = "jpeg"
PNG = "png"
5 changes: 2 additions & 3 deletions src/safeds/data/tabular/containers/_column.py
Original file line number Diff line number Diff line change
Expand Up @@ -497,14 +497,13 @@ def boxplot(self) -> Image:
plt.tight_layout()

buffer = io.BytesIO()
fig.savefig(buffer, format='png')
fig.savefig(buffer, format="png")
plt.close() # Prevents the figure from being displayed directly
buffer.seek(0)
return Image(buffer, ImageFormat.PNG)

def histogram(self) -> Image:
"""Plot a column in a histogram."""

fig = plt.figure()
ax = sns.histplot(data=self._data)
ax.set_xticks(ax.get_xticks())
Expand All @@ -517,7 +516,7 @@ def histogram(self) -> Image:
plt.tight_layout()

buffer = io.BytesIO()
fig.savefig(buffer, format='png')
fig.savefig(buffer, format="png")
plt.close() # Prevents the figure from being displayed directly
buffer.seek(0)
return Image(buffer, ImageFormat.PNG)
Expand Down
11 changes: 6 additions & 5 deletions src/safeds/data/tabular/containers/_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from scipy import stats

from safeds.data.image.containers import Image
from safeds.data.image.typing import ImageFormat
from safeds.data.tabular.typing import ColumnType, Schema
from safeds.exceptions import (
ColumnLengthMismatchError,
Expand All @@ -25,9 +26,9 @@
SchemaMismatchError,
UnknownColumnNameError,
)

from ._column import Column
from ._row import Row
from ...image.typing import ImageFormat

if TYPE_CHECKING:
from collections.abc import Callable, Iterable
Expand Down Expand Up @@ -822,7 +823,7 @@ def slice_rows(
def sort_columns(
self,
comparator: Callable[[Column, Column], int] = lambda col1, col2: (col1.name > col2.name)
- (col1.name < col2.name),
- (col1.name < col2.name),
) -> Table:
"""
Sort the columns of a `Table` with the given comparator and return a new `Table`.
Expand Down Expand Up @@ -960,7 +961,7 @@ def correlation_heatmap(self) -> Image:
plt.tight_layout()

buffer = io.BytesIO()
fig.savefig(buffer, format='png')
fig.savefig(buffer, format="png")
plt.close() # Prevents the figure from being displayed directly
buffer.seek(0)
return Image(buffer, format_=ImageFormat.PNG)
Expand Down Expand Up @@ -1005,7 +1006,7 @@ def lineplot(self, x_column_name: str, y_column_name: str) -> Image:
plt.tight_layout()

buffer = io.BytesIO()
fig.savefig(buffer, format='png')
fig.savefig(buffer, format="png")
plt.close() # Prevents the figure from being displayed directly
buffer.seek(0)
return Image(buffer, format_=ImageFormat.PNG)
Expand Down Expand Up @@ -1047,7 +1048,7 @@ def scatterplot(self, x_column_name: str, y_column_name: str) -> Image:
plt.tight_layout()

buffer = io.BytesIO()
fig.savefig(buffer, format='png')
fig.savefig(buffer, format="png")
plt.close() # Prevents the figure from being displayed directly
buffer.seek(0)
return Image(buffer, format_=ImageFormat.PNG)
Expand Down
35 changes: 9 additions & 26 deletions tests/safeds/data/image/containers/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from tempfile import NamedTemporaryFile

import pytest

from helpers import resolve_resource_path
from safeds.data.image.containers import Image
from safeds.data.image.typing import ImageFormat
Expand All @@ -11,18 +10,14 @@
class TestFromJpegFile:
@pytest.mark.parametrize(
"path",
[
"image/white_square.jpg"
],
["image/white_square.jpg"],
)
def test_should_load_jpeg_file(self, path: str) -> None:
Image.from_jpeg_file(resolve_resource_path(path))

@pytest.mark.parametrize(
"path",
[
"image/missing_file.jpg"
],
["image/missing_file.jpg"],
)
def test_should_raise_if_file_not_found(self, path: str) -> None:
with pytest.raises(FileNotFoundError):
Expand All @@ -32,18 +27,14 @@ def test_should_raise_if_file_not_found(self, path: str) -> None:
class TestFromPngFile:
@pytest.mark.parametrize(
"path",
[
"image/white_square.png"
],
["image/white_square.png"],
)
def test_should_load_png_file(self, path: str) -> None:
Image.from_png_file(resolve_resource_path(path))

@pytest.mark.parametrize(
"path",
[
"image/missing_file.png"
],
["image/missing_file.png"],
)
def test_should_raise_if_file_not_found(self, path: str) -> None:
with pytest.raises(FileNotFoundError):
Expand All @@ -55,7 +46,7 @@ class TestFormat:
("image", "format_"),
[
(Image.from_jpeg_file(resolve_resource_path("image/white_square.jpg")), ImageFormat.JPEG),
(Image.from_png_file(resolve_resource_path("image/white_square.png")), ImageFormat.PNG)
(Image.from_png_file(resolve_resource_path("image/white_square.png")), ImageFormat.PNG),
],
)
def test_should_return_correct_format(self, image: Image, format_: ImageFormat) -> None:
Expand All @@ -65,9 +56,7 @@ def test_should_return_correct_format(self, image: Image, format_: ImageFormat)
class TestToJpegFile:
@pytest.mark.parametrize(
"path",
[
"image/white_square.jpg"
],
["image/white_square.jpg"],
)
def test_should_save_jpeg_file(self, path: str) -> None:
image = Image.from_jpeg_file(resolve_resource_path(path))
Expand All @@ -85,9 +74,7 @@ def test_should_save_jpeg_file(self, path: str) -> None:
class TestToPngFile:
@pytest.mark.parametrize(
"path",
[
"image/white_square.png"
],
["image/white_square.png"],
)
def test_should_save_png_file(self, path: str) -> None:
image = Image.from_png_file(resolve_resource_path(path))
Expand All @@ -105,9 +92,7 @@ def test_should_save_png_file(self, path: str) -> None:
class TestReprJpeg:
@pytest.mark.parametrize(
"image",
[
Image.from_png_file(resolve_resource_path("image/white_square.png"))
],
[Image.from_png_file(resolve_resource_path("image/white_square.png"))],
)
def test_should_return_none_if_image_is_not_jpeg(self, image: Image) -> None:
assert image._repr_jpeg_() is None
Expand All @@ -116,9 +101,7 @@ def test_should_return_none_if_image_is_not_jpeg(self, image: Image) -> None:
class TestReprPng:
@pytest.mark.parametrize(
"image",
[
Image.from_jpeg_file(resolve_resource_path("image/white_square.jpg"))
],
[Image.from_jpeg_file(resolve_resource_path("image/white_square.jpg"))],
)
def test_should_return_none_if_image_is_not_png(self, image: Image) -> None:
assert image._repr_png_() is None
4 changes: 1 addition & 3 deletions tests/safeds/data/image/typing/test_image_format.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import pytest

from safeds.data.image.typing import ImageFormat


class TestValue:

@pytest.mark.parametrize(
"image_format, expected_value",
("image_format", "expected_value"),
[
(ImageFormat.JPEG, "jpeg"),
(ImageFormat.PNG, "png"),
Expand Down

0 comments on commit 29a2ee3

Please sign in to comment.