Example #1
0
 def test_get_json_filepath(self):
     directory = filepaths.get_directory_path("holdings")
     path = filepaths.make_filepath(
         filename="holding_feist.yaml", directory=directory
     )
     raw_holdings = loaders.load_holdings(filepath=path)
     assert raw_holdings[0]["outputs"]["type"] == "fact"
 def test_passage_from_imported_statute(self, make_regime):
     oracle_majority = loaders.load_and_read_decision(f"oracle_h.json").majority
     raw_holdings = loaders.load_holdings("holding_oracle.json")
     holdings = readers.read_holdings(raw_holdings, regime=make_regime)
     oracle_majority.posit(holdings)
     despite_text = str(list(oracle_majority.holdings)[5])
     assert "In no case does copyright protection " in despite_text
 def test_greater_than_implies_equal(self, make_beard_rule):
     beard_dictionary = loaders.load_holdings("beard_rules.json")
     beard_dictionary[0]["inputs"][1][
         "content"] = "the length of the suspected beard was = 8 millimetres"
     longer_hair_rule = readers.read_rule(beard_dictionary[0],
                                          client=client)
     assert make_beard_rule[0].implies(longer_hair_rule)
Example #4
0
 def test_load_any_enactments(self, fake_beard_client):
     """Test bug where holding's enactment's aren't loaded."""
     beard_dictionary = loaders.load_holdings("beard_rules.yaml")
     shorter = [beard_dictionary[0]]
     beard_rules = readers.read_holdings(shorter, client=fake_beard_client)
     expected = "facial hair no shorter than 5 millimetres"
     assert expected in beard_rules[0].enactments[0].selected_text()
 def test_enactment_name_index(self, make_regime):
     """
     Test error message:
     'Name "securing for authors" not found in the index of mentioned Factors'
     """
     feist_records = loaders.load_holdings("holding_feist.json")
     record, mentioned = name_index.index_names(feist_records)
     assert "securing for authors" in mentioned
 def test_same_enactment_objects_equal(self, make_regime):
     """
     Don't expect the holdings imported from the JSON to
     exactly match the holdings created for testing in conftest.
     """
     to_read = load_holdings("holding_watt.json")
     holdings = readers.read_holdings(to_read, regime=make_regime)
     assert holdings[0].enactments[0] == holdings[1].enactments[0]
 def test_import_some_holdings(self, make_regime):
     """
     Now generates 10, instead of 12, because the "exclusive" Holding
     is stored with that flag instead of generating Holdings that it
     implies.
     """
     lotus_holdings = load_holdings("holding_lotus.json")
     assert len(lotus_holdings) == 10
Example #8
0
 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_enactment_name_in_holding(self, make_regime):
     """
     Test error message:
     'Name "securing for authors" not found in the index of mentioned Factors'
     """
     feist_records = loaders.load_holdings("holding_feist.json")
     feist_holding = readers.read_holding(feist_records[0], regime=make_regime)
     assert "securing for limited Times" in feist_holding.short_string
Example #10
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
 def test_different_enactments_same_code(self, make_regime):
     """
     Don't expect the holdings imported from the JSON to
     exactly match the holdings created for testing in conftest.
     """
     to_read = load_holdings("holding_lotus.json")
     holdings = readers.read_holdings(to_read, regime=make_regime)
     assert holdings[0].enactments[0].code == holdings[1].enactments[0].code
     assert holdings[0].enactments[0].code is holdings[1].enactments[0].code
 def test_same_object_for_enactment_in_import(self, make_regime):
     """
     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.
     """
     to_read = load_holdings("holding_brad.json")
     holdings = readers.read_holdings(to_read, regime=make_regime)
     assert any(holdings[6].inputs[0] == x for x in holdings[5].inputs)
 def test_greater_than_contradicts_not_greater(self, make_beard_rule):
     beard_dictionary = loaders.load_holdings("beard_rules.json")
     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_rule(beard_dictionary[1],
                                                  client=client)
     assert make_beard_rule[1].contradicts(long_hair_is_not_a_beard)
    def test_use_int_not_pint_without_dimension(self, make_regime, make_opinion):

        brad = make_opinion["brad_majority"]
        to_read = load_holdings("holding_brad.json")
        holdings = readers.read_holdings(to_read, regime=make_regime)
        brad.posit(holdings)
        expectation_not_reasonable = list(brad.holdings)[6]
        assert "dimensionless" not in str(expectation_not_reasonable)
        assert isinstance(expectation_not_reasonable.inputs[0].predicate.quantity, int)
