refactor: flatten app/scoreboard/ subpackage and rename files for clarity
This commit is contained in:
103
tests/test_games.py
Normal file
103
tests/test_games.py
Normal file
@@ -0,0 +1,103 @@
|
||||
from tests.conftest import make_game
|
||||
from app.games import (
|
||||
convert_game_state,
|
||||
get_game_outcome,
|
||||
process_period,
|
||||
process_record,
|
||||
process_start_time,
|
||||
process_time_remaining,
|
||||
utc_to_est_time,
|
||||
)
|
||||
|
||||
|
||||
class TestConvertGameState:
|
||||
def test_off_maps_to_final(self):
|
||||
assert convert_game_state("OFF") == "FINAL"
|
||||
|
||||
def test_crit_maps_to_live(self):
|
||||
assert convert_game_state("CRIT") == "LIVE"
|
||||
|
||||
def test_fut_maps_to_pre(self):
|
||||
assert convert_game_state("FUT") == "PRE"
|
||||
|
||||
def test_unknown_state_passes_through(self):
|
||||
assert convert_game_state("LIVE") == "LIVE"
|
||||
|
||||
|
||||
class TestProcessRecord:
|
||||
def test_na_returns_na(self):
|
||||
assert process_record("N/A") == "N/A"
|
||||
|
||||
def test_pads_single_digit_parts(self):
|
||||
assert process_record("5-3-1") == "05-03-01"
|
||||
|
||||
def test_already_padded_unchanged(self):
|
||||
assert process_record("40-25-10") == "40-25-10"
|
||||
|
||||
|
||||
class TestProcessPeriod:
|
||||
def test_pre_game_returns_zero(self):
|
||||
game = make_game(game_state="PRE")
|
||||
assert process_period(game) == 0
|
||||
|
||||
def test_fut_game_returns_zero(self):
|
||||
game = make_game(game_state="FUT")
|
||||
assert process_period(game) == 0
|
||||
|
||||
def test_final_game_returns_na(self):
|
||||
game = make_game(game_state="OFF")
|
||||
assert process_period(game) == "N/A"
|
||||
|
||||
def test_live_game_returns_period_number(self):
|
||||
game = make_game(game_state="LIVE", period=2)
|
||||
assert process_period(game) == 2
|
||||
|
||||
|
||||
class TestProcessTimeRemaining:
|
||||
def test_pre_game_returns_2000(self):
|
||||
game = make_game(game_state="FUT")
|
||||
assert process_time_remaining(game) == "20:00"
|
||||
|
||||
def test_final_game_returns_0000(self):
|
||||
game = make_game(game_state="OFF")
|
||||
assert process_time_remaining(game) == "00:00"
|
||||
|
||||
def test_live_game_returns_clock(self):
|
||||
game = make_game(game_state="LIVE", seconds_remaining=305)
|
||||
assert process_time_remaining(game) == "05:05"
|
||||
|
||||
def test_live_game_at_zero_returns_end(self):
|
||||
game = make_game(game_state="LIVE", seconds_remaining=0)
|
||||
assert process_time_remaining(game) == "END"
|
||||
|
||||
|
||||
class TestProcessStartTime:
|
||||
def test_pre_game_returns_est_time(self):
|
||||
game = make_game(game_state="FUT", start_time_utc="2024-04-10T23:00:00Z")
|
||||
result = process_start_time(game)
|
||||
assert result == "7:00 PM"
|
||||
|
||||
def test_pre_game_strips_leading_zero(self):
|
||||
game = make_game(game_state="FUT", start_time_utc="2024-04-10T22:00:00Z")
|
||||
result = process_start_time(game)
|
||||
assert not result.startswith("0")
|
||||
|
||||
def test_live_game_returns_na(self):
|
||||
game = make_game(game_state="LIVE")
|
||||
assert process_start_time(game) == "N/A"
|
||||
|
||||
|
||||
class TestGetGameOutcome:
|
||||
def test_final_game_returns_last_period_type(self):
|
||||
game = make_game(game_state="OFF")
|
||||
assert get_game_outcome(game, "FINAL") == "REG"
|
||||
|
||||
def test_live_game_returns_na(self):
|
||||
game = make_game(game_state="LIVE")
|
||||
assert get_game_outcome(game, "LIVE") == "N/A"
|
||||
|
||||
|
||||
class TestUtcToEstTime:
|
||||
def test_converts_utc_to_est(self):
|
||||
result = utc_to_est_time("2024-04-10T23:00:00Z")
|
||||
assert result == "07:00 PM"
|
||||
Reference in New Issue
Block a user