Skip to content

Commit

Permalink
Add tests and code cleanup - No functionality change (#169)
Browse files Browse the repository at this point in the history
* No functionality change
  • Loading branch information
vasqued2 authored Aug 3, 2024
1 parent a6d29b0 commit d6b4671
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 48 deletions.
5 changes: 1 addition & 4 deletions custom_components/teamtracker/set_cricket.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@ async def async_set_cricket_values(
) -> bool:
"""Set cricket specific values"""

if team_index == 0:
oppo_index = 1
else:
oppo_index = 0
oppo_index = 1 - team_index
competition = await async_get_value(event, "competitions", competition_index)
competitor = await async_get_value(competition, "competitors", team_index)
opponent = await async_get_value(competition, "competitors", oppo_index)
Expand Down
5 changes: 1 addition & 4 deletions custom_components/teamtracker/set_golf.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@ async def async_set_golf_values(
) -> bool:
"""Set golf specific values"""

if team_index == 0:
oppo_index = 1
else:
oppo_index = 0
oppo_index = 1 if team_index == 0 else 0
competition = await async_get_value(event, "competitions", competition_index)
competitor = await async_get_value(competition, "competitors", team_index)
opponent = await async_get_value(competition, "competitors", oppo_index)
Expand Down
5 changes: 1 addition & 4 deletions custom_components/teamtracker/set_hockey.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@ async def async_set_hockey_values(
) -> bool:
"""Set hockey specific values"""

if team_index == 0:
oppo_index = 1
else:
oppo_index = 0
oppo_index = 1 - team_index
competition = await async_get_value(event, "competitions", competition_index)
competitor = await async_get_value(competition, "competitors", team_index)
opponent = await async_get_value(competition, "competitors", oppo_index)
Expand Down
5 changes: 1 addition & 4 deletions custom_components/teamtracker/set_mma.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ async def async_set_mma_values(

_LOGGER.debug("%s: async_set_mma_values() 1: %s", sensor_name, sensor_name)

if team_index == 0:
oppo_index = 1
else:
oppo_index = 0
oppo_index = 1 - team_index
competition = await async_get_value(event, "competitions", competition_index)
competitor = await async_get_value(competition, "competitors", team_index)
opponent = await async_get_value(competition, "competitors", oppo_index)
Expand Down
5 changes: 1 addition & 4 deletions custom_components/teamtracker/set_racing.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@ async def async_set_racing_values(

# _LOGGER.debug("%s: async_set_racing_values() 0: %s", sensor_name, new_values)

if team_index == 0:
oppo_index = 1
else:
oppo_index = 0
oppo_index = 1 if team_index == 0 else 0
competition = await async_get_value(event, "competitions", competition_index)
competitor = await async_get_value(competition, "competitors", team_index)
opponent = await async_get_value(competition, "competitors", oppo_index)
Expand Down
5 changes: 1 addition & 4 deletions custom_components/teamtracker/set_soccer.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ async def async_set_soccer_values(
teamPP = None
oppoPP = None

if team_index == 0:
oppo_index = 1
else:
oppo_index = 0
oppo_index = 1 - team_index
competition = await async_get_value(event, "competitions", competition_index)
competitor = await async_get_value(competition, "competitors", team_index)
opponent = await async_get_value(competition, "competitors", oppo_index)
Expand Down
5 changes: 1 addition & 4 deletions custom_components/teamtracker/set_tennis.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ async def async_set_tennis_values(

# _LOGGER.debug("%s: async_set_tennis_values() 0: %s %s %s", sensor_name, sensor_name, grouping_index, competition_index)

if team_index == 0:
oppo_index = 1
else:
oppo_index = 0
oppo_index = 1 - team_index

grouping = await async_get_value(event, "groupings", grouping_index)
if grouping is None:
Expand Down
20 changes: 4 additions & 16 deletions custom_components/teamtracker/set_values.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,7 @@ async def async_set_values(

# _LOGGER.debug("%s: async_set_values() 1: %s", sensor_name, sensor_name)

if team_index == 0:
oppo_index = 1
else:
oppo_index = 0
oppo_index = 1 if team_index == 0 else 0
grouping = await async_get_value(event, "groupings", grouping_index)
if grouping is None:
competition = await async_get_value(event, "competitions", competition_index)
Expand Down Expand Up @@ -180,10 +177,7 @@ async def async_set_universal_values(

# _LOGGER.debug("%s: async_set_universal_values() 1: %s", sensor_name, sensor_name)

if team_index == 0:
oppo_index = 1
else:
oppo_index = 0
oppo_index = 1 if team_index == 0 else 0
grouping = await async_get_value(event, "groupings", grouping_index)
if grouping is None:
competition = await async_get_value(event, "competitions", competition_index)
Expand Down Expand Up @@ -397,10 +391,7 @@ async def async_set_team_values(

# _LOGGER.debug("%s: async_set_team_values() 1: %s", sensor_name, sensor_name)

if team_index == 0:
oppo_index = 1
else:
oppo_index = 0
oppo_index = 1 if team_index == 0 else 0
grouping = await async_get_value(event, "groupings", grouping_index)
if grouping is None:
competition = await async_get_value(event, "competitions", competition_index)
Expand Down Expand Up @@ -479,10 +470,7 @@ async def async_set_in_values(

# _LOGGER.debug("%s: async_set_in_values() 1: %s", sensor_name, sensor_name)

if team_index == 0:
oppo_index = 1
else:
oppo_index = 0
oppo_index = 1 if team_index == 0 else 0

grouping = await async_get_value(event, "groupings", grouping_index)
if grouping is None:
Expand Down
5 changes: 1 addition & 4 deletions custom_components/teamtracker/set_volleyball.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@ async def async_set_volleyball_values(
) -> bool:
"""Set volleyball specific values"""

if team_index == 0:
oppo_index = 1
else:
oppo_index = 0
oppo_index = 1 - team_index
competition = await async_get_value(event, "competitions", competition_index)
competitor = await async_get_value(competition, "competitors", team_index)
opponent = await async_get_value(competition, "competitors", oppo_index)
Expand Down
44 changes: 44 additions & 0 deletions tests/test_error_conditions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
"""Test NFL Sensor"""
import logging

from custom_components.teamtracker.set_cricket import async_set_cricket_values
from custom_components.teamtracker.set_golf import async_set_golf_values
from custom_components.teamtracker.set_hockey import async_set_hockey_values
from custom_components.teamtracker.set_mma import async_set_mma_values
from custom_components.teamtracker.set_racing import async_set_racing_values
from custom_components.teamtracker.set_soccer import async_set_soccer_values
from custom_components.teamtracker.set_tennis import async_set_tennis_values
from custom_components.teamtracker.set_volleyball import async_set_volleyball_values
from custom_components.teamtracker.set_values import async_set_values, async_set_universal_values, async_set_team_values, async_set_in_values

_LOGGER = logging.getLogger(__name__)


async def test_error_conditions(hass):
""" Use file w/ test json and loop through test cases and compare to expected results """

rc = await async_set_cricket_values({}, {}, 0, 0, "en", "sensor_name")
assert rc is False
rc = await async_set_golf_values({}, {}, 0, 0, "en", "sensor_name")
assert rc is False
rc = await async_set_hockey_values({}, {}, 0, 0, "sensor_name")
assert rc is False
rc = await async_set_mma_values({}, {}, 0, 0, "en", "sensor_name")
assert rc is False
rc = await async_set_racing_values({}, {}, 0, 0, "en", "sensor_name")
assert rc is False
rc = await async_set_soccer_values({}, {}, 0, 0, "sensor_name")
assert rc is False
rc = await async_set_tennis_values({}, {}, 0, 0, 0, "en", "sensor_name")
assert rc is False
rc = await async_set_volleyball_values({}, {}, 0, 0, "sensor_name")
assert rc is False

rc = await async_set_values({}, {}, 0, 0, 0, "en", "sensor_name")
assert rc is False
rc = await async_set_universal_values({}, {}, 0, 0, 0, "en", "sensor_name")
assert rc is False
rc = await async_set_team_values({}, {}, 0, 0, 0, "en", "sensor_name")
assert rc is False
rc = await async_set_in_values({}, {}, 0, 0, 0, "sensor_name")
assert rc is False

0 comments on commit d6b4671

Please sign in to comment.