Skip to content

Commit

Permalink
Updates package resource loading to use files() instead of soon-to-be…
Browse files Browse the repository at this point in the history
…-deprecated open_text()
  • Loading branch information
coreyjs committed Nov 26, 2023
1 parent fe55827 commit 11a0a01
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
2 changes: 1 addition & 1 deletion nhlpy/_version.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Should this be driven by the main pyproject.toml file? yes, is it super convoluted? yes, can it wait? sure

__version__ = "2.1.3"
__version__ = "2.1.4"
8 changes: 6 additions & 2 deletions nhlpy/api/teams.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,12 @@ def teams_info(self) -> dict:
:return: dict
"""

with importlib.resources.open_text("nhlpy.data", "teams_20232024.json") as f:
return json.load(f)
# with importlib.resources.files("nhlpy.data", "teams_20232024.json") as f:
# return json.load(f)['teams']

data_resource = importlib.resources.files("nhlpy") / "data"
teams_info = json.loads((data_resource / "teams_20232024.json").read_text())["teams"]
return teams_info

def roster(self, team_abbr: str, season: str) -> dict:
"""
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api"

[tool.poetry]
name = "nhl-api-py"
version = "2.1.3"
version = "2.1.4"
description = "NHL API. For standings, team stats, outcomes, player information. Contains each individual API endpoint as well as convience methods for easy data loading in Pandas or any ML applications."
authors = ["Corey Schaf <[email protected]>"]
readme = "README.md"
Expand Down
12 changes: 12 additions & 0 deletions tests/test_teams.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,15 @@ def test_stats_summary(h_m, nhl_client):
nhl_client.teams.team_stats_summary()
h_m.assert_called_once()
assert h_m.call_args[1]["url"] == "https://api.nhle.com/stats/rest/en/team/summary"


@mock.patch("httpx.get")
def test_roster(h_m, nhl_client):
nhl_client.teams.roster(team_abbr="BUF", season="20202021")
h_m.assert_called_once()
assert h_m.call_args[1]["url"] == "https://api-web.nhle.com/v1/roster/BUF/20202021"


def test_teams_info(nhl_client):
teams = nhl_client.teams.teams_info()
assert len(teams) == 32

0 comments on commit 11a0a01

Please sign in to comment.