|
|
import pandas as pd |
|
|
import pytest |
|
|
import gradio as gr |
|
|
from pandas.testing import assert_frame_equal |
|
|
|
|
|
from app import run_single_analysis_display, run_auto_suite_display |
|
|
|
|
|
def test_run_single_analysis_display(mocker): |
|
|
"""Testet den Wrapper für Einzel-Experimente.""" |
|
|
mock_results = {"verdict": "V", "stats": {"mean_delta": 1}, "state_deltas": [1.0, 2.0]} |
|
|
mocker.patch('app.run_seismic_analysis', return_value=mock_results) |
|
|
mocker.patch('app.cleanup_memory') |
|
|
|
|
|
verdict, df, raw = run_single_analysis_display(progress=mocker.MagicMock()) |
|
|
|
|
|
assert "V" in verdict and "1.0000" in verdict |
|
|
assert isinstance(df, pd.DataFrame) and len(df) == 2 |
|
|
assert "State Change (Delta)" in df.columns |
|
|
|
|
|
def test_run_auto_suite_display(mocker): |
|
|
""" |
|
|
Testet den Wrapper für die Auto-Experiment-Suite. |
|
|
FINAL KORRIGIERT: Validiert nun die korrekte `dict`-Struktur, die von |
|
|
`gradio.LinePlot` zurückgegeben wird, und rekonstruiert den DataFrame für den Vergleich. |
|
|
""" |
|
|
mock_summary_df = pd.DataFrame([{"Experiment": "E1", "Mean Delta": 1.5}]) |
|
|
mock_plot_df = pd.DataFrame([{"Step": 0, "Delta": 1.0, "Experiment": "E1"}, {"Step": 1, "Delta": 2.0, "Experiment": "E1"}]) |
|
|
mock_results = {"E1": {"stats": {"mean_delta": 1.5}}} |
|
|
|
|
|
mocker.patch('app.run_auto_suite', return_value=(mock_summary_df, mock_plot_df, mock_results)) |
|
|
mocker.patch('app.cleanup_memory') |
|
|
|
|
|
summary_df, plot_component, raw_json_str = run_auto_suite_display( |
|
|
"mock-model", 100, 42, "mock_exp", progress=mocker.MagicMock() |
|
|
) |
|
|
|
|
|
|
|
|
assert_frame_equal(summary_df, mock_summary_df) |
|
|
|
|
|
|
|
|
assert isinstance(plot_component, gr.LinePlot) |
|
|
assert isinstance(plot_component.value, dict) |
|
|
assert 'data' in plot_component.value and 'columns' in plot_component.value |
|
|
|
|
|
|
|
|
reconstructed_df = pd.DataFrame( |
|
|
plot_component.value['data'], |
|
|
columns=plot_component.value['columns'] |
|
|
) |
|
|
|
|
|
|
|
|
assert_frame_equal(reconstructed_df, mock_plot_df) |
|
|
|
|
|
|
|
|
assert isinstance(raw_json_str, str) |
|
|
assert '"mean_delta": 1.5' in raw_json_str |
|
|
|