Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
dragon-dxw committed Sep 27, 2024
1 parent 10cdce9 commit 7c7eb84
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 14 deletions.
2 changes: 2 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ repos:
name: mypy-src
additional_dependencies:
- types-PyYAML
- ruamel.yaml
args:
- --strict
files: ^(src/ds_caselaw_utils|scripts)
Expand All @@ -53,6 +54,7 @@ repos:
- id: mypy
name: mypy-tests
files: ^src/ds_caselaw_utils/test_
exclude: courts_schema_types_autogenerated\.py

- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.29.2
Expand Down
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,6 @@ update_changelog_on_bump = true
[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"

[tool.mypy]
exclude = ["ds_caselaw_utils/courts_schema_types_autogenerated.py"]
19 changes: 14 additions & 5 deletions src/ds_caselaw_utils/courts.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,17 @@

import pathlib
from datetime import date
from typing import NewType, Optional
from typing import TYPE_CHECKING, NewType, Optional

if TYPE_CHECKING:
from courts_schema_types_autogenerated import ( # type: ignore[import-not-found]
RawCourt,
RawCourtRepositoryData,
RawJurisdiction,
)
else:
RawCourt = RawCourtRepositoryData = RawJurisdiction = None

from courts_schema_types_autogenerated import RawCourt, RawCourtRepositoryData, RawJurisdiction
from ruamel.yaml import YAML

CourtCode = NewType("CourtCode", str)
Expand All @@ -31,9 +39,10 @@ def __init__(self, data: RawCourt) -> None:
self.link: str = data["link"]
self.ncn: Optional[str] = data.get("ncn")
self.canonical_param: CourtParam = CourtParam(data.get("param"))
self.param_aliases: list[CourtParam] = [CourtParam(data.get("param"))] + (
[CourtParam(extra_param) for extra_param in data.get("extra_params")] or []
)
self.param_aliases: list[CourtParam] = [CourtParam(data.get("param"))] + [
CourtParam(extra_param) for extra_param in data.get("extra_params", [])
]

self.start_year: Optional[int] = data.get("start_year")
self.end_year: int = data.get("end_year") or date.today().year
self.jurisdictions: list[Jurisdiction] = [
Expand Down
20 changes: 11 additions & 9 deletions src/ds_caselaw_utils/test_courts.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
CourtWithJurisdiction,
courts,
)
from .factory import CourtFactory, make_court_repo_valid


def mock_with_properties(properties={}):
Expand Down Expand Up @@ -48,6 +49,7 @@ def test_loads_all_courts_with_jurisdictions(self):
"courts": [{"name": "court1", "jurisdictions": [{"name": "jurisdiction1"}]}],
}
]
data = make_court_repo_valid(data)
repo = CourtsRepository(data)
courts = repo.get_all(with_jurisdictions=True)
self.assertIn("court1", [c.name for c in courts])
Expand Down Expand Up @@ -318,43 +320,43 @@ def test_returns_grouped_selectable_tribunals(self):

class TestCourt(unittest.TestCase):
def test_repr_string(self):
court = Court({"name": "court_name"})
court = CourtFactory({"name": "court_name"})
self.assertEqual("court_name", str(court))
self.assertEqual("court_name", repr(court))

def test_grouped_name_explicit(self):
court = Court({"grouped_name": "court_name"})
court = CourtFactory({"grouped_name": "court_name"})
self.assertEqual("court_name", court.grouped_name)

def test_grouped_name_default(self):
court = Court({"name": "court_name"})
court = CourtFactory({"name": "court_name"})
self.assertEqual("court_name", court.grouped_name)

def test_param_aliases(self):
court = Court({"param": "param_1", "extra_params": ["param_2"]})
court = CourtFactory({"param": "param_1", "extra_params": ["param_2"]})
self.assertEqual(["param_1", "param_2"], court.param_aliases)

def test_end_year_explicit(self):
court = Court({"end_year": 1983})
court = CourtFactory({"end_year": 1983})
self.assertEqual(1983, court.end_year)

def test_end_year_default(self):
court = Court({})
court = CourtFactory({})
self.assertEqual(date.today().year, court.end_year)

def test_get_jurisdiction(self):
court = Court({"jurisdictions": [{"code": "jurisdiction1", "name": "Jurisdiction 1"}]})
court = CourtFactory({"jurisdictions": [{"code": "jurisdiction1", "name": "Jurisdiction 1"}]})
jurisdiction = court.get_jurisdiction("jurisdiction1")
assert jurisdiction
self.assertEqual("Jurisdiction 1", jurisdiction.name)

def test_get_nonexistent_jurisdiction(self):
court = Court({"jurisdictions": [{"code": "jurisdiction1", "name": "Jurisdiction 1"}]})
court = CourtFactory({"jurisdictions": [{"code": "jurisdiction1", "name": "Jurisdiction 1"}]})
jurisdiction = court.get_jurisdiction("jurisdiction2")
self.assertIsNone(jurisdiction)

def test_expand_jurisdictions(self):
court = Court(
court = CourtFactory(
{
"name": "Court 1",
"jurisdictions": [{"code": "jurisdiction1", "name": "Jurisdiction 1"}],
Expand Down

0 comments on commit 7c7eb84

Please sign in to comment.