def test_nest_selector_fields_before_loading(self, test_client, fourth_a): fourth_a["selection"] = [{"start": 10, "end": 20}] fourth_a["suffix"] = ", and no Warrants shall issue" schema = ExpandableEnactmentSchema() updated = schema.move_selector_fields(fourth_a) assert updated["selection"][1][ "suffix"] == ", and no Warrants shall issue"
def test_load_enactment_with_text_anchor(self, provision_with_text_anchor, test_client): schema = ExpandableEnactmentSchema() record = test_client.update_enactment_from_api( provision_with_text_anchor) result = schema.load(record) assert result.anchors[0].exact == "17 U.S.C. § 102(a)"
def test_invalid_selector_text(self, section_11_subdivided): section_11_subdivided["selection"] = [{ "exact": "text that doesn't exist in the code" }] schema = ExpandableEnactmentSchema() with pytest.raises(TextSelectionError): _ = schema.load(section_11_subdivided)
def test_enactment_does_not_fail_for_excess_selector( self, section_11_subdivided): """Test selector that extends into the text of a subnode.""" exact = "The Department of Beards may issue licenses to such barbers" section_11_subdivided["exact"] = exact schema = ExpandableEnactmentSchema(many=False) enactment = schema.load(section_11_subdivided) assert enactment.selected_text() == exact + "…"
def test_non_overlapping_text_selection(self, fourth_a): schema = ExpandableEnactmentSchema() left = schema.load(fourth_a) right = schema.load(fourth_a) left.select("The right of the people to be secure in their persons") right.select("shall not be violated") left.select_more_text_at_current_node(right.selection) assert left.selected_text() == ( "The right of the people to be secure in their persons…" "shall not be violated…")
def test_enactment_with_False_as_selector(self, section_11_subdivided): schema = ExpandableEnactmentSchema() section_11_subdivided["selection"] = False section_11_subdivided["children"][1]["selection"] = [{ "start": 0, "end": 12 }] result = schema.load(section_11_subdivided) answer = "…hairdressers…" assert result.selected_text() == answer
def test_enactment_with_True_as_selector(self, section_11_subdivided): schema = ExpandableEnactmentSchema() section_11_subdivided["selection"] = True section_11_subdivided["children"][1]["selection"] = [{ "start": 0, "end": 12 }] result = schema.load(section_11_subdivided) answer = "The Department of Beards may issue licenses to such…hairdressers…" assert result.selected_text() == answer
def test_add_overlapping_text_selection(self, fourth_a): schema = ExpandableEnactmentSchema() search = schema.load(fourth_a) warrant = schema.load(fourth_a) search.select(TextQuoteSelector(suffix=", and no Warrants")) warrant.select( TextQuoteSelector( exact="shall not be violated, and no Warrants shall issue,")) search.select_more_text_at_current_node(warrant.selection) passage = ("against unreasonable searches and seizures, " + "shall not be violated, " + "and no Warrants shall issue,") assert passage in search.selected_text()
def test_unequal_enactment_text(self, fourth_a): search_clause = fourth_a.copy() search_clause["selection"] = [{"suffix": ", and no Warrants"}] schema = ExpandableEnactmentSchema() fourth_a = schema.load(fourth_a) fourth_a.select_all() search_clause = schema.load(search_clause) assert fourth_a != search_clause assert not fourth_a.means(search_clause) assert fourth_a >= search_clause
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_add_shorter_plus_longer(self, fourth_a): search_clause = fourth_a.copy() search_clause["selection"] = [{"suffix": ", and no Warrants"}] schema = ExpandableEnactmentSchema() fourth_a = schema.load(fourth_a) fourth_a.select_all() search_clause = schema.load(search_clause) greater_plus_lesser = search_clause + fourth_a assert greater_plus_lesser.text == fourth_a.text assert greater_plus_lesser.means(fourth_a) lesser_plus_greater = fourth_a + search_clause assert lesser_plus_greater.text == fourth_a.text assert lesser_plus_greater.means(fourth_a)
def test_consolidate_enactments(self, fourth_a): search_clause = fourth_a.copy() search_clause["selection"] = [{"suffix": ", and no Warrants"}] warrants_clause = fourth_a.copy() warrants_clause["selection"] = [{"prefix": "shall not be violated,"}] schema = ExpandableEnactmentSchema() search = schema.load(search_clause) warrants = schema.load(warrants_clause) fourth_amendment = fourth_a.copy() fourth_amendment["selection"] = True fourth = schema.load(fourth_amendment) consolidated = consolidate_enactments([fourth, search, warrants]) assert len(consolidated) == 1 assert consolidated[0].means(fourth)
def test_select_unavailable_text(self, fourth_a): schema = ExpandableEnactmentSchema() fourth = schema.load(fourth_a) with pytest.raises(TextSelectionError): fourth.select("right to privacy")
def test_load_enactment_missing_textversion_field( self, fourth_a_no_text_version): schema = ExpandableEnactmentSchema(many=False) enactment = schema.load(fourth_a_no_text_version) assert enactment.text.startswith("The right of the people")
def test_load_with_text_quote_selector(self, section_11_together): schema = ExpandableEnactmentSchema() section_11_together["selection"] = [{"exact": "Department of Beards"}] result = schema.load(section_11_together) assert result.selected_text() == "…Department of Beards…"
def test_selector_not_wrapped_in_list(self, section_11_together): schema = ExpandableEnactmentSchema() section_11_together["selection"] = {"start": 4, "end": 24} result = schema.load(section_11_together) assert result.selected_text() == "…Department of Beards…"