File size: 1,434 Bytes
1025a87
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""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