Example #15
0
 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_imported_holding_same_as_test_object(self, real_holding, make_opinion):
        """
        These objects were once the same, but now the JSON treats
        "lived at" at "operated" as separate Factors.
        """

        watt = make_opinion["watt_majority"]
        watt.posit(load_holdings("holding_watt.json"))
        assert watt.holdings[0] == real_holding["h1"]
Example #17
0
 def test_passage_from_imported_statute(self, fake_usc_client):
     oracle = loaders.load_decision("oracle_h.json")
     oracle_decision = Decision(**oracle)
     reading = DecisionReading(decision=oracle_decision)
     loaded = loaders.load_holdings("holding_oracle.yaml")
     holdings = readers.read_holdings(loaded, client=fake_usc_client)
     reading.posit(holdings)
     despite_text = str(list(reading.holdings)[5])
     assert "In no case does copyright protection " in despite_text
Example #18
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)
Example #19
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
Example #20
0
    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_name_inferred_from_content(self, make_regime):
        """
        Test that a name field is generated for Factors without them.

        The Factors must be inserted in "mentioned" with the generated name.
        """

        oracle_records = loaders.load_holdings("holding_oracle.json")
        oracle_holdings = readers.read_holdings(oracle_records, regime=make_regime)
        factor = oracle_holdings[2].inputs[0]
        assert factor.content == "{} was an original work"
Example #22
0
 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])
 def test_contradictory_fact_about_beard_length(self, make_beard_rule):
     beard_dictionary = loaders.load_holdings("beard_rules.json")
     beard_dictionary[1]["despite"] = beard_dictionary[1]["inputs"][0]
     beard_dictionary[1]["inputs"] = {
         "type": "fact",
         "content": "the length of the suspected beard was >= 12 inches",
     }
     beard_dictionary[1]["outputs"][0]["truth"] = False
     beard_dictionary[1]["mandatory"] = True
     long_thing_is_not_a_beard = readers.read_rule(beard_dictionary[1],
                                                   client=client)
     assert make_beard_rule[1].contradicts(long_thing_is_not_a_beard)
    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"
            ]
        """

        raw_holdings = loaders.load_holdings("holding_feist.json")
        holding_links = anchors.get_holding_anchors(raw_holdings)
        assert len(holding_links[6]) == 2
Example #25
0
    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_import_holding(self, make_regime):
     """
     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.
     """
     cardenas_json = load_holdings("holding_cardenas.json")
     cardenas_holdings = readers.read_holdings(cardenas_json, regime=make_regime)
     assert len(cardenas_holdings) == 2
Example #27
0
    def test_contradictory_fact_about_beard_length(self, fake_beard_client,
                                                   make_beard_rule):
        beard_dictionary = loaders.load_holdings("beard_rules.yaml")
        long_means_not_beard = readers.read_holdings(
            beard_dictionary[1], client=fake_beard_client)[0].rule
        long_means_not_beard.set_despite(
            [long_means_not_beard.inputs[0], long_means_not_beard.inputs[2]])
        long_means_not_beard.set_inputs([long_means_not_beard.inputs[1]])
        long_means_not_beard.set_outputs(
            [long_means_not_beard.outputs[0].negated()])
        long_means_not_beard.mandatory = True

        assert make_beard_rule[1].contradicts(long_means_not_beard)
        assert long_means_not_beard.contradicts(make_beard_rule[1])
    def test_exclusive_does_not_result_in_more_holdings(self, make_regime):
        """
        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.
        """
        feist_json = load_holdings("holding_feist.json")
        feist_holdings = readers.read_holdings(feist_json, regime=make_regime)

        assert len(feist_holdings) == len(feist_json)
Example #29
0
    def test_new_context_creates_equal_rule(self, make_opinion_with_holding,
                                            make_response):
        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_pairs = {
            "proof of Bradley's guilt": "proof of Wattenburg's guilt",
            "Bradley": "Wattenburg",
            "officers' search of the yard":
            "officers' search of the stockpile",
            "Bradley's marijuana patch": "the stockpile of trees",
        }
        watt.posit(brad.holdings[0], context_pairs)
        assert watt.holdings[-1].means(brad.holdings[0])
    def test_read_holdings_and_then_get_anchors(self, make_regime):
        """
        Test whether read_holdings mutates raw_holding and makes it
        impossible to get text anchors.
        """
        raw_holdings = load_holdings(f"holding_oracle.json")
        oracle_holdings, mentioned, holding_anchors = readers.read_holdings_with_index(
            raw_holdings, regime=make_regime
        )
        named_anchors = anchors.get_named_anchors(mentioned)

        assert isinstance(oracle_holdings[0], Holding)
        assert isinstance(named_anchors.popitem()[1].pop(), TextQuoteSelector)

        from authorityspoke.io.loaders import load_holdings_with_index