Skip to content

Commit

Permalink
Merge pull request #399 from roclark/fix-nfl-invalid-player-weight
Browse files Browse the repository at this point in the history
Handle missing player weights throwing errors
  • Loading branch information
roclark authored Apr 12, 2020
2 parents 32cc99f + 985e61d commit 15e70fb
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 0 deletions.
2 changes: 2 additions & 0 deletions sportsreference/mlb/roster.py
Original file line number Diff line number Diff line change
Expand Up @@ -746,6 +746,8 @@ def weight(self):
"""
Returns an ``int`` of the player's weight in pounds.
"""
if not self._weight:
return None
return int(self._weight.replace('lb', ''))

@property
Expand Down
2 changes: 2 additions & 0 deletions sportsreference/nba/roster.py
Original file line number Diff line number Diff line change
Expand Up @@ -720,6 +720,8 @@ def weight(self):
"""
Returns an ``int`` of the player's weight in pounds.
"""
if not self._weight:
return None
return int(self._weight.replace('lb', ''))

@property
Expand Down
2 changes: 2 additions & 0 deletions sportsreference/nfl/roster.py
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,8 @@ def weight(self):
"""
Returns an ``int`` of the player's weight in pounds.
"""
if not self._weight:
return None
return int(self._weight.replace('lb', ''))

@property
Expand Down
2 changes: 2 additions & 0 deletions sportsreference/nhl/roster.py
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,8 @@ def weight(self):
"""
Returns an ``int`` of the player's weight in pounds.
"""
if not self._weight:
return None
return int(self._weight.replace('lb', ''))

@_int_property_decorator
Expand Down
8 changes: 8 additions & 0 deletions tests/unit/test_mlb_roster.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,11 @@ def test_cleanup_of_none_returns_default_for_player(self):
result = _cleanup_player(None)

assert result == ''

@patch('requests.get', side_effect=mock_pyquery)
def test_missing_weight_returns_none(self, *args, **kwargs):
mock_weight = PropertyMock(return_value=None)
player = Player(None)
type(player)._weight = mock_weight

assert not player.weight
8 changes: 8 additions & 0 deletions tests/unit/test_nba_roster.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,14 @@ def test_empty_contract_is_none(self):

assert player._contract is None

@patch('requests.get', side_effect=mock_pyquery)
def test_missing_weight_returns_none(self, *args, **kwargs):
mock_weight = PropertyMock(return_value=None)
player = Player(None)
type(player)._weight = mock_weight

assert not player.weight


class TestInvalidNBAPlayer:
def test_no_player_data_returns_no_stats(self):
Expand Down
8 changes: 8 additions & 0 deletions tests/unit/test_nfl_roster.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,11 @@ def test_invalid_url_returns_none(self, *args, **kwargs):
result = player._retrieve_html_page()

assert result is None

@patch('requests.get', side_effect=mock_pyquery)
def test_missing_weight_returns_none(self, *args, **kwargs):
mock_weight = PropertyMock(return_value=None)
player = Player(None)
type(player)._weight = mock_weight

assert not player.weight
8 changes: 8 additions & 0 deletions tests/unit/test_nhl_roster.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,11 @@ def test_invalid_url_returns_none(self, *args, **kwargs):
result = player._retrieve_html_page()

assert result is None

@patch('requests.get', side_effect=mock_pyquery)
def test_missing_weight_returns_none(self, *args, **kwargs):
mock_weight = PropertyMock(return_value=None)
player = Player(None)
type(player)._weight = mock_weight

assert not player.weight

0 comments on commit 15e70fb

Please sign in to comment.