Skip to content

Commit

Permalink
test: snapshot tests (#495)
Browse files Browse the repository at this point in the history
Closes #482
Closes #483

### Summary of Changes

* Use [sypury](https://github.com/tophat/syrupy) snapshot tests for
images. Run `pytest --snapshot-update` to update snapshots after
changes.
* Fix random test failures due to TCL when running tests in a terminal

---------

Co-authored-by: megalinter-bot <129584137+megalinter-bot@users.noreply.github.com>
  • Loading branch information
lars-reimann and megalinter-bot authored Nov 22, 2023
1 parent 6443beb commit 6deddbe
Show file tree
Hide file tree
Showing 79 changed files with 330 additions and 329 deletions.
16 changes: 15 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ seaborn = "^0.13.0"
[tool.poetry.group.dev.dependencies]
pytest = "^7.2.1"
pytest-cov = "^4.0.0"
syrupy = "^4.6.0"

[tool.poetry.group.docs.dependencies]
jupyter = "^1.0.0"
Expand Down
35 changes: 35 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from typing import Any

import matplotlib as mpl
import pytest
from safeds.data.image.containers import Image
from syrupy import SnapshotAssertion
from syrupy.extensions.single_file import SingleFileSnapshotExtension
from syrupy.types import SerializedData

# Fix for failures when running pytest in a terminal (https://github.com/Safe-DS/Library/issues/482)
mpl.use("agg")


class JPEGImageExtension(SingleFileSnapshotExtension):
_file_extension = "jpg"

def serialize(self, data: Image, **_kwargs: Any) -> SerializedData:
return data._repr_jpeg_()


@pytest.fixture()
def snapshot_jpeg(snapshot: SnapshotAssertion) -> SnapshotAssertion:
return snapshot.use_extension(JPEGImageExtension)


class PNGImageSnapshotExtension(SingleFileSnapshotExtension):
_file_extension = "png"

def serialize(self, data: Image, **_kwargs: Any) -> SerializedData:
return data._repr_png_()


@pytest.fixture()
def snapshot_png(snapshot: SnapshotAssertion) -> SnapshotAssertion:
return snapshot.use_extension(PNGImageSnapshotExtension)
Binary file removed tests/resources/image/adjusted_colors/by_0.5.png
Binary file not shown.
Binary file removed tests/resources/image/adjusted_colors/by_0.png
Binary file not shown.
Binary file removed tests/resources/image/adjusted_colors/by_2.png
Binary file not shown.
Binary file removed tests/resources/image/blurredBoy.png
Binary file not shown.
Binary file removed tests/resources/image/boy.png
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed tests/resources/image/brightness/to_brighten.png
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed tests/resources/image/copy.png
Binary file not shown.
Binary file removed tests/resources/image/edgyBoy.png
Binary file not shown.
Binary file removed tests/resources/image/flip_horizontally.png
Binary file not shown.
Binary file removed tests/resources/image/flip_vertically.png
Binary file not shown.
Binary file removed tests/resources/image/inverted_colors_original.jpg
Binary file not shown.
Binary file removed tests/resources/image/inverted_colors_original.png
Binary file not shown.
Binary file removed tests/resources/image/noise/noise_0.0.png
Binary file not shown.
Binary file removed tests/resources/image/noise/noise_0.7.png
Binary file not shown.
Binary file removed tests/resources/image/noise/noise_2.5.png
Binary file not shown.
Binary file removed tests/resources/image/original.png
Binary file not shown.
Binary file added tests/resources/image/plane.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/resources/image/plane.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed tests/resources/image/sharpen/sharpened_by_-1.png
Binary file not shown.
Binary file removed tests/resources/image/sharpen/sharpened_by_0.5.png
Binary file not shown.
Binary file removed tests/resources/image/sharpen/sharpened_by_10.png
Diff not rendered.
Binary file removed tests/resources/image/sharpen/to_sharpen.png
Diff not rendered.
Diff not rendered.
Diff not rendered.
Binary file removed tests/resources/image/snapshot_empty_heatmap.png
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Binary file removed tests/resources/image/white.png
Diff not rendered.
Binary file removed tests/resources/image/whiteCropped.png
Diff not rendered.
Loading

0 comments on commit 6deddbe

Please sign in to comment.