Skip to content

Commit 6deddbe

Browse files
test: snapshot tests (#495)
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 <[email protected]>
1 parent 6443beb commit 6deddbe

File tree

79 files changed

+330
-329
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+330
-329
lines changed

poetry.lock

+15-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ seaborn = "^0.13.0"
2727
[tool.poetry.group.dev.dependencies]
2828
pytest = "^7.2.1"
2929
pytest-cov = "^4.0.0"
30+
syrupy = "^4.6.0"
3031

3132
[tool.poetry.group.docs.dependencies]
3233
jupyter = "^1.0.0"

tests/conftest.py

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
from typing import Any
2+
3+
import matplotlib as mpl
4+
import pytest
5+
from safeds.data.image.containers import Image
6+
from syrupy import SnapshotAssertion
7+
from syrupy.extensions.single_file import SingleFileSnapshotExtension
8+
from syrupy.types import SerializedData
9+
10+
# Fix for failures when running pytest in a terminal (https://github.com/Safe-DS/Library/issues/482)
11+
mpl.use("agg")
12+
13+
14+
class JPEGImageExtension(SingleFileSnapshotExtension):
15+
_file_extension = "jpg"
16+
17+
def serialize(self, data: Image, **_kwargs: Any) -> SerializedData:
18+
return data._repr_jpeg_()
19+
20+
21+
@pytest.fixture()
22+
def snapshot_jpeg(snapshot: SnapshotAssertion) -> SnapshotAssertion:
23+
return snapshot.use_extension(JPEGImageExtension)
24+
25+
26+
class PNGImageSnapshotExtension(SingleFileSnapshotExtension):
27+
_file_extension = "png"
28+
29+
def serialize(self, data: Image, **_kwargs: Any) -> SerializedData:
30+
return data._repr_png_()
31+
32+
33+
@pytest.fixture()
34+
def snapshot_png(snapshot: SnapshotAssertion) -> SnapshotAssertion:
35+
return snapshot.use_extension(PNGImageSnapshotExtension)
-8.02 KB
Binary file not shown.
-8.01 KB
Binary file not shown.
-7.99 KB
Binary file not shown.

tests/resources/image/blurredBoy.png

-152 KB
Binary file not shown.

tests/resources/image/boy.png

-236 KB
Binary file not shown.
Binary file not shown.
Binary file not shown.
-135 KB
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

tests/resources/image/copy.png

-10.6 KB
Binary file not shown.

tests/resources/image/edgyBoy.png

-96.9 KB
Binary file not shown.
-8.02 KB
Binary file not shown.
-7.94 KB
Binary file not shown.
Binary file not shown.
Binary file not shown.
-220 KB
Binary file not shown.
-765 KB
Binary file not shown.
-468 KB
Binary file not shown.

tests/resources/image/original.png

-10.6 KB
Binary file not shown.

tests/resources/image/plane.jpg

30.2 KB

tests/resources/image/plane.png

215 KB
Binary file not shown.
Binary file not shown.
Binary file not shown.
-135 KB
Binary file not shown.
Binary file not shown.
Binary file not shown.
-10.3 KB
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

tests/resources/image/white.png

-765 Bytes
Binary file not shown.
-131 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)