Add heatmap_visualization/tests/test_core.py
This commit is contained in:
parent
c10d6ceb1b
commit
9e048fa351
1 changed files with 39 additions and 0 deletions
39
heatmap_visualization/tests/test_core.py
Normal file
39
heatmap_visualization/tests/test_core.py
Normal file
|
|
@ -0,0 +1,39 @@
|
||||||
|
import pytest
|
||||||
|
import pandas as pd
|
||||||
|
import matplotlib.figure as mfig
|
||||||
|
import seaborn as sns
|
||||||
|
from heatmap_visualization import core
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def sample_log_data():
|
||||||
|
# Beispielhafte Logdaten inklusive Edge-Case (Nullwerte, Varianz)
|
||||||
|
return pd.DataFrame([
|
||||||
|
{"worker_start_offset": 0.0, "expires_at_dist_hours": 12.0, "retry_total_overhead_ms": 150.0},
|
||||||
|
{"worker_start_offset": 1.5, "expires_at_dist_hours": 8.0, "retry_total_overhead_ms": 300.0},
|
||||||
|
{"worker_start_offset": 3.0, "expires_at_dist_hours": 10.0, "retry_total_overhead_ms": 120.0},
|
||||||
|
{"worker_start_offset": 0.5, "expires_at_dist_hours": 7.5, "retry_total_overhead_ms": 200.0},
|
||||||
|
{"worker_start_offset": 2.0, "expires_at_dist_hours": 9.0, "retry_total_overhead_ms": 180.0}
|
||||||
|
])
|
||||||
|
|
||||||
|
def test_generate_heatmap_returns_figure(sample_log_data):
|
||||||
|
fig = core.generate_heatmap(sample_log_data)
|
||||||
|
assert isinstance(fig, mfig.Figure), "Erwartet ein Matplotlib Figure-Objekt"
|
||||||
|
|
||||||
|
def test_generate_heatmap_with_list_input(sample_log_data):
|
||||||
|
data_list = sample_log_data.to_dict(orient="records")
|
||||||
|
fig = core.generate_heatmap(data_list)
|
||||||
|
assert isinstance(fig, mfig.Figure)
|
||||||
|
|
||||||
|
def test_generate_heatmap_invalid_input():
|
||||||
|
with pytest.raises((ValueError, TypeError)):
|
||||||
|
core.generate_heatmap({"not": "valid"})
|
||||||
|
|
||||||
|
def test_heatmap_visualization_colormap(sample_log_data):
|
||||||
|
fig = core.generate_heatmap(sample_log_data)
|
||||||
|
# Überprüfe, ob Seaborn-Heatmap-Farbschema korrekt angewendet wurde.
|
||||||
|
assert any(ax.images for ax in fig.axes), "Heatmap enthält kein Farb-Image"
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("invalid_data", [None, [], [{}], [{"worker_start_offset": None}]])
|
||||||
|
def test_generate_heatmap_edge_cases(invalid_data):
|
||||||
|
with pytest.raises((ValueError, TypeError)):
|
||||||
|
core.generate_heatmap(invalid_data)
|
||||||
Loading…
Reference in a new issue