Пример #1
0
 def test_opinion_posits_holding(self, make_response):
     mock_client = FakeClient(responses=make_response)
     to_read = load_holdings("holding_brad.yaml")
     holdings = readers.read_holdings(to_read, client=mock_client)
     reading = OpinionReading()
     reading.posit(holdings[0])
     assert "warrantless search and seizure" in reading.holdings[
         0].short_string
Пример #2
0
 def test_read_holding_with_no_anchor(self, make_analysis):
     raw_analysis = make_analysis["no anchors"]
     reading = OpinionReading()
     anchored_holdings = readers.read_holdings_with_anchors(raw_analysis)
     reading.posit(
         holdings=anchored_holdings.holdings,
         named_anchors=anchored_holdings.named_anchors,
         enactment_anchors=anchored_holdings.enactment_anchors,
     )
     assert not reading.holding_anchors[0].positions
     assert not reading.holding_anchors[0].quotes
Пример #3
0
 def add_opinion_reading(self, opinion_reading: OpinionReading) -> None:
     """Add an OpinionReading for an existing Opinion of the Decision."""
     matching_opinion = self.find_opinion_matching_reading(opinion_reading)
     if matching_opinion:
         opinion_reading.opinion_type = (
             matching_opinion.type or opinion_reading.opinion_type
         )
         opinion_reading.opinion_author = (
             matching_opinion.author or opinion_reading.opinion_author
         )
     self.opinion_readings.append(opinion_reading)
Пример #4
0
    def test_posit_holding_with_selector(self, make_analysis, make_opinion):

        anchored_holdings = readers.read_holdings_with_anchors(
            make_analysis["minimal"])

        brad = make_opinion["brad_majority"]
        reading = OpinionReading(opinion_type="majority",
                                 opinion_author=brad.author)
        reading.posit(anchored_holdings.holdings)
        assert reading.holding_anchors[0].quotes[
            0].exact == "open fields or grounds"
Пример #5
0
 def test_load_and_posit_holdings_with_anchors(self, make_response):
     """
     Test that Opinion.posit can take a HoldingsIndexed as the only argument.
     Trying to combine several tasks that normally happen together, into a single command.
     """
     mock_client = FakeClient(responses=make_response)
     oracle_holdings_with_anchors = loaders.read_anchored_holdings_from_file(
         "holding_oracle.yaml", client=mock_client)
     reading = OpinionReading()
     reading.posit(oracle_holdings_with_anchors)
     assert len(reading.holdings) == 20
Пример #6
0
 def test_posit_one_holding_with_anchor(self, raw_holding, make_response):
     mock_client = FakeClient(responses=make_response)
     holdings = readers.read_holdings([raw_holding["bradley_house"]],
                                      client=mock_client)
     reading = OpinionReading()
     reading.posit_holding(
         holdings[0],
         holding_anchors=TextQuoteSelector(
             exact="some text supporting this holding"),
     )
     assert (reading.anchored_holdings.holdings[-1].anchors.quotes[0].exact
             == "some text supporting this holding")
Пример #7
0
 def test_error_decision_with_no_majority_posits_holding(
         self, fake_usc_client):
     lotus_analysis = read_anchored_holdings_from_file(
         "holding_lotus.yaml", client=fake_usc_client)
     reading1 = OpinionReading(opinion_type="plurality")
     reading2 = OpinionReading(opinion_type="concurring")
     decision_reading = DecisionReading(
         decision=Decision(decision_date=date(2000, 2, 2)),
         opinion_readings=[reading1, reading2],
     )
     with pytest.raises(AttributeError):
         decision_reading.posit(lotus_analysis)
Пример #8
0
 def test_loading_opinion_with_one_holding_in_list(self,
                                                   make_anchored_holding):
     holding = make_anchored_holding["watt"].holdings[0]
     reading = OpinionReading(anchored_holdings=AnchoredHoldings(
         holdings=[holding]))
     assert isinstance(reading.holdings, HoldingGroup)
     assert len(reading.holdings) == 1
