Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: snapshot tests for diagrams #239

Merged
merged 16 commits into from
May 5, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added tests/resources/image/snapshot_boxplot.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 added tests/resources/image/snapshot_heatmap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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/snapshot_lineplot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import _pytest
import matplotlib.pyplot as plt
import pytest
from safeds.data.image.containers import Image
from safeds.data.tabular.containers import Table
from safeds.data.tabular.exceptions import NonNumericColumnError

from tests.helpers import resolve_resource_path


def test_plot_boxplot_complex() -> None:
lars-reimann marked this conversation as resolved.
Show resolved Hide resolved
with pytest.raises(NotImplementedError): # noqa: PT012
Expand All @@ -27,3 +30,12 @@ def test_plot_boxplot_int(monkeypatch: _pytest.monkeypatch) -> None:
monkeypatch.setattr(plt, "show", lambda: None)
table = Table.from_dict({"A": [1, 2, 3]})
table.get_column("A").plot_boxplot()


def test_plot_boxplot_legacy() -> None:
PhilipGutberlet marked this conversation as resolved.
Show resolved Hide resolved
table = Table.from_dict({"A": [1, 2, 3]})
# table.get_column("A").plot_boxplot().to_png_file(resolve_resource_path("./image/snapshot_boxplot.png"))
PhilipGutberlet marked this conversation as resolved.
Show resolved Hide resolved
table.get_column("A").plot_boxplot()
current = table.get_column("A").plot_boxplot()
legacy = Image.from_png_file(resolve_resource_path("./image/snapshot_boxplot.png"))
PhilipGutberlet marked this conversation as resolved.
Show resolved Hide resolved
assert legacy._image.tobytes() == current._image.tobytes()
Original file line number Diff line number Diff line change
@@ -1,9 +1,28 @@
import _pytest
import matplotlib.pyplot as plt
from safeds.data.image.containers import Image
from safeds.data.tabular.containers import Table

from tests.helpers import resolve_resource_path


def test_plot_histogram(monkeypatch: _pytest.monkeypatch) -> None:
PhilipGutberlet marked this conversation as resolved.
Show resolved Hide resolved
monkeypatch.setattr(plt, "show", lambda: None)
table = Table.from_dict({"A": [1, 2, 3]})
table.get_column("A").plot_histogram()


def test_plot_histogram_legacy_check_str() -> None:
table = Table.from_dict({"A": ["A", "B", "Apple"]})
# table.get_column("A").plot_histogram().to_png_file(resolve_resource_path("./image/snapshot_histogram_str.png"))
current = table.get_column("A").plot_histogram()
legacy = Image.from_png_file(resolve_resource_path("./image/snapshot_histogram_str.png"))
assert legacy._image.tobytes() == current._image.tobytes()


def test_plot_histogram_legacy_check_numeric() -> None:
table = Table.from_dict({"A": [1, 2, 3]})
# table.get_column("A").plot_histogram().to_png_file(resolve_resource_path("./image/snapshot_histogram_numeric.png"))
current = table.get_column("A").plot_histogram()
legacy = Image.from_png_file(resolve_resource_path("./image/snapshot_histogram_numeric.png"))
assert legacy._image.tobytes() == current._image.tobytes()
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import _pytest
import matplotlib.pyplot as plt
from safeds.data.image.containers import Image
from safeds.data.tabular.containers import Table

from tests.helpers import resolve_resource_path


def test_plot_correlation_heatmap_non_numeric(monkeypatch: _pytest.monkeypatch) -> None:
monkeypatch.setattr(plt, "show", lambda: None)
Expand All @@ -13,3 +16,11 @@ def test_plot_correlation_heatmap(monkeypatch: _pytest.monkeypatch) -> None:
monkeypatch.setattr(plt, "show", lambda: None)
table = Table.from_dict({"A": [1, 2, 3.5], "B": [2, 4, 7]})
table.plot_correlation_heatmap()


def test_plot_heatmap_legacy_check() -> None:
table = Table.from_dict({"A": [1, 2, 3.5], "B": [0.2, 4, 77]})
# table.plot_correlation_heatmap().to_png_file(resolve_resource_path("./image/snapshot_heatmap.png"))
PhilipGutberlet marked this conversation as resolved.
Show resolved Hide resolved
current = table.plot_correlation_heatmap()
legacy = Image.from_png_file(resolve_resource_path("./image/snapshot_heatmap.png"))
assert legacy._image.tobytes() == current._image.tobytes()
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import _pytest
import matplotlib.pyplot as plt
import pytest
from safeds.data.image.containers import Image
from safeds.data.tabular.containers import Table
from safeds.data.tabular.exceptions import UnknownColumnNameError

from tests.helpers import resolve_resource_path


def test_plot_lineplot(monkeypatch: _pytest.monkeypatch) -> None:
monkeypatch.setattr(plt, "show", lambda: None)
Expand All @@ -15,3 +18,11 @@ def test_plot_lineplot_wrong_column_name() -> None:
table = Table.from_dict({"A": [1, 2, 3], "B": [2, 4, 7]})
with pytest.raises(UnknownColumnNameError):
table.plot_lineplot("C", "A")


def test_plot_lineplot_legacy_check() -> None:
table = Table.from_dict({"A": [1, 2, 3], "B": [2, 4, 7]})
# table.plot_lineplot("A", "B").to_png_file(resolve_resource_path("./image/snapshot_lineplot.png"))
current = table.plot_lineplot("A", "B")
legacy = Image.from_png_file(resolve_resource_path("./image/snapshot_lineplot.png"))
assert legacy._image.tobytes() == current._image.tobytes()
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import _pytest
import matplotlib.pyplot as plt
import pytest
from safeds.data.image.containers import Image
from safeds.data.tabular.containers import Table
from safeds.data.tabular.exceptions import UnknownColumnNameError

from tests.helpers import resolve_resource_path


def test_plot_scatterplot(monkeypatch: _pytest.monkeypatch) -> None:
monkeypatch.setattr(plt, "show", lambda: None)
Expand All @@ -15,3 +18,11 @@ def test_plot_scatterplot_wrong_column_name() -> None:
table = Table.from_dict({"A": [1, 2, 3], "B": [2, 4, 7]})
with pytest.raises(UnknownColumnNameError):
table.plot_scatterplot("C", "A")


def test_plot_scatterplot_legacy_check() -> None:
table = Table.from_dict({"A": [1, 2, 3], "B": [2, 4, 7]})
# table.plot_scatterplot("A", "B").to_png_file(resolve_resource_path("./image/snapshot_scatterplot.png"))
current = table.plot_scatterplot("A", "B")
legacy = Image.from_png_file(resolve_resource_path("./image/snapshot_scatterplot.png"))
assert legacy._image.tobytes() == current._image.tobytes()