Skip to content

Commit

Permalink
infer Selector.exact only when source is given
Browse files Browse the repository at this point in the history
  • Loading branch information
mscarey committed Jun 27, 2019
1 parent 51f83a3 commit c39e484
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
12 changes: 6 additions & 6 deletions authorityspoke/selectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ class TextQuoteSelector:
:param source:
the :class:`.Code` where the quoted text can be found,
or the :class:`.Regime` that has enacted it.
Only needed if ``exact`` is not specified.
Only needed if ``exact`` is not specified. If this
parameter is given, then the ``exact`` text will be
stored even if it's the entire text of a section or
:class:`.Code`.
"""

path: Optional[str] = None
Expand All @@ -61,11 +64,8 @@ def __post_init__(self):
if self.source and not self.path:
object.__setattr__(self, "path", self.source.uri)

if not self.exact:
if (self.prefix or self.suffix) and not self.source:
object.__setattr__(
self, "exact", self.set_exact_from_source(self.source)
)
if self.source and not self.exact:
object.__setattr__(self, "exact", self.set_exact_from_source(self.source))

object.__delattr__(self, "source")

Expand Down
12 changes: 9 additions & 3 deletions tests/test_enactments.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,7 @@ def test_passage_from_cfr_code(self, make_code):

def test_cite_entire_constitution(self, make_regime):
entire_const = Enactment(
selector=TextQuoteSelector(path="/us/const", source=make_regime),
regime=make_regime,
selector=TextQuoteSelector(path="/us/const"), regime=make_regime
)
assert "and been seven Years a Citizen" in entire_const.text

Expand Down Expand Up @@ -170,16 +169,23 @@ def test_bill_of_rights_effective_date(self, make_enactment):
1791, 12, 15
)

def test_12th_A_effective_date(self, make_regime):
def test_date_and_text_from_path_and_regime(self, make_regime):
"""
This tests different parsing code because the date is
in the format "dated the 25th of September, 1804"
This also verifies that providing the ``regime`` to the
Enactment constructor is sufficient to assign the full text of
the section as the text of the Enactment, even though no
``exact``, ``prefix``, ``suffix``, or ``source`` parameter was
passed to the TextQuoteSelector constructor.
"""
amendment_12 = Enactment(
selector=TextQuoteSelector(path="/us/const/amendment-XII"),
regime=make_regime,
)
assert amendment_12.effective_date == datetime.date(1804, 9, 25)
assert "Electors shall meet" in amendment_12.text

def test_14th_A_effective_date(self, make_enactment):
# July 28, 1868
Expand Down

0 comments on commit c39e484

Please sign in to comment.