SocialDynamics_Lab / tests /test_app.py
ImAnouar1's picture
Upload 16 files
1025a87 verified
Raw History Blame Contribute Delete
1.43 kB
"""Smoke tests for the Gradio handlers (skipped where gradio is not installed)."""
import re
import sys
from pathlib import Path
import pytest
gr = pytest.importorskip("gradio")
sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
import app # noqa: E402
DEFAULTS = [100, "Small World", "Random", 0.05, "Split extremes", 0.25, 0.35, "Positive (+1)",
0.45, 0.45, 0.02, 60, 42, 0.0, 0.5]
def _text(fragment: str) -> str:
return re.sub(r"\s+", " ", re.sub(r"<[^>]+>", " ", fragment))
def test_default_run_no_longer_claims_like_minded_concentration():
final = list(app.run_simulation(*DEFAULTS))[-1]
text = _text(final[6])
assert "Influence concentrates among like-minded neighbours" not in text
assert "no network echo chamber" in text
def test_every_preset_runs_and_echo_chamber_is_detected():
regimes = {}
for name in app.PRESETS:
v = app.preset_values(name)
values = [100, *v[:11], 42, v[11], v[12]]
final = list(app.run_simulation(*values))[-1]
regimes[name] = _text(final[6])
assert "Echo chamber" in regimes["Echo Chamber"]
assert "Polarized, mixed" in regimes["Filtered, Not Segregated"]
def test_compare_and_sweep_handlers():
table, fig, status = app.compare_networks(1, *DEFAULTS)
assert "Scale Free" in table and "Complete" in status
fig, verdict, _ = app.run_sweep(3, *DEFAULTS)
assert "correlate" in verdict