File size: 1,014 Bytes
0ac2632
 
 
38e243c
 
 
0ac2632
 
 
 
38e243c
0ac2632
 
 
 
 
 
38e243c
0ac2632
38e243c
1180a53
38e243c
0ac2632
 
 
 
38e243c
 
 
 
 
 
 
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
import os
import json
import pytest
from src.monitoring import main, REPORTS_DIR

METRICS_PATH = os.path.join(REPORTS_DIR, "metrics.json")


@pytest.fixture(autouse=True)
def cleanup_metrics():
    """Rimuove il file metrics.json prima e dopo i test."""
    if os.path.exists(METRICS_PATH):
        os.remove(METRICS_PATH)
    yield
    if os.path.exists(METRICS_PATH):
        os.remove(METRICS_PATH)


def test_monitoring_creates_metrics():
    """Verifica che il monitoring crei correttamente il file metrics.json e contenga i dati previsti."""
    main()

    assert os.path.exists(METRICS_PATH), "metrics.json non è stato generato"

    with open(METRICS_PATH, "r") as f:
        metrics = json.load(f)

    assert "TweetEval" in metrics, "Mancano metriche TweetEval"
    assert "YouTube" in metrics, "Mancano metriche YouTube"

    for dataset_name, data in metrics.items():
        assert "accuracy" in data, f"Manca accuracy per {dataset_name}"
        assert "f1" in data, f"Manca F1 per {dataset_name}"