Skip to content

Commit

Permalink
test_util: Improve type hints for test_get_random_game_name (#434)
Browse files Browse the repository at this point in the history
  • Loading branch information
sonic2kk authored Jul 31, 2024
1 parent cb0cd82 commit ec20c1f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
6 changes: 3 additions & 3 deletions pupgui2/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -885,14 +885,14 @@ def create_missing_dependencies_message(ct_name: str, dependencies: List[str]) -
return tr_msg, False


def get_random_game_name(games: List[Union[SteamApp, LutrisGame, HeroicGame]]) -> str:
def get_random_game_name(games: list[SteamApp] | list[LutrisGame] | list[HeroicGame]) -> str:
""" Return a random game name from list of SteamApp, LutrisGame, or HeroicGame """

if len(games) <= 0:
return ''

tooltip_game_name = ''
random_game = random.choice(games)
tooltip_game_name: str = ''
random_game: SteamApp | LutrisGame | HeroicGame = random.choice(games)
if type(random_game) is SteamApp:
tooltip_game_name = random_game.game_name
elif type(random_game) is LutrisGame:
Expand Down
14 changes: 8 additions & 6 deletions tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
from pupgui2.datastructures import SteamApp, LutrisGame, HeroicGame


def test_get_random_game_name():
""" test whether get_random_game_name returns a valid game name """
names = ["game", "A super cool game", "A game with a very long name that is very long", "0123456789"]
def test_get_random_game_name() -> None:

steam_app = [SteamApp() for _ in range(len(names))]
lutris_game = [LutrisGame() for _ in range(len(names))]
heroic_game = [HeroicGame() for _ in range(len(names))]
""" Test whether get_random_game_name returns a valid game name for each launcher game type. """

names: list[str] = ["game", "A super cool game", "A game with a very long name that is very long", "0123456789"]

steam_app: list[SteamApp] = [SteamApp() for _ in range(len(names))]
lutris_game: list[LutrisGame] = [LutrisGame() for _ in range(len(names))]
heroic_game: list[HeroicGame] = [HeroicGame() for _ in range(len(names))]

for i, name in enumerate(names):
steam_app[i].game_name = name
Expand Down

0 comments on commit ec20c1f

Please sign in to comment.