Add mini_reporting_block/tests/test_core.py
This commit is contained in:
parent
1198dc404d
commit
18f5863609
1 changed files with 42 additions and 0 deletions
42
mini_reporting_block/tests/test_core.py
Normal file
42
mini_reporting_block/tests/test_core.py
Normal file
|
|
@ -0,0 +1,42 @@
|
||||||
|
import json
|
||||||
|
import pytest
|
||||||
|
from mini_reporting_block import core
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def sample_analysis_results():
|
||||||
|
return [
|
||||||
|
{"corr_id": "c1", "expires_at_dist_hours": -3, "visibility_lag": 1.2},
|
||||||
|
{"corr_id": "c2", "expires_at_dist_hours": -1, "visibility_lag": 0.8},
|
||||||
|
]
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def sample_reporting_block(sample_analysis_results):
|
||||||
|
text_block = core.generate_reporting_block(sample_analysis_results)
|
||||||
|
rb = core.ReportingBlock(summary="2 Δt<0 Fälle erkannt", details=sample_analysis_results)
|
||||||
|
return text_block, rb
|
||||||
|
|
||||||
|
def test_reporting_block_structure(sample_reporting_block):
|
||||||
|
text_block, rb = sample_reporting_block
|
||||||
|
assert isinstance(rb, core.ReportingBlock)
|
||||||
|
data = rb.to_json()
|
||||||
|
assert set(data.keys()) == {"summary", "details"}
|
||||||
|
assert isinstance(data["summary"], str)
|
||||||
|
assert isinstance(data["details"], list)
|
||||||
|
assert all(isinstance(d, dict) for d in data["details"])
|
||||||
|
|
||||||
|
def test_generate_reporting_block_output(sample_analysis_results):
|
||||||
|
text_block = core.generate_reporting_block(sample_analysis_results)
|
||||||
|
assert isinstance(text_block, str)
|
||||||
|
assert "Δt<0" in text_block or "dt<0" in text_block or "<0" in text_block
|
||||||
|
|
||||||
|
def test_empty_input_handling():
|
||||||
|
with pytest.raises((AssertionError, ValueError, TypeError)):
|
||||||
|
_ = core.generate_reporting_block([])
|
||||||
|
|
||||||
|
def test_json_serialization_compatibility(sample_reporting_block):
|
||||||
|
_, rb = sample_reporting_block
|
||||||
|
data = rb.to_json()
|
||||||
|
# Should be JSON serializable
|
||||||
|
json_text = json.dumps(data)
|
||||||
|
reloaded = json.loads(json_text)
|
||||||
|
assert reloaded == data
|
||||||
Loading…
Reference in a new issue