def test_do_not_consolidate_from_different_sections(self, make_response): client = FakeClient(responses=make_response) due_process_5 = client.read("/us/const/amendment/V") due_process_14 = client.read("/us/const/amendment/XIV") due_process_5.select( "life, liberty, or property, without due process of law") due_process_14.select( "life, liberty, or property, without due process of law") combined = EnactmentGroup(passages=[due_process_5, due_process_14]) assert len(combined) == 2
def test_fact_from_loaded_holding(self, make_response): to_read = load_holdings("holding_watt.yaml") mock_client = FakeClient(responses=make_response) holdings = readers.read_holdings(to_read, client=mock_client) new_fact = holdings[0].inputs[1] assert "lived at <Hideaway Lodge>" in str(new_fact) assert isinstance(new_fact.terms[0], Entity)
def test_posit_anchored_holdings(self, make_response): client = FakeClient(responses=make_response) oracle_dict = load_decision("oracle_h.json") lotus_dict = load_decision("lotus_h.json") oracle = Decision(**oracle_dict) lotus = Decision(**lotus_dict) oracle_ah = read_anchored_holdings_from_file("holding_oracle.yaml", client=client) lotus_ah = read_anchored_holdings_from_file("holding_lotus.yaml", client=client) oracle_reading = DecisionReading(decision=oracle) lotus_reading = DecisionReading(decision=lotus) oracle_reading.posit( holdings=oracle_ah.holdings, named_anchors=oracle_ah.named_anchors, enactment_anchors=oracle_ah.enactment_anchors, ) lotus_reading.posit( holdings=lotus_ah.holdings, named_anchors=lotus_ah.named_anchors, enactment_anchors=lotus_ah.enactment_anchors, ) assert lotus_reading.contradicts(oracle_reading)
def test_new_context_inferring_factors_to_change(self, make_opinion_with_holding, make_response): """ This changes watt's holdings; may break tests below. """ watt = make_opinion_with_holding["watt_majority"] brad = make_opinion_with_holding["brad_majority"] client = FakeClient(responses=make_response) watt.clear_holdings() watt_raw = loaders.load_holdings("holding_watt.yaml") watt.posit(readers.read_holdings(watt_raw, client=client)) brad.clear_holdings() brad_raw = loaders.load_holdings("holding_brad.yaml") brad.posit(readers.read_holdings(brad_raw, client=client)) context_items = [ "proof of Wattenburg's guilt", "<Wattenburg>", "<officers' search of the stockpile>", "<Hideaway Lodge>", "<the stockpile of trees>", ] watt.posit(brad.holdings[0], context=context_items) assert watt.holdings[-1].means(brad.holdings[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])
def test_greater_than_implies_equal(self, beard_response, make_beard_rule): client = FakeClient(responses=beard_response) beard_dictionary = loaders.load_holdings("beard_rules.yaml") beard_dictionary[0]["inputs"][1][ "content"] = "the length of the suspected beard was = 8 millimetres" longer_hair_rule = readers.read_holdings([beard_dictionary[0]], client=client) assert make_beard_rule[0].implies(longer_hair_rule[0])
def test_decision_posits_holdings_with_anchors(self, make_response): mock_client = FakeClient(responses=make_response) oracle_holdings_with_anchors = loaders.read_anchored_holdings_from_file( "holding_oracle.yaml", client=mock_client) reading = DecisionReading(decision=Decision( decision_date=date(2019, 1, 1))) reading.posit(oracle_holdings_with_anchors) assert len(reading.holdings) == 20
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
def test_same_enactment_objects_equal(self, make_response): """ Don't expect the holdings imported from the JSON to exactly match the holdings created for testing in conftest. """ mock_client = FakeClient(responses=make_response) to_read = load_holdings("holding_watt.yaml") holdings = readers.read_holdings(to_read, client=mock_client) assert holdings[0].enactments[0].means(holdings[1].enactments[0])
def test_same_object_for_enactment_in_import(self, make_response): """ The JSON for Bradley repeats identical fields to create the same Factor for multiple Rules, instead of using the "name" field as a shortcut. This tests whether the loaded objects turn out equal. """ mock_client = FakeClient(responses=make_response) to_read = load_holdings("holding_brad.yaml") holdings = readers.read_holdings(to_read, client=mock_client) assert any(holdings[6].inputs[0].means(x) for x in holdings[5].inputs)
def test_same_enactment_in_two_opinions(self, make_response): mock_client = FakeClient(responses=make_response) to_read = load_holdings("holding_brad.yaml") brad_holdings = readers.read_holdings(to_read, client=mock_client) to_read = load_holdings("holding_watt.yaml") watt_holdings = readers.read_holdings(to_read, client=mock_client) assert any(watt_holdings[0].enactments[0].means(brad_enactment) for brad_enactment in brad_holdings[0].enactments)
def test_pass_holdings_to_decision_reading_constructor( self, make_decision, make_response): mock_client = FakeClient(responses=make_response) oracle = make_decision["oracle"] oracle_holdings = read_holdings_from_file("holding_oracle.yaml", client=mock_client) oracle_reading = DecisionReading(decision=oracle) oracle_reading.posit(oracle_holdings) assert (oracle_reading.opinion_readings[0].holdings[0].enactments[0]. node == "/us/usc/t17/s102/a")
def test_load_from_fake_client(self): fake_client = FakeClient.from_file("usc.json") filepath = filepaths.make_filepath(filename="holding_mazza_alaluf.yaml") result = read_anchored_holdings_from_file(filepath=filepath, client=fake_client) key = "the fact it was false that <Turismo Costa Brava> was a domestic financial institution" anchors = result.get_term_anchors(key) assert anchors.quotes[0].exact.startswith( "without respect to whether or not Turismo" ) assert len(result.holdings) == 2
def test_getting_factors_from_opinion(self, make_opinion_with_holding, make_response): client = FakeClient(responses=make_response) watt = make_opinion_with_holding["watt_majority"] watt.clear_holdings() watt_raw = loaders.load_holdings("holding_watt.yaml") holdings_to_posit = readers.read_holdings(watt_raw, client=client) watt.posit(holdings_to_posit) factors = watt.factors_by_name() assert "proof of Wattenburg's guilt" in factors.keys()
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
def test_greater_than_contradicts_not_greater(self, beard_response, make_beard_rule): client = FakeClient(responses=beard_response) beard_dictionary = loaders.load_holdings("beard_rules.yaml") beard_dictionary[1]["inputs"][1][ "content"] = "the length of the suspected beard was >= 12 inches" beard_dictionary[1]["outputs"][0]["truth"] = False beard_dictionary[1]["mandatory"] = True long_hair_is_not_a_beard = readers.read_holdings([beard_dictionary[1]], client=client) assert make_beard_rule[1].contradicts(long_hair_is_not_a_beard[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
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 test_posit_list_of_holdings_and_imply(self, make_opinion_with_holding, make_response): watt = make_opinion_with_holding["watt_majority"] brad = make_opinion_with_holding["brad_majority"] watt.clear_holdings() brad.clear_holdings() client = FakeClient(responses=make_response) some_rules_raw = loaders.load_holdings(filename="holding_watt.yaml") some_rules = readers.read_holdings(some_rules_raw, client=client) for case in (watt, brad): case.clear_holdings() case.posit(some_rules[:3])
class TestLoadAndReadFake: client = FakeClient.from_file("usc.json") @pytest.mark.vcr def test_read_holdings_from_file(self): oracle_holdings = read_holdings_from_file( "holding_oracle.yaml", client=self.client ) assert oracle_holdings[0] def test_read_holdings_in_nested_rule(self): watt_holdings = read_holdings_from_file("holding_watt.yaml", client=self.client) assert watt_holdings[4].inputs[0].terms[0].name == "Hideaway Lodge"
def test_multiple_non_Factor_selectors_for_Holding(self): """ The Holding-level TextQuoteSelectors should be built from this: "text": [ "Census data therefore do not|trigger|copyright", "|may|possess the requisite originality" ] """ client = FakeClient.from_file("usc.json") holdings = loaders.read_anchored_holdings_from_file( "holding_feist.yaml", client=client) assert len(holdings.holdings[6].anchors.quotes) == 2
def test_read_holdings_and_then_get_anchors(self, make_response): """ Test whether read_holdings mutates raw_holding and makes it impossible to get text anchors. """ mock_client = FakeClient(responses=make_response) raw_holdings = load_holdings("holding_oracle.yaml") loaded = readers.read_holdings_with_anchors(raw_holdings, client=mock_client) assert isinstance(loaded.holdings[0], HoldingWithAnchors) assert isinstance(loaded.named_anchors[1].anchors.quotes[0], TextQuoteSelector)
def test_consolidate_adjacent_passages(self, make_response): client = FakeClient(responses=make_response) copyright_clause = client.read("/us/const/article/I/8/8") copyright_statute = client.read("/us/usc/t17/s102/b") passage = copyright_clause.select(None) securing_for_authors = passage + ( "To promote the Progress of Science and " "useful Arts, by securing for limited Times to Authors") and_inventors = passage + "and Inventors" right_to_writings = passage + "the exclusive Right to their respective Writings" to_combine = [ copyright_statute, securing_for_authors, and_inventors, right_to_writings, ] combined = EnactmentGroup(passages=to_combine) assert len(combined) == 2 assert any( law.selected_text().startswith("To promote the Progress") and law.selected_text().endswith("their respective Writings…") for law in combined)
def test_exclusive_does_not_result_in_more_holdings(self, make_response): """ The intended behavior is now for the Holding to assert that its Rule is the "exclusive" way to reach the outputs, and to have an additional function that can generate additional Rules that can be inferred from the exclusive flag. "Implies" and "contradict" methods will be able to look at the Holding's generated Rules as well as its original Rule. """ mock_client = FakeClient(responses=make_response) feist_json = load_holdings("holding_feist.yaml") feist_holdings = readers.read_holdings(feist_json, client=mock_client) assert len(feist_holdings) == len(feist_json)
def test_import_holding(self, make_response): """ Based on this text: This testimony tended “only remotely” to prove that appellant had committed the attempted robbery of money from the 7-Eleven store. In addition, the probative value of the evidence was substantially outweighed by the inflammatory effect of the testimony on the jury. Hence, admission of the testimony concerning appellant’s use of narcotics was improper. """ mock_client = FakeClient(responses=make_response) cardenas_dict = load_holdings("holding_cardenas.yaml") cardenas_holdings = readers.read_holdings(cardenas_dict, client=mock_client) assert len(cardenas_holdings) == 2
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
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)
def test_select_enactment_text_by_default(self, make_response): mock_client = FakeClient(responses=make_response) holding_dict = { "outputs": [{ "type": "fact", "content": "the Lotus menu command hierarchy was copyrightable", }], "enactments": { "enactment": { "node": "/us/usc/t17/s410/c" } }, } holding = readers.read_holdings([holding_dict], client=mock_client) assert holding[0].enactments[0].selected_text().startswith( "In any judicial")
def test_error_because_string_does_not_match_factor_name( self, make_response): rule_holding = { "inputs": ["this factor hasn't been mentioned"], "outputs": [{ "type": "fact", "content": "{the dog} bit {the man}" }], "enactments": [{ "enactment": { "node": "/us/const/amendment/IV" } }], "mandatory": True, } mock_client = FakeClient(responses=make_response) with pytest.raises(ValidationError): readers.read_holdings([rule_holding], client=mock_client)
def test_holding_inferred_from_exclusive(self, make_enactment, make_response): """ Test whether the Feist opinion object includes a holding that was inferred from an entry in the JSON saying that the "exclusive" way to reach the output "Rural's telephone directory was copyrightable" is to have the input "Rural's telephone directory was original". The inferred holding says that in the absence of the input "Rural's telephone directory was original", the court MUST ALWAYS find the output to be absent as well. Marked xfail because the "exclusive" flag no longer causes inferred Holdings to be expanded. Instead, it now should generate inferred Rules that aren't expanded during data loading. """ mock_client = FakeClient(responses=make_response) to_read = load_holdings("holding_feist.yaml") feist_holdings = readers.read_holdings(to_read["holdings"], client=mock_client) directory = Entity(name="Rural's telephone directory") not_original = Fact(Predicate(content="{} was an original work"), directory, absent=True) not_copyrightable = Fact(Predicate(content="{} was copyrightable"), directory, absent=True) no_originality_procedure = Procedure(outputs=not_copyrightable, inputs=not_original) no_originality_rule = Rule( no_originality_procedure, mandatory=True, universal=True, enactments=[ make_enactment["securing_for_authors"], make_enactment["right_to_writings"], make_enactment["copyright_requires_originality"], ], ) assert feist_holdings[4].rule.means(no_originality_rule)