Пример #9
0
 def test_holding_with_non_generic_value(self, make_entity, make_response):
     """
     This test originally required a ValueError, but why should it?
     """
     mock_client = FakeClient(responses=make_response)
     reading = OpinionReading()
     to_read = load_holdings("holding_brad.yaml")
     holdings = readers.read_holdings(to_read, client=mock_client)
     reading.posit(holdings)
     expectation_not_reasonable = reading.holdings[6]
     generic_patch = expectation_not_reasonable.generic_terms()[1]
     changes = ContextRegister()
     changes.insert_pair(generic_patch, make_entity["trees_specific"])
     context_change = expectation_not_reasonable.new_context(changes)
     string = context_change.short_string
     assert "plants in the stockpile of trees was at least 3" in string
Пример #10
0
 def test_opinion_posits_holding_tuple_context(self, make_entity,
                                               make_response):
     """
     Having the Watt case posit a holding from the Brad
     case, but with generic factors from Watt.
     """
     mock_client = FakeClient(responses=make_response)
     to_read = load_holdings("holding_brad.yaml")
     brad_holdings = readers.read_holdings(to_read, client=mock_client)
     context_holding = brad_holdings[6].new_context(
         [make_entity["watt"], make_entity["trees"], make_entity["motel"]])
     reading = OpinionReading()
     reading.posit(context_holding)
     holding_string = reading.holdings[-1].short_string
     assert (
         "the number of marijuana plants in <the stockpile of trees> was at least 3"
         in holding_string)
Пример #11
0
    def test_opinion_contradicts_opinion(self, make_opinion_with_holding):
        """Return the only contradictory pair of Holdings between these two Opinions."""
        oracle = make_opinion_with_holding["oracle_majority"]
        lotus = make_opinion_with_holding["lotus_majority"]

        left = OpinionReading(opinion_type="majority",
                              opinion_author=oracle.opinion_author)
        left.posit(lotus.holdings[6])
        right = OpinionReading(opinion_type="majority",
                               opinion_author=lotus.opinion_author)
        right.posit(oracle.holdings[10])
        explanation = left.explain_contradiction(right)
        assert len(explanation.reasons) == 1
        assert isinstance(explanation.reasons[0].left, Holding)
        assert isinstance(explanation.reasons[0].right, Holding)
Пример #12
0
 def test_decision_with_opinion_reading_posits_holding(
         self, fake_usc_client):
     lotus_analysis = read_anchored_holdings_from_file(
         "holding_lotus.yaml", client=fake_usc_client)
     decision_reading = DecisionReading(
         decision=Decision(decision_date=date(2000, 2, 2)),
         opinion_readings=[OpinionReading(opinion_type="plurality")],
     )
     decision_reading.posit(lotus_analysis)
     assert len(decision_reading.holdings) == len(lotus_analysis.holdings)
Пример #13
0
 def test_use_int_not_pint_without_dimension(self, make_response):
     mock_client = FakeClient(responses=make_response)
     to_read = load_holdings("holding_brad.yaml")
     loaded_holdings = readers.read_holdings(to_read, client=mock_client)
     anchored_holdings = AnchoredHoldings(holdings=[
         HoldingWithAnchors(holding=item) for item in loaded_holdings
     ])
     reading = OpinionReading(anchored_holdings=anchored_holdings)
     expectation_not_reasonable = list(reading.holdings)[6]
     assert "dimensionless" not in str(expectation_not_reasonable)
     assert expectation_not_reasonable.inputs[0].predicate.quantity == 3
Пример #14
0
 def get_majority(self) -> Optional[OpinionReading]:
     """Return the majority OpinionReading, creating it if needed."""
     majority = self.majority
     if majority:
         return majority
     for opinion in self.decision.opinions:
         if opinion.type == "majority":
             new_reading = OpinionReading(
                 opinion_type=opinion.type, opinion_author=opinion.author
             )
             self.opinion_readings.append(new_reading)
             return new_reading
     return None
