File size: 2,533 Bytes
a345062 5ab2ded a345062 8489475 d407fda a345062 8489475 5ab2ded d407fda 8489475 5ab2ded 11cf050 5ab2ded d407fda a345062 8489475 a345062 11cf050 d407fda a345062 11cf050 5ab2ded 11cf050 5ab2ded 11cf050 d407fda 5ab2ded 11cf050 5ab2ded 11cf050 d407fda |
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 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
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: Rekonstruiert DataFrames aus den serialisierten `dict`-Werten
der Gradio-Komponenten, um die tatsächliche API-Nutzung widerzuspiegeln.
"""
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')
dataframe_component, plot_component, raw_json_str = run_auto_suite_display(
"mock-model", 100, 42, "mock_exp", progress=mocker.MagicMock()
)
# KORREKTUR: Die `.value` Eigenschaft einer gr.DataFrame Komponente ist ein Dictionary.
# Wir müssen den pandas.DataFrame daraus rekonstruieren, um ihn zu vergleichen.
assert isinstance(dataframe_component, gr.DataFrame)
assert isinstance(dataframe_component.value, dict)
reconstructed_summary_df = pd.DataFrame(
data=dataframe_component.value['data'],
columns=dataframe_component.value['headers']
)
assert_frame_equal(reconstructed_summary_df, mock_summary_df)
# Dasselbe gilt für die LinePlot-Komponente
assert isinstance(plot_component, gr.LinePlot)
assert isinstance(plot_component.value, dict)
reconstructed_plot_df = pd.DataFrame(
data=plot_component.value['data'],
columns=plot_component.value['columns']
)
assert_frame_equal(reconstructed_plot_df, mock_plot_df)
# Der JSON-String bleibt ein String
assert isinstance(raw_json_str, str)
assert '"mean_delta": 1.5' in raw_json_str
|