47 lines
2.0 KiB
Python
47 lines
2.0 KiB
Python
from __future__ import annotations
|
|
import pytest
|
|
from legal_mcp.services import corroboration as cor
|
|
|
|
@pytest.mark.parametrize("raw,expected", [
|
|
({"treatment": "followed"}, "followed"),
|
|
({"treatment": "OVERRULED"}, "overruled"), # case-insensitive
|
|
({"treatment": "bananas"}, "mentioned"), # unknown -> neutral default
|
|
({}, "mentioned"), # missing -> neutral default
|
|
])
|
|
def test_coerce_treatment(raw, expected):
|
|
assert cor._coerce_treatment(raw) == expected
|
|
|
|
def test_treatment_polarity():
|
|
assert cor.is_positive("followed") and cor.is_positive("explained")
|
|
assert cor.is_negative("distinguished") and cor.is_negative("overruled")
|
|
assert not cor.is_positive("mentioned") and not cor.is_negative("mentioned")
|
|
|
|
def test_match_accepts_above_threshold():
|
|
assert cor.accept_match(("h1", 0.62), floor=0.50) == "h1"
|
|
|
|
def test_match_rejects_below_threshold():
|
|
assert cor.accept_match(("h1", 0.41), floor=0.50) is None
|
|
|
|
def test_match_rejects_empty():
|
|
assert cor.accept_match(None, floor=0.50) is None
|
|
|
|
def _link(src, treatment):
|
|
return {"source_id": src, "treatment": treatment}
|
|
|
|
def test_aggregate_counts_distinct_positive():
|
|
links = [_link("d1","followed"), _link("d1","explained"), _link("d2","followed")]
|
|
agg = cor.aggregate(links, min_cites=2)
|
|
assert agg["positive_sources"] == 2 # d1 counted once (INV-COR4 independence)
|
|
assert agg["has_negative"] is False
|
|
assert agg["corroborated"] is True
|
|
|
|
def test_aggregate_negative_blocks():
|
|
links = [_link("d1","followed"), _link("d2","followed"), _link("d3","distinguished")]
|
|
agg = cor.aggregate(links, min_cites=2)
|
|
assert agg["has_negative"] is True
|
|
assert agg["corroborated"] is False # any negative -> not corroborated (INV-COR2)
|
|
|
|
def test_aggregate_below_threshold():
|
|
agg = cor.aggregate([_link("d1","followed")], min_cites=2)
|
|
assert agg["corroborated"] is False # single source insufficient (INV-COR4)
|