Пример #15
0
    def test_selectors_not_duplicated(self, make_decision, raw_holding):
        """
        Test that the factors attribute for this Opinion contains
        one instance of the Fact "Mark stole a watch", but that both
        of the different text anchors for that Fact are attached to it.
        """
        watch = raw_holding["stolen watch"]
        holdings = readers.read_holdings_with_anchors([watch])
        cardenas = OpinionReading(anchored_holdings=holdings)

        assert any(selector.exact == "Mark stole the watch" for selector in
                   cardenas.anchored_holdings.holdings[0].anchors.quotes)
        assert any(selector.exact == "a watch was stolen by Mark" for selector
                   in cardenas.anchored_holdings.holdings[0].anchors.quotes)
        assert len(cardenas.anchored_holdings.holdings[0].anchors.quotes) == 2
Пример #16
0
 def posit(
     self,
     holdings: Union[
         AnchoredHoldings,
         Holding,
         Rule,
         HoldingWithAnchors,
         List[Union[HoldingWithAnchors, Holding, Rule]],
     ],
     holding_anchors: Optional[List[HoldingWithAnchors]] = None,
     named_anchors: Optional[List[TermWithAnchors]] = None,
     enactment_anchors: Optional[List[EnactmentWithAnchors]] = None,
     context: Optional[Sequence[Factor]] = None,
 ) -> None:
     """Add one or more Holdings to the majority Opinion of this Decision."""
     majority = self.get_majority()
     if majority is not None:
         reading_to_use = majority
     elif len(self.opinion_readings) == 1:
         reading_to_use = self.opinion_readings[0]
     elif not self.opinion_readings:
         self.opinion_readings = [OpinionReading()]
         reading_to_use = self.opinion_readings[0]
     else:
         raise AttributeError(
             "Cannot determine how to posit the Holding because this DecisionReading "
             "has multiple OpinionReadings, none of which is linked to a majority "
             "Opinion. Try using the .posit() method of one of the OpinionReadings "
             "on this object's `opinion_readings` attribute."
         )
     reading_to_use.posit(
         holdings=holdings,
         holding_anchors=holding_anchors,
         named_anchors=named_anchors,
         enactment_anchors=enactment_anchors,
         context=context,
     )
Пример #17
0
 def test_empty_holding_list_when_loading_opinion(self):
     reading = OpinionReading(opinion_type="majority")
     assert isinstance(reading.holdings, HoldingGroup)
Пример #18
0
 def test_opinion_entity_list(self, make_opinion, real_holding, make_entity,
                              make_evidence):
     watt = make_opinion["watt_majority"]
     h = real_holding
     e = make_entity
     reading = OpinionReading(opinion_type=watt.type,
                              opinion_author=watt.author)
     reading.posit(h["h1"], context=(e["motel"], e["watt"]))
     reading.posit(h["h2"], context=(e["trees"], e["motel"]))
     reading.posit(
         h["h3"],
         context=(
             make_evidence["generic"],
             e["motel"],
             e["watt"],
             e["trees"],
             e["tree_search"],
         ),
     )
     reading.posit(h["h4"],
                   context=(e["trees"], e["tree_search"], e["motel"],
                            e["watt"]))
     assert make_entity["watt"] in reading.generic_terms()
Пример #19
0
 def test_opinion_implied_by_decision(self, make_holding,
                                      make_decision_with_holding):
     watt = make_decision_with_holding["watt"]
     reading = OpinionReading()
     reading.posit(watt.holdings[0])
     assert reading.implied_by(watt)
Пример #20
0
 def test_opinion_posits_holding_dict_context(self, make_entity,
                                              make_response):
     """
     Having the Watt case posit a holding from the Brad
     case, but replacing one generic factor with a factor
     from Watt.
     """
     mock_client = FakeClient(responses=make_response)
     to_read = load_holdings("holding_brad.yaml")
     holdings = readers.read_holdings(to_read, client=mock_client)
     breading = OpinionReading()
     breading.clear_holdings()
     breading.posit(holdings)
     expectation_not_reasonable = breading.holdings[6]
     changes = ContextRegister()
     changes.insert_pair(
         key=expectation_not_reasonable.generic_terms()[0],
         value=make_entity["watt"],
     )
     context_holding = expectation_not_reasonable.new_context(changes)
     wreading = OpinionReading()
     wreading.clear_holdings()
     wreading.posit(context_holding)
     string = str(context_holding)
     assert "<Wattenburg> lived at <Bradley's house>" in string
     assert "<Wattenburg> lived at <Bradley's house>" in str(
         wreading.holdings[-1])