Skip to content

Commit

Permalink
Fix types
Browse files Browse the repository at this point in the history
  • Loading branch information
dragon-dxw committed Sep 27, 2024
1 parent 8f266bd commit ed283c2
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 48 deletions.
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,5 @@ update_changelog_on_bump = true
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"

[tool.mypy]
exclude = ["ds_caselaw_utils/courts_schema_types_autogenerated.py"]
# [tool.mypy]
# exclude = ["ds_caselaw_utils/courts_schema_types_autogenerated.py"]
34 changes: 18 additions & 16 deletions src/ds_caselaw_utils/courts_schema_types_autogenerated.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,24 @@ class RawCourt(TypedDict, total=False):
jurisdictions: List["RawJurisdiction"]


RawCourtRepository = List["_RawCourtListItem"]
class RawCourtGroup(TypedDict, total=False):
""" Raw Court Group. """

name: Required[str]
""" Required property """

display_name: Required[Union[str, None]]
""" Required property """

is_tribunal: Required[bool]
""" Required property """

courts: Required[List["RawCourt"]]
""" Required property """



RawCourtRepository = List["RawCourtGroup"]
"""
Raw Court List.
Expand All @@ -70,18 +87,3 @@ class RawJurisdiction(TypedDict, total=False):
_RawCourtExtraParamsItem = str
""" pattern: ^[a-z]{2,}(/[a-z]+)?$ """



class _RawCourtListItem(TypedDict, total=False):
name: Required[str]
""" Required property """

display_name: Required[Union[str, None]]
""" Required property """

is_tribunal: Required[bool]
""" Required property """

courts: Required[List["RawCourt"]]
""" Required property """

1 change: 1 addition & 0 deletions src/ds_caselaw_utils/data/schema/courts.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"type": "array",
"items": {
"type": "object",
"title": "Raw Court Group",
"properties": {
"name": {
"type": "string"
Expand Down
6 changes: 4 additions & 2 deletions src/ds_caselaw_utils/factory.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import typing

from .courts import Court
from .courts_schema_types_autogenerated import RawCourt, RawCourtRepository

Expand All @@ -15,7 +17,7 @@ def make_court_valid(data) -> RawCourt:
for keyword in ["selectable", "listable"]:
if keyword not in data:
data[keyword] = True
return data
return typing.cast(RawCourt, data)


def make_court_repo_valid(data) -> RawCourtRepository:
Expand All @@ -26,4 +28,4 @@ def make_court_repo_valid(data) -> RawCourtRepository:
new_courts.append(make_court_valid(court))
court_group["court"] = new_courts
new_court_groups.append(court_group)
return new_court_groups
return RawCourtRepository(new_court_groups)
57 changes: 29 additions & 28 deletions src/ds_caselaw_utils/test_courts.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from ruamel.yaml import YAML

from ds_caselaw_utils.courts_schema_types_autogenerated import RawCourtRepository
from ds_caselaw_utils.factory import CourtFactory, make_court_repo_valid

from .courts import (
Expand Down Expand Up @@ -37,8 +38,8 @@ def test_loads_all_courts_without_jurisdictions(self):
"courts": [{"name": "court1", "jurisdictions": [{"name": "jurisdiction1", "code": "code"}]}],
}
]
data = make_court_repo_valid(data)
repo = CourtsRepository(data)
valid_data: RawCourtRepository = make_court_repo_valid(data)
repo = CourtsRepository(valid_data)
courts = repo.get_all()
self.assertIn("court1", [c.name for c in courts])
self.assertNotIn("court1 – jurisdiction1", [c.name for c in courts])
Expand All @@ -51,8 +52,8 @@ def test_loads_all_courts_with_jurisdictions(self):
"courts": [{"name": "court1", "jurisdictions": [{"name": "jurisdiction1", "code": "code"}]}],
}
]
data = make_court_repo_valid(data)
repo = CourtsRepository(data)
valid_data = make_court_repo_valid(data)
repo = CourtsRepository(valid_data)
courts = repo.get_all(with_jurisdictions=True)
self.assertIn("court1", [c.name for c in courts])
self.assertIn("court1 – jurisdiction1", [c.name for c in courts])
Expand All @@ -76,8 +77,8 @@ def test_loads_selectable_courts(self):
"courts": [{"name": "court3", "selectable": False}],
},
]
data = make_court_repo_valid(data)
repo = CourtsRepository(data)
valid_data = make_court_repo_valid(data)
repo = CourtsRepository(valid_data)
selectable = repo.get_selectable()
self.assertIn("court1", [c.name for c in selectable])
self.assertNotIn("court2", [c.name for c in selectable])
Expand Down Expand Up @@ -107,8 +108,8 @@ def test_loads_listable_courts(self):
"courts": [{"name": "court3", "listable": False}],
},
]
data = make_court_repo_valid(data)
repo = CourtsRepository(data)
valid_data = make_court_repo_valid(data)
repo = CourtsRepository(valid_data)
groups = repo.get_listable_groups()
self.assertIn("court group 1", [g.name for g in groups])
self.assertNotIn("court group 2", [g.name for g in groups])
Expand All @@ -127,8 +128,8 @@ def test_loads_court_by_param(self):
"courts": [{"param": "court2", "name": "Court 2"}],
},
]
data = make_court_repo_valid(data)
repo = CourtsRepository(data)
valid_data = make_court_repo_valid(data)
repo = CourtsRepository(valid_data)
self.assertEqual("Court 2", repo.get_by_param(CourtParam("court2")).name)

def test_raises_on_unknown_court_param(self):
Expand All @@ -142,8 +143,8 @@ def test_raises_on_unknown_court_param(self):
"courts": [{"param": "court2", "name": "Court 2"}],
},
]
data = make_court_repo_valid(data)
repo = CourtsRepository(data)
valid_data = make_court_repo_valid(data)
repo = CourtsRepository(valid_data)
self.assertRaises(CourtNotFoundException, repo.get_by_param, "court3")

def test_loads_court_by_code(self):
Expand All @@ -157,8 +158,8 @@ def test_loads_court_by_code(self):
"courts": [{"code": "court2", "name": "Court 2"}],
},
]
data = make_court_repo_valid(data)
repo = CourtsRepository(data)
valid_data = make_court_repo_valid(data)
repo = CourtsRepository(valid_data)
self.assertEqual("Court 2", repo.get_by_code(CourtCode("court2")).name)

def test_loads_court_with_jurisdiction_by_code(self):
Expand All @@ -174,8 +175,8 @@ def test_loads_court_with_jurisdiction_by_code(self):
],
}
]
data = make_court_repo_valid(data)
repo = CourtsRepository(data)
valid_data = make_court_repo_valid(data)
repo = CourtsRepository(valid_data)
self.assertEqual("Court 1 – Jurisdiction 1", repo.get_by_code(CourtCode("court1/jurisdiction1")).name)

def test_raises_error_for_nonexistent_jurisdictions(self):
Expand All @@ -191,8 +192,8 @@ def test_raises_error_for_nonexistent_jurisdictions(self):
],
}
]
data = make_court_repo_valid(data)
repo = CourtsRepository(data)
valid_data = make_court_repo_valid(data)
repo = CourtsRepository(valid_data)
self.assertRaises(CourtNotFoundException, repo.get_by_code, "court1/jurisdiction2")
self.assertRaises(CourtNotFoundException, repo.get_by_code, "court2/jurisdiction1")

Expand All @@ -207,8 +208,8 @@ def test_raises_on_unknown_court_code(self):
"courts": [{"code": "court2", "name": "Court 2"}],
},
]
data = make_court_repo_valid(data)
repo = CourtsRepository(data)
valid_data = make_court_repo_valid(data)
repo = CourtsRepository(valid_data)
self.assertRaises(CourtNotFoundException, repo.get_by_code, "court3")

def test_returns_listable_courts(self):
Expand All @@ -227,8 +228,8 @@ def test_returns_listable_courts(self):
"courts": [{"param": "court3", "listable": True, "name": "Court 3"}],
},
]
data = make_court_repo_valid(data)
repo = CourtsRepository(data)
valid_data = make_court_repo_valid(data)
repo = CourtsRepository(valid_data)
self.assertIn("court1", [c.canonical_param for c in repo.get_listable_courts()])
self.assertNotIn("court2", [c.canonical_param for c in repo.get_listable_courts()])
self.assertNotIn("court3", [c.canonical_param for c in repo.get_listable_courts()])
Expand All @@ -251,8 +252,8 @@ def test_returns_listable_tribunals(self):
],
},
]
data = make_court_repo_valid(data)
repo = CourtsRepository(data)
valid_data = make_court_repo_valid(data)
repo = CourtsRepository(valid_data)
self.assertNotIn("court1", [c.canonical_param for c in repo.get_listable_tribunals()])
self.assertNotIn("court2", [c.canonical_param for c in repo.get_listable_tribunals()])
self.assertIn("court3", [c.canonical_param for c in repo.get_listable_tribunals()])
Expand Down Expand Up @@ -285,8 +286,8 @@ def test_returns_grouped_selectable_courts(self):
],
},
]
data = make_court_repo_valid(data)
repo = CourtsRepository(data)
valid_data = make_court_repo_valid(data)
repo = CourtsRepository(valid_data)
groups = repo.get_grouped_selectable_courts()
self.assertIn("Court group", [g.name for g in groups])
self.assertNotIn("Tribunal group", [g.name for g in groups])
Expand Down Expand Up @@ -322,8 +323,8 @@ def test_returns_grouped_selectable_tribunals(self):
],
},
]
data = make_court_repo_valid(data)
repo = CourtsRepository(data)
valid_data = make_court_repo_valid(data)
repo = CourtsRepository(valid_data)
groups = repo.get_grouped_selectable_tribunals()
self.assertIn("Tribunal group", [g.name for g in groups])
self.assertNotIn("Court group", [g.name for g in groups])
Expand Down

0 comments on commit ed283c2

Please sign in to comment.