Skip to content

Commit

Permalink
add tests for TextQuoteSelectors
Browse files Browse the repository at this point in the history
  • Loading branch information
mscarey committed Jun 5, 2019
1 parent 6b73a83 commit fa14717
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion authorityspoke/selectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def exact_from_ends(text: str) -> str:
elif self.source.__class__.__name__ == "Code":
code = self.source
else:
raise TypeError(
raise ValueError(
"If 'exact' parameter is not specified, you must specify "
+ "a 'Code' or 'Regime' object as the 'source' parameter to "
+ "obtain the exact text selection."
Expand Down
23 changes: 23 additions & 0 deletions tests/test_selectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,39 @@ def test_passage_from_uslm_code(self, make_code):
+ "for an original work of authorship extend to any"
)

def test_convert_selector_to_json(self, make_code):
usc17 = make_code["usc17"]
copyright_exceptions = TextQuoteSelector(
path="/us/usc/t17/s102/b", suffix="idea, procedure,", source=usc17
)
assert '"exact": "In no case does copyright' in copyright_exceptions.json

def test_failed_prefix(self, make_code):
usc17 = make_code["usc17"]
with pytest.raises(ValueError):
copyright_exceptions = TextQuoteSelector(
path="/us/usc/t17/s102/b", prefix="sound recordings", source=usc17
)

def test_fail_no_exact_or_source(self, make_code):
usc17 = make_code["usc17"]
with pytest.raises(ValueError):
copyright_exceptions = TextQuoteSelector(
path="/us/usc/t17/s102/b", prefix="sound recordings"
)

def test_failed_suffix(self, make_code):
usc17 = make_code["usc17"]
with pytest.raises(ValueError):
copyright_exceptions = TextQuoteSelector(
path="/us/usc/t17/s102/b", suffix="sound recordings", source=usc17
)

def test_section_text_from_path_and_regime(self, make_regime):
copyright_exceptions = TextQuoteSelector(
path="/us/usc/t17/s102/b", source=make_regime
)
assert copyright_exceptions.exact.startswith(
"In no case does copyright protection "
+ "for an original work of authorship extend to any"
)

0 comments on commit fa14717

Please sign in to comment.