Skip to content

Commit

Permalink
Merge pull request #198 from nationalarchives/add-repr-to-court-objects
Browse files Browse the repository at this point in the history
Add repr to multicourt objects
  • Loading branch information
jacksonj04 authored Oct 28, 2024
2 parents 754ba3e + d27c817 commit 2bef929
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/ds_caselaw_utils/courts.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ def display_heading(self) -> bool:
"""Is this group displayed in the PUI?"""
return self.name is not None

def __repr__(self) -> str:
return f"CourtGroup({self.name!r}, {self.courts!r})"


class CourtNotFoundException(Exception):
pass
Expand All @@ -137,6 +140,9 @@ def __init__(self, data: RawCourtRepository):
self._byParam[CourtParam(courtData["param"])] = court
self._byCode[CourtCode(courtData["code"])] = court

def __repr__(self) -> str:
return f"CourtsRepository({self._data!r})"

def get_by_param(self, param: CourtParam) -> Court:
try:
return self._byParam[param]
Expand Down
19 changes: 19 additions & 0 deletions src/ds_caselaw_utils/test_courts.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,21 @@ def test_returns_grouped_selectable_tribunals(self):
self.assertNotIn("Unselectable tribunal", [c.name for g in groups for c in g.courts])
self.assertNotIn("Selectable court", [c.name for g in groups for c in g.courts])

def test_repr(self):
data = [
{
"name": "group1",
"display_name": "Court group",
"is_tribunal": False,
"courts": [
{"param": "court1", "selectable": True, "name": "Selectable court"},
],
}
]
valid_data = make_court_repo_valid(data)
repo = CourtsRepository(valid_data)
assert "'name': 'group1', 'display_name': 'Court group'" in str(repo)


class TestCourt(unittest.TestCase):
def test_repr_string(self):
Expand Down Expand Up @@ -478,6 +493,10 @@ def test_dont_display_heading_when_no_display_name(self):
group = CourtGroup(None, [])
assert not group.display_heading

def test_repr(self):
group = CourtGroup("name", [])
assert str(group) == "CourtGroup('name', [])"


class TestCourts(unittest.TestCase):
def test_loads_court_yaml(self):
Expand Down

0 comments on commit 2bef929

Please sign in to comment.