-
Notifications
You must be signed in to change notification settings - Fork 4
/
conftest.py
35 lines (23 loc) · 1.03 KB
/
conftest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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)