Skip to content

Commit

Permalink
DecisionReading makes OpinionReadings for all Opinions
Browse files Browse the repository at this point in the history
  • Loading branch information
mscarey committed Jul 26, 2021
1 parent 1cf0f2e commit 180cf6d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 16 deletions.
16 changes: 11 additions & 5 deletions authorityspoke/decisions.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ def __init__(
):
self.decision = decision
self.opinion_readings = opinion_readings or []
for opinion in self.decision.opinions:
if not any(
opinion.text == reading.opinion.text
for reading in self.opinion_readings
):
self.opinion_readings.append(OpinionReading(opinion=opinion))

def __str__(self):
citation = self.decision.citations[0].cite if self.decision.citations else ""
Expand Down Expand Up @@ -104,7 +110,7 @@ def contradicts(self, other):
return self.majority.contradicts(other)

def explain_contradiction(
self, other: Union[Opinion, Holding, Rule]
self, other: Union[OpinionReading, Holding, Rule]
) -> Optional[Explanation]:
explanations = self.explanations_contradiction(other)
try:
Expand All @@ -115,12 +121,12 @@ def explain_contradiction(

def explanations_contradiction(
self,
other: Union[Decision, Opinion, Holding, Rule],
other: Union[DecisionReading, Opinion, Holding, Rule],
) -> Iterator[Explanation]:
if isinstance(other, Decision):
if isinstance(other, DecisionReading):
if self.majority and other.majority:
yield from self.majority.explanations_contradiction(other.majority)
elif isinstance(other, (Rule, Holding, Opinion)):
elif isinstance(other, (Rule, Holding, OpinionReading)):
if self.majority:
yield from self.majority.explanations_contradiction(other)
else:
Expand Down Expand Up @@ -203,7 +209,7 @@ def explanations_implied_by(
self, other: Comparable, context: Optional[ContextRegister] = None
) -> Iterator[Explanation]:
context = context or ContextRegister()
if isinstance(other, Opinion):
if isinstance(other, OpinionReading):
other = other.holdings
if isinstance(other, HoldingGroup):
yield from other.explanations_implication(
Expand Down
4 changes: 2 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -1528,8 +1528,8 @@ def make_opinion(make_decision) -> Dict[str, Opinion]:
def make_opinion_with_holding(make_decision_with_holding) -> Dict[str, Opinion]:
opinions = {}
for case in TEST_CASES:
for opinion in make_decision_with_holding[case].opinions:
opinions[f"{case}_{opinion.type}"] = opinion
for reading in make_decision_with_holding[case].opinion_readings:
opinions[f"{case}_{reading.opinion.type}"] = reading
return opinions


Expand Down
23 changes: 14 additions & 9 deletions tests/test_decisions.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ def test_need_opinion_to_posit_holding(self, make_holding):
with pytest.raises(AttributeError):
decision.posit(make_holding["h1"])

def test_decision_reading_has_opinion_readings(self, make_decision):
watt = make_decision["watt"]
reading = DecisionReading(decision=watt)
hamley = "hamley, circuit judge"
assert reading.opinion_readings[0].opinion.author.lower() == hamley


class TestImplication:
def test_implication_of_decision_with_one_of_same_holdings(
Expand Down Expand Up @@ -117,12 +123,9 @@ def test_decision_does_not_imply_procedure(
oracle = make_decision_with_holding["oracle"]
assert not oracle.implies(make_procedure["c1"])

def test_opinion_implies_decision(self, make_holding, make_opinion_with_holding):
watt = make_opinion_with_holding["watt_majority"]
decision = Decision(decision_date=date(2000, 1, 1))
decision.add_opinion(opinion=Opinion(type="majority"))
decision.posit(watt.holdings[0])
assert watt.implies(decision)
def test_opinion_implies_decision(self, make_decision_with_holding):
watt = make_decision_with_holding["watt"]
assert watt.opinion_readings[0].implies(watt)

def test_rule_implied_by_decision(self, make_decision_with_holding):
oracle = make_decision_with_holding["oracle"]
Expand Down Expand Up @@ -162,15 +165,17 @@ def test_no_contradiction_with_plurality(self, make_decision_with_holding):
decision_date=datetime.date(2020, 1, 1),
opinions=[Opinion(position="plurality")],
)
assert not oracle.contradicts(other)
reading = DecisionReading(decision=other)
assert not oracle.contradicts(reading)

def test_no_contradiction_of_majority_without_holdings(
self, make_decision_with_holding
):
oracle = make_decision_with_holding["oracle"]
other = Decision(decision_date=datetime.date(2020, 1, 1))
other.add_opinion(Opinion(position="majority"))
assert not oracle.contradicts(other)
other.opinions.append(Opinion(position="majority"))
reading = DecisionReading(decision=other)
assert not oracle.contradicts(reading)

def test_decision_contradicts_holding(self, make_decision_with_holding):
oracle = make_decision_with_holding["oracle"]
Expand Down

0 comments on commit 180cf6d

Please sign in to comment.