Skip to content

Commit

Permalink
use different Legislice schema imports for JSON and YAML
Browse files Browse the repository at this point in the history
  • Loading branch information
mscarey committed May 7, 2021
1 parent 7c97775 commit 2e48e01
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 70 deletions.
1 change: 1 addition & 0 deletions authorityspoke/io/downloads.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import eyecite
from eyecite.models import CaseCitation
from legislice import Client as LegisClient
import requests

from authorityspoke.decisions import CAPCitation, Decision
Expand Down
14 changes: 14 additions & 0 deletions authorityspoke/io/fake_enactments.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from typing import Dict, Optional, Union

from legislice.download import Client, normalize_path, LegislicePathError, RawEnactment
from legislice.enactments import CrossReference, Enactment


# A dict indexing responses by iso-format date strings.
Expand Down Expand Up @@ -127,3 +128,16 @@ def fetch(self, query: str, date: Union[datetime.date, str] = "") -> RawEnactmen

def _fetch_from_url(self, url: str) -> None:
raise RuntimeError("Network access not allowed from FakeClient")

def read(
self,
query: Union[str, CrossReference],
date: Union[datetime.date, str] = "",
) -> Enactment:
"""
Use text expansion, unlike a real client.
"""
raw_enactment = self.fetch(query=query, date=date)
enactment = self.read_from_json(raw_enactment, use_text_expansion=True)
enactment.select_all()
return enactment
4 changes: 3 additions & 1 deletion authorityspoke/io/schemas_yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
from anchorpoint.textselectors import TextQuoteSelector, TextPositionSelector
from anchorpoint.schemas import SelectorSchema
from legislice import Enactment
from legislice.schemas import EnactmentSchema as LegisliceSchema
from legislice.schemas import enactment_needs_api_update
from legislice.yaml_schemas import ExpandableEnactmentSchema as LegisliceSchema

from nettlesome.entities import Entity
from nettlesome.predicates import Predicate
from nettlesome.quantities import Comparison, QuantityRange, Quantity
Expand All @@ -32,6 +33,7 @@
from authorityspoke.io.name_index import RawFactor, RawPredicate
from authorityspoke.io.nesting import nest_fields
from authorityspoke.io import text_expansion

from authorityspoke.opinions import Opinion, AnchoredHoldings
from authorityspoke.pleadings import Pleading, Allegation

Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
anchorpoint>=0.4.4
git+git://github.com/mscarey/anchorpoint.git@b866676a9f2ca420ac921523023052593bc1a7c8#egg=anchorpoint
apispec[validation]~=4.3.0
apispec-oneofschema
eyecite
legislice>=0.5.0
git+git://github.com/mscarey/legislice.git@a9b9ad563c2096702f74fdc12267dbee2c018f34#egg=legislice
marshmallow>=3.10
marshmallow-oneofschema
nettlesome>=0.5.0
Expand Down
50 changes: 5 additions & 45 deletions tests/cassettes/TestDump.test_dump_dict.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,68 +9,28 @@ interactions:
Connection:
- keep-alive
User-Agent:
- python-requests/2.25.0
authorization:
- DUMMY
method: GET
uri: https://authorityspoke.com/api/v1/us/const/article/I/8/8
response:
body:
string: ''
headers:
Connection:
- keep-alive
Content-Length:
- '0'
Content-Type:
- text/html; charset=utf-8
Date:
- Sat, 28 Nov 2020 10:19:39 GMT
Location:
- /api/v1/us/const/article/I/8/8/
Referrer-Policy:
- same-origin
Server:
- gunicorn/20.0.4
Via:
- 1.1 vegur
X-Content-Type-Options:
- nosniff
status:
code: 301
message: Moved Permanently
- request:
body: null
headers:
Accept:
- '*/*'
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
User-Agent:
- python-requests/2.25.0
- python-requests/2.25.1
authorization:
- DUMMY
method: GET
uri: https://authorityspoke.com/api/v1/us/const/article/I/8/8/
response:
body:
string: '{"heading":"Patents and copyrights.","start_date":"1788-09-13","node":"/us/const/article/I/8/8","url":"https://authorityspoke.com/api/v1/us/const/article/I/8/8/","end_date":null,"content":"To
string: '{"heading":"Patents and copyrights.","start_date":"1788-09-13","node":"/us/const/article/I/8/8","text_version":{"id":735650,"url":"https://authorityspoke.com/api/v1/textversions/735650/","content":"To
promote the Progress of Science and useful Arts, by securing for limited Times
to Authors and Inventors the exclusive Right to their respective Writings
and Discoveries;","children":[],"citations":[],"parent":"https://authorityspoke.com/api/v1/us/const/article/I/8/"}'
and Discoveries;"},"url":"https://authorityspoke.com/api/v1/us/const/article/I/8/8/","end_date":null,"children":[],"citations":[],"parent":"https://authorityspoke.com/api/v1/us/const/article/I/8/"}'
headers:
Allow:
- GET, POST, PUT, PATCH, HEAD, OPTIONS
Connection:
- keep-alive
Content-Length:
- '459'
- '551'
Content-Type:
- application/json
Date:
- Sat, 28 Nov 2020 10:19:39 GMT
- Fri, 07 May 2021 06:20:32 GMT
Referrer-Policy:
- same-origin
Server:
Expand Down
3 changes: 2 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from anchorpoint.textselectors import TextQuoteSelector
from dotenv import load_dotenv
from legislice.download import Client
from legislice.yaml_schemas import ExpandableEnactmentSchema as EnactmentSchema
from nettlesome.terms import ContextRegister
from nettlesome.entities import Entity
from nettlesome.predicates import Predicate
Expand All @@ -24,7 +25,7 @@

from authorityspoke.io import loaders, readers
from authorityspoke.io.fake_enactments import FakeClient
from authorityspoke.io.schemas_json import EnactmentSchema, RawFactor, RawHolding
from authorityspoke.io.schemas_json import RawFactor, RawHolding


load_dotenv()
Expand Down
3 changes: 2 additions & 1 deletion tests/test_codes.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@


from legislice.schemas import EnactmentSchema
from legislice.yaml_schemas import ExpandableEnactmentSchema

from authorityspoke.io import loaders
from authorityspoke.io.fake_enactments import FakeClient
Expand All @@ -25,7 +26,7 @@ class TestCodes:
def test_cfr_repr(self):
oracle_dictionary = loaders.load_holdings("holding_oracle.json")
regulation = oracle_dictionary[10]["enactments_despite"][1]
schema = EnactmentSchema()
schema = ExpandableEnactmentSchema()
enactment = schema.load(regulation)

assert enactment.level == "regulation"
Expand Down
20 changes: 0 additions & 20 deletions tests/test_enactments.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,26 +189,6 @@ def test_add_longer_plus_shorter(self, e_fourth_a, e_search_clause):
assert combined.selected_text() == e_fourth_a.selected_text()
assert combined.means(e_fourth_a)

def test_consolidate_enactments(self, make_response):

fourth_a = make_response["/us/const/amendment/IV"]["1791-12-15"]
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 = EnactmentSchema()

fourth = schema.load(fourth_a)
fourth.select_all()

search = schema.load(search_clause)
warrants = schema.load(warrants_clause)

consolidated = EnactmentGroup([fourth, search, warrants])
assert len(consolidated) == 1
assert consolidated[0].means(fourth)

def test_consolidate_adjacent_passages(self, make_response):
client = FakeClient(responses=make_response)
Expand Down

0 comments on commit 2e48e01

Please sign in to comment.