def test_fail_to_check_enactment_implies_textsequence( self, section_11_subdivided): schema = EnactmentSchema() subdivided = schema.load(section_11_subdivided) text = subdivided.text_sequence() with pytest.raises(TypeError): _ = subdivided >= text
def test_error_for_unusable_selector(self, section_11_subdivided): schema = EnactmentSchema() section = schema.load(section_11_subdivided) selection = TextPositionSet(TextPositionSelector(0, 10), TextPositionSelector(1000, 1010)) with pytest.raises(ValueError): section.children[3].select(selection)
def test_load_enactment_with_cross_reference(self): data = { "heading": "", "content": "The Department of Beards shall waive the collection of beard tax upon issuance of beardcoin under Section 6C where the reason the maintainer wears a beard is due to bona fide religious, cultural, or medical reasons.", "start_date": "2013-07-18", "node": "/test/acts/47/6D/1", "children": [], "end_date": None, "url": "http://127.0.0.1:8000/api/v1/test/acts/47/6D/1@2020-01-01/", "citations": [{ "target_uri": "/test/acts/47/6C", "target_url": "http://127.0.0.1:8000/api/v1/test/acts/47/6C@2020-01-01/", "target_node": 1660695, "reference_text": "Section 6C", }], } schema = EnactmentSchema(many=False) enactment = schema.load(data) assert len(enactment._cross_references) == 1
def test_fail_to_check_if_textpassage_means_enactment( self, section_11_subdivided): schema = EnactmentSchema() subdivided = schema.load(section_11_subdivided) subdivided.select_all() text = subdivided.text_sequence() with pytest.raises(TypeError): _ = text.passages[0].means(subdivided)
def test_text_of_enactment_subset(self, section_11_together): schema = EnactmentSchema() combined = schema.load(section_11_together) selector = TextQuoteSelector( exact="barbers, hairdressers, or other male grooming professionals" ) combined.select(selector) sequence = combined.text_sequence() assert str(sequence).strip("…").startswith("barbers")
def test_add_string_as_selector(self, section_11_subdivided): schema = EnactmentSchema() section = schema.load(section_11_subdivided) section.select("The Department of Beards may issue licenses to such") more = section + "hairdressers" assert ( more.selected_text() == "The Department of Beards may issue licenses to such…hairdressers…" )
def test_dump_enactment_with_selector_to_dict(self, test_client): copyright_clause = test_client.read("/us/const/article/I/8/8") copyright_clause.select("Science and useful Arts") schema = EnactmentSchema() dumped = schema.dump(copyright_clause) selection = dumped["selection"][0] quote = dumped["text_version"]["content"][ selection["start"]:selection["end"]] assert quote == "Science and useful Arts"
def test_select_all(self, section_11_subdivided): """Clear selected text, and then select one subsection.""" schema = EnactmentSchema() combined = schema.load(section_11_subdivided) combined.select(None) combined.children[3].select() assert (combined.selected_text() == "…as they see fit to purchase a beardcoin from a customer…") assert (combined.children[3].selected_text() == "as they see fit to purchase a beardcoin from a customer")
def test_combined_section_implies_subdivided_section( self, section_11_together, section_11_subdivided): schema = EnactmentSchema() combined = schema.load(section_11_together) combined.select_all() subdivided = schema.load(section_11_subdivided) subdivided.select_all() assert combined >= subdivided assert combined > subdivided assert combined.text_sequence() > subdivided.text_sequence()
def test_enactment_subset(self, section_11_together): schema = EnactmentSchema() combined = schema.load(section_11_together) combined.select_all() limited = schema.load(section_11_together) selector = TextQuoteSelector( exact="barbers, hairdressers, or other male grooming professionals" ) limited.select(selector) assert not combined.means(limited) assert combined > limited
def test_fields_ordered_with_children_last(self, test_client): s103 = test_client.read(query="/us/usc/t17/s103", date="2020-01-01") schema = EnactmentSchema() dumped = schema.dump(s103) assert list( dumped["children"][0]["selection"][0].keys()) == ["start", "end"] as_json = json.dumps(dumped) # Start field comes before end field in selector assert '"selection": [{"start":' in as_json # "Children" field is last, since it's hard to read otherwise assert list(dumped.keys())[-1] == "children"
def test_select_nested_text_with_positions(self, section_11_subdivided): phrases = TextPositionSet( TextPositionSelector(0, 51), TextPositionSelector(61, 73), TextPositionSelector(112, 127), ) schema = EnactmentSchema() section = schema.load(section_11_subdivided) section.select(phrases) text_sequence = section.text_sequence() assert str(text_sequence) == ( "The Department of Beards may issue licenses to " "such…hairdressers…as they see fit…")
def test_get_passage(self, section_11_subdivided): """ Use selector to get passage from Enactment without changing which part is selected. Checks that `.selected_text()` is the same before and after `.get_passage()`. """ schema = EnactmentSchema() section = schema.load(section_11_subdivided) section.select(TextPositionSelector(61, 73)) assert section.selected_text() == "…hairdressers…" passage = section.get_passage(TextPositionSelector(112, 127)) assert passage == "…as they see fit…" assert section.selected_text() == "…hairdressers…"
def test_do_not_consolidate_from_different_sections( self, fifth_a, fourteenth_dp): schema = EnactmentSchema() due_process_5 = schema.load(fifth_a) due_process_14 = schema.load(fourteenth_dp) 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 = consolidate_enactments([due_process_5, due_process_14]) assert len(combined) == 2
def test_add_overlapping_enactments(self, fourth_a): schema = EnactmentSchema() 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,")) combined = search + warrant passage = ("against unreasonable searches and seizures, " + "shall not be violated, " + "and no Warrants shall issue,") assert passage in combined.text # Test that original Enactments unchanged assert "and no Warrants" not in search.selected_text()
def test_create_TextPositionSet_on_init(self, section_11_subdivided): schema = EnactmentSchema() section_11_subdivided["selection"] = [{"start": 0}] for child in section_11_subdivided["children"]: child["selection"] = [] section_11_subdivided["children"][1]["selection"] = [{ "start": 0, "end": 12 }] result = schema.load(section_11_subdivided) assert isinstance(result.selection, TextPositionSet) assert ( result.selected_text() == "The Department of Beards may issue licenses to such…hairdressers…" )
def test_get_positions_from_quotes(self, section_11_subdivided): schema = EnactmentSchema() section = schema.load(section_11_subdivided) quotes = [ TextQuoteSelector( exact="The Department of Beards may issue licenses to such"), TextQuoteSelector(exact="hairdressers", suffix=", or other male grooming"), TextQuoteSelector(exact="as they see fit"), ] positions = section.convert_quotes_to_position(quotes) assert positions == TextPositionSet( TextPositionSelector(0, 51), TextPositionSelector(61, 73), TextPositionSelector(112, 127), )
def test_cannot_select_text_with_citation(self, section_11_subdivided): schema = EnactmentSchema() section = schema.load(section_11_subdivided) cite = section.as_citation() with pytest.raises(TypeError): section.select_more(cite)
def test_load_nested_enactment(self, section6d): schema = EnactmentSchema() result = schema.load(section6d) assert result.heading.startswith("Waiver")
def test_select_none_with_None(self, section_11_subdivided): schema = EnactmentSchema() combined = schema.load(section_11_subdivided) combined.select(None) assert combined.selected_text() == ""
def test_select_all_nested(self, section_11_subdivided): """Clear selected text, and then select one subsection.""" schema = EnactmentSchema() combined = schema.load(section_11_subdivided) combined.select() assert combined.selected_text().startswith("The Department of Beards")
def test_select_with_position_selector(self, section_11_together): schema = EnactmentSchema() section = schema.load(section_11_together) section.select(TextPositionSelector(start=29, end=43)) assert section.selected_text() == "…issue licenses…"
def test_select_text_with_string(self, fourth_a): schema = EnactmentSchema() fourth_a = schema.load(fourth_a) fourth_a.select("The right of the people") assert fourth_a.selected_text() == "The right of the people…"