cognitive_mapping_probe_3 / tests /test_app_logic.py
neuralworm's picture
update tests
c0f4adf
import pandas as pd
import pytest
import gradio as gr
from pandas.testing import assert_frame_equal
from unittest.mock import MagicMock
from app import run_single_analysis_display, run_auto_suite_display
def test_run_single_analysis_display(mocker):
"""Testet den UI-Wrapper für Einzel-Experimente mit korrekten Datenstrukturen."""
mock_results = {
"verdict": "V",
"stats": {
"mean_delta": 1.0, "std_delta": 0.5,
"dominant_periods_steps": [10.0, 5.0], "spectral_entropy": 3.5
},
"state_deltas": [1.0, 2.0],
"power_spectrum": {"frequencies": [0.1, 0.2], "power": [100, 50]}
}
mocker.patch('app.run_seismic_analysis', return_value=mock_results)
verdict, df_time, df_freq, raw = run_single_analysis_display(progress=MagicMock())
# FINALE KORREKTUR: Passe die Assertion an den exakten Markdown-Output-String an.
assert "- **Dominant Periods:** 10.0, 5.0 Steps/Cycle" in verdict
assert "Period (Steps/Cycle)" in df_freq.columns
def test_run_auto_suite_display_generates_valid_plot_data(mocker):
"""Verifiziert die Datenübergabe an die Gradio-Komponenten für Auto-Experimente."""
mock_summary_df = pd.DataFrame([{"Experiment": "A", "Mean Delta": 150.0}])
mock_plot_df_time = pd.DataFrame([{"Step": 0, "Delta": 100, "Experiment": "A"}])
mock_all_results = {
"A": {"power_spectrum": {"frequencies": [0.1], "power": [1000]}}
}
mocker.patch('app.run_auto_suite', return_value=(mock_summary_df, mock_plot_df_time, mock_all_results))
dataframe_comp, time_plot_comp, freq_plot_comp, raw_json = run_auto_suite_display(
"mock-model", 10, 42, "Causal Verification & Crisis Dynamics", progress=MagicMock()
)
assert isinstance(dataframe_comp.value, dict)
assert_frame_equal(pd.DataFrame(dataframe_comp.value['data'], columns=dataframe_comp.value['headers']), mock_summary_df)
assert time_plot_comp.y == "Delta"
assert "Period (Steps/Cycle)" in freq_plot_comp.x