Skip to content

Commit

Permalink
test_util: Add test for get_launcher_from_installdir (DavidoTek#435)
Browse files Browse the repository at this point in the history
* test_util: Add test for get_launcher_from_installdir

* removed commented line

* correct comment
  • Loading branch information
sonic2kk authored Jul 31, 2024
1 parent ec20c1f commit f2573d5
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 2 deletions.
1 change: 1 addition & 0 deletions pupgui2/datastructures.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,3 +233,4 @@ class Launcher(Enum):
LUTRIS = 2
BOTTLES = 3
HEROIC = 4
WINEZGUI = 5
4 changes: 3 additions & 1 deletion pupgui2/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -847,14 +847,16 @@ def get_launcher_from_installdir(install_dir: str) -> Launcher:
Return Type: Launcher (Enum)
"""

if 'steam/compatibilitytools.d' in install_dir.lower():
if any(steam_path in install_dir.lower() for steam_path in ['steam/compatibilitytools.d', 'steam/root/compatibilitytools.d']):
return Launcher.STEAM
elif 'lutris/runners' in install_dir.lower():
return Launcher.LUTRIS
elif 'heroic/tools' in install_dir.lower():
return Launcher.HEROIC
elif 'bottles/runners' in install_dir.lower():
return Launcher.BOTTLES
elif 'winezgui/runners' in install_dir.lower():
return Launcher.WINEZGUI
else:
return Launcher.UNKNOWN

Expand Down
5 changes: 5 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
[build-system]
requires = ["setuptools>=42"]
build-backend = "setuptools.build_meta"

[tool.pytest.ini_options]
pythonpath = [
"."
]
37 changes: 36 additions & 1 deletion tests/test_util.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,41 @@
from pupgui2.util import *

from pupgui2.datastructures import SteamApp, LutrisGame, HeroicGame
from pupgui2.constants import POSSIBLE_INSTALL_LOCATIONS
from pupgui2.datastructures import SteamApp, LutrisGame, HeroicGame, Launcher


def test_get_launcher_from_installdir() -> None:

"""
Test whether get_laucher_from_installdir returns the correct Launcher type Enum from the installdir path.
"""

# All possible Steam paths
steam_install_paths: list[str] = [ install_location['install_dir'] for install_location in POSSIBLE_INSTALL_LOCATIONS if install_location['launcher'] == 'steam' ]
steam_install_path_tests: list[Launcher] = [ get_launcher_from_installdir(steam_path) for steam_path in steam_install_paths ]

# All possible Lutris paths
lutris_install_paths: list[str] = [ install_location['install_dir'] for install_location in POSSIBLE_INSTALL_LOCATIONS if install_location['launcher'] == 'lutris' ]
lutris_install_path_tests: list[Launcher] = [ get_launcher_from_installdir(lutris_path) for lutris_path in lutris_install_paths ]

# All possible Heroic paths
heroic_install_paths: list[str] = [ install_location['install_dir'] for install_location in POSSIBLE_INSTALL_LOCATIONS if install_location['launcher'] in ['heroicwine', 'heroicproton'] ]
heroic_install_path_tests: list[Launcher] = [ get_launcher_from_installdir(heroic_path) for heroic_path in heroic_install_paths ]

# All possible Bottles paths
bottles_install_paths: list[str] = [ install_location['install_dir'] for install_location in POSSIBLE_INSTALL_LOCATIONS if install_location['launcher'] == 'bottles' ]
bottles_install_path_tests: list[Launcher] = [ get_launcher_from_installdir(bottles_path) for bottles_path in bottles_install_paths ]

# All possible WineZGUI paths
winezgui_install_paths: list[str] = [ install_location['install_dir'] for install_location in POSSIBLE_INSTALL_LOCATIONS if install_location['launcher'] == 'winezgui' ]
winezgui_install_path_tests: list[Launcher] = [ get_launcher_from_installdir(winezgui_path) for winezgui_path in winezgui_install_paths ]


assert all(launcher == Launcher.STEAM for launcher in steam_install_path_tests)
assert all(launcher == Launcher.LUTRIS for launcher in lutris_install_path_tests)
assert all(launcher == Launcher.HEROIC for launcher in heroic_install_path_tests)
assert all(launcher == Launcher.BOTTLES for launcher in bottles_install_path_tests)
assert all(launcher == Launcher.WINEZGUI for launcher in winezgui_install_path_tests)


def test_get_random_game_name() -> None:
Expand Down

0 comments on commit f2573d5

Please sign in to comment.