Skip to content

Commit

Permalink
raise ValueError when text not found from selector
Browse files Browse the repository at this point in the history
  • Loading branch information
mscarey committed Jun 10, 2019
1 parent 07f7b53 commit 9568c01
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 7 deletions.
5 changes: 4 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ jobs:
python3 -m venv venv
. venv/bin/activate
pip install -r requirements.txt
pip install -r requirements-dev.txt
pip install pytest
pip install pytest-cov
pip install coveralls
- save_cache:
paths:
Expand Down
11 changes: 9 additions & 2 deletions authorityspoke/enactments.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ def usc_statute_text():
if selector.path is not None:
docpath = selector.path.replace(self.uri, "")

if selector.path is None:
if selector.path is None: # selecting the whole Code
passages = self.xml.find_all(name="text")
elif self.jurisdiction == "us":
if self.level == "regulation":
Expand Down Expand Up @@ -297,7 +297,10 @@ def usc_statute_text():
)
if re.search(passage_regex, text, re.IGNORECASE):
return selector.exact
return None
raise ValueError(
f"Passage {selector.exact} from TextQuoteSelector "
+ f"not found in Code at path {selector.path}."
)

def __repr__(self):
return f'{self.__class__.__name__}("{self.filename}")'
Expand All @@ -324,6 +327,10 @@ class Enactment:
:param code:
the :class:`Code` where this legislative text appears.
:param regime:
a :class:`.Regime` with a :class:`.Jurisdiction` that has enacted
the :class:`Code` where this legislative text appears.
:param name:
an identifier for this object, often used if the object needs
to be referred to multiple times in the process of composing
Expand Down
10 changes: 6 additions & 4 deletions authorityspoke/relations.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,16 +138,18 @@ def update_matchlist(
self, matchlist: List[Dict[Factor, Factor]]
) -> List[Dict[Factor, Optional[Factor]]]:
"""
Filter a :py:class:`list` of possible :class:`.Factor` assignments with an :meth:`~Relation.unordered_comparison`.
Filter :class:`list` of :class:`.Factor` assignments with :meth:`~Relation.unordered_comparison`.
:param matchlist:
possible ways to match generic :class:`.Factor`\s of ``need_matches`` with ``available``.
possible ways to match generic :class:`.Factor`\s of
``need_matches`` with ``available``.
:returns:
a new version of ``matchlist`` filtered to be consistent with ``self``\'s :meth:`~Relation.unordered_comparison`.
a new version of ``matchlist`` filtered to be consistent with
``self``\'s :meth:`~Relation.unordered_comparison`.
"""
new_matchlist = []
for matches in matchlist:
for answer in self.unordered_comparison(matches, list(self.need_matches)):
for answer in self.unordered_comparison(matches=matches):
new_matchlist.append(answer)
return new_matchlist
8 changes: 8 additions & 0 deletions tests/test_selectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,11 @@ def test_section_text_from_path_and_regime(self, make_regime):
"In no case does copyright protection "
+ "for an original work of authorship extend to any"
)

def test_exact_text_not_in_selection(self, make_regime):
due_process_wrong_section = TextQuoteSelector(
path="/us/const/amendment-XV/1", exact="due process"
)
enactment = Enactment(selector=due_process_wrong_section, regime=make_regime)
with pytest.raises(ValueError):
print(enactment.text)

0 comments on commit 9568c01

Please sign in to comment.