Add trace_agg_tests/tests/test_trace_agg.py
This commit is contained in:
parent
7f59b16b47
commit
e1e3a6c462
1 changed files with 55 additions and 0 deletions
55
trace_agg_tests/tests/test_trace_agg.py
Normal file
55
trace_agg_tests/tests/test_trace_agg.py
Normal file
|
|
@ -0,0 +1,55 @@
|
||||||
|
import unittest
|
||||||
|
import json
|
||||||
|
import os
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
import trace_agg # Erwartet, dass trace_agg.py im Projekt vorhanden ist
|
||||||
|
|
||||||
|
|
||||||
|
def load_test_data(default_file: str = "test_data.json"):
|
||||||
|
data_file = os.environ.get("TRACE_AGG_TESTDATA", default_file)
|
||||||
|
path = Path(data_file)
|
||||||
|
if not path.exists():
|
||||||
|
raise FileNotFoundError(f"Testdaten-Datei nicht gefunden: {path}")
|
||||||
|
with path.open("r", encoding="utf-8") as f:
|
||||||
|
return json.load(f)
|
||||||
|
|
||||||
|
|
||||||
|
class TraceAggTestCase(unittest.TestCase):
|
||||||
|
"""Testet Aggregations- und Filterlogik in trace_agg.py anhand definierter Testdaten."""
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
self.test_data = load_test_data()
|
||||||
|
self.input_data = self.test_data.get("input", [])
|
||||||
|
self.expected_output = self.test_data.get("expected_output", {})
|
||||||
|
|
||||||
|
def test_aggregation(self):
|
||||||
|
"""Überprüft, ob Aggregation erwartete Werte liefert."""
|
||||||
|
if not hasattr(trace_agg, "aggregate"):
|
||||||
|
self.skipTest("trace_agg.aggregate nicht implementiert")
|
||||||
|
|
||||||
|
result = trace_agg.aggregate(self.input_data)
|
||||||
|
self.assertIsInstance(result, dict)
|
||||||
|
|
||||||
|
for key, expected_value in self.expected_output.items():
|
||||||
|
self.assertIn(key, result, f"Schlüssel {key} fehlt in Aggregationsergebnis")
|
||||||
|
self.assertEqual(result[key], expected_value, f"Falscher Wert für {key}")
|
||||||
|
|
||||||
|
def test_filtering_logic(self):
|
||||||
|
"""Validiert, dass Filterung vor Aggregation angewendet wird."""
|
||||||
|
if not all(hasattr(trace_agg, name) for name in ("filter_traces", "aggregate")):
|
||||||
|
self.skipTest("Erforderliche Funktionen filter_traces/aggregate nicht vorhanden")
|
||||||
|
|
||||||
|
filtered = trace_agg.filter_traces(self.input_data)
|
||||||
|
result = trace_agg.aggregate(filtered)
|
||||||
|
|
||||||
|
# Vergleich: direkt aggregierte vs. ungefilterte Summen dürfen sich unterscheiden
|
||||||
|
direct_result = trace_agg.aggregate(self.input_data)
|
||||||
|
|
||||||
|
self.assertNotEqual(result, direct_result, "Filterung scheint nicht angewendet zu werden")
|
||||||
|
# Filter- und Aggregationsergebnisstruktur prüfen
|
||||||
|
self.assertTrue(isinstance(result, dict) and len(result) > 0)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
unittest.main(verbosity=2)
|
||||||
Loading…
Reference in a new issue