def test_whitespace_when_selecting_with_suffix(self, e_copyright): """Overwrite existing selector and test for trailing whitespace.""" copyright_selector = TextQuoteSelector(suffix="idea, procedure,") e_copyright.select(copyright_selector) assert e_copyright.selected_text() == ( "In no case does copyright protection " + "for an original work of authorship extend to any…")
def test_make_enactment_from_selector_without_code(self, make_code): select = TextQuoteSelector(suffix=", shall be vested") art_3 = Enactment( selector=select, source="/us/const/article-III/1", code=make_code["const"] ) assert art_3.text.startswith("The judicial Power") assert art_3.text.endswith("the United States")
def test_exact_text_not_in_selection(self, fake_usc_client): passage = fake_usc_client.read_from_json({ "node": "/us/const/amendment/XV/1", }) selector = TextQuoteSelector(exact="due process") with pytest.raises(TextSelectionError): passage.select(selector)
def test_serialize_enactment_after_adding(self, fourth_a): schema = ExpandableEnactmentSchema() search = schema.load(fourth_a) warrant = deepcopy(search) search.select(TextQuoteSelector(suffix=", and no Warrants")) warrant.select( TextQuoteSelector( exact="shall not be violated, and no Warrants shall issue,")) combined_enactment = search + warrant # search.select_more_text_at_current_node(warrant.selection) dumped = schema.dump(combined_enactment) assert dumped["text_version"]["content"].startswith("The right") assert dumped["text_version"].get("uri") is None
def test_exact_text_not_in_selection(self, make_regime): due_process_wrong_section = TextQuoteSelector(exact="due process") with pytest.raises(ValueError): _ = readers.read_enactment( { "selector": due_process_wrong_section, "source": "/us/const/amendment-XV/1", }, regime=make_regime, )
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")
def select_text(self, selector: TextQuoteSelector) -> Optional[str]: r""" Get text using a :class:`.TextQuoteSelector`. :param selector: a selector referencing a text passage in this :class:`Opinion`. :returns: the text referenced by the selector, or ``None`` if the text can't be found. """ if re.search(selector.passage_regex(), self.text, re.IGNORECASE): return selector.exact raise ValueError( f'Passage "{selector.exact}" from TextQuoteSelector ' + f'not found in Opinion "{self}".')
def test_posit_one_holding_with_anchor( self, make_opinion, raw_holding, make_regime ): holding, mentioned, anchor_list = readers.read_holdings_with_index( raw_holding["bradley_house"], regime=make_regime, many=False ) cardenas = make_opinion["cardenas_majority"] cardenas.posit_holding( holding, holding_anchors=TextQuoteSelector( exact="some text supporting this holding" ), ) assert ( cardenas.holding_anchors[holding][0].exact == "some text supporting this holding" )
def test_insert_duplicate_anchor_in_factor_index(self): api = Entity(name="the Java API", generic=True, plural=False) quote_selector = TextQuoteSelector( exact="it possesses at least some minimal degree of creativity.") anchors = TextPositionSet(quotes=quote_selector) fact = Fact( predicate=Predicate( content= "$product possessed at least some minimal degree of creativity" ), terms=[api], ) term = TermWithAnchors(term=fact, anchors=anchors) index = AnchoredHoldings(holdings=[], named_anchors=[term]) index.add_term(term=fact, anchors=anchors) assert len(index.named_anchors) == 1 assert index.named_anchors[0].anchors.quotes == [quote_selector]
def test_make_enactment_from_selector_without_code(self, fake_usc_client): selector = TextQuoteSelector(suffix=" to their respective") art_3 = fake_usc_client.read("/us/const/article/I/8/8") passage = art_3.select(selector) assert passage.text.startswith("To promote") assert passage.selected_text().endswith("exclusive Right…")
def test_invalid_text_selector(self, make_decision_with_holding): oracle = make_decision_with_holding["oracle"] anchor = TextQuoteSelector(exact="text not in opinion") with pytest.raises(TextSelectionError): _ = oracle.decision.majority.select_text(selector=anchor)