Skip to content

Commit

Permalink
Tests and changelos
Browse files Browse the repository at this point in the history
  • Loading branch information
GB609 committed Dec 22, 2024
1 parent 3136118 commit 00759e4
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 33 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
**1.3.2**
- Completely reworked windows wine installation. This should solve a lot of problems with failing game installs (thanks to GB609)
- Completely reworked windows wine installation. This should solve a lot of problems with failing game installs. Innoextract (if installed) is only used to detect and configure the installation language. (thanks to GB609)
- Variables and arguments in game settings can now contain blanks when quoted shell-style (thanks to GB609)
- Minigalaxy will now create working Desktop Shortcuts for wine games (thanks to GB609)

Expand Down
9 changes: 5 additions & 4 deletions minigalaxy/installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import re

from minigalaxy.config import Config
from minigalaxy.constants import SUPPORTED_DOWNLOAD_LANGUAGES, GAME_LANGUAGE_IDS
from minigalaxy.constants import GAME_LANGUAGE_IDS
from minigalaxy.game import Game
from minigalaxy.logger import logger
from minigalaxy.translation import _
Expand Down Expand Up @@ -53,8 +53,7 @@ def install_game( # noqa: C901
language: str,
install_dir: str,
keep_installers: bool,
create_desktop_file: bool,
use_innoextract: bool = True, # not set externally as of yet
create_desktop_file: bool
):
error_message = ""
tmp_dir = ""
Expand Down Expand Up @@ -415,7 +414,9 @@ def match_game_lang_to_installer(installer: str, language: str, outputLogFile=No
return "en-US"

lang_keys = GAME_LANGUAGE_IDS.get(language, [])
lang_name_regex = re.compile(f'(\\w+)\\s*:\\s*.*')
# match lines like ' - french : French'
# gets the first lowercase word which is the key
lang_name_regex = re.compile('(\\w+)\\s*:\\s*.*')

if outputLogFile is not None:
logger.info('write setup language data: ', outputLogFile)
Expand Down
51 changes: 23 additions & 28 deletions tests/test_installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,21 +86,6 @@ def test2_extract_installer(self, mock_subprocess, mock_listdir, mock_is_file):
obs, use_temp = installer.extract_installer(game, installer_path, temp_dir, "en")
self.assertEqual(exp, obs)

# TODO: Delete - innoextract not used for installation anymore
@mock.patch('subprocess.Popen')
@mock.patch('shutil.which')
def test3_extract_installer(self, mock_which, mock_subprocess):
"""[scenario: innoextract, unpack success]"""
mock_which.return_value = True
mock_subprocess().poll.return_value = 0
mock_subprocess().stdout.readlines.return_value = ["stdout", "stderr"]
game = Game("Absolute Drift", install_dir="/home/makson/GOG Games/Absolute Drift", platform="windows")
installer_path = "/home/makson/.cache/minigalaxy/download/Absolute Drift/setup_absolute_drift_1.0f_(64bit)_(47863).exe"
temp_dir = "/home/makson/.cache/minigalaxy/extract/1136126792"
exp = ""
obs, use_temp = installer.extract_installer(game, installer_path, temp_dir, "en")
self.assertEqual(exp, obs)

@mock.patch('os.path.exists')
@mock.patch('os.listdir')
@mock.patch('subprocess.Popen')
Expand All @@ -115,47 +100,57 @@ def test_extract_linux(self, mock_subprocess, mock_listdir, mock_is_file):
obs, temp_used = installer.extract_linux(installer_path, temp_dir)
self.assertEqual(exp, obs)


@mock.patch('os.path.exists')
@mock.patch('minigalaxy.installer.extract_by_wine')
@mock.patch('shutil.which')
def test1_get_lang_with_innoextract(self, mock_which, mock_wine_extract):
def test1_get_lang_with_innoextract(self, mock_which, mock_wine_extract, mock_exists):
"""[scenario: no innoextract - default en-US used]"""
mock_which.return_value = False
mock_wine_extract.side_effect = lambda game, installer, lang: lang
mock_exists.return_value = True
installer_path = "/home/makson/.cache/minigalaxy/download/Absolute Drift/setup_absolute_drift_1.0f_(64bit)_(47863).exe"
game = Game("Absolute Drift", install_dir="/home/makson/GOG Games/Absolute Drift", platform="windows")
exp = "en-US"
obs, uses_temp = installer.extract_windows(game, installer_path, "en")
self.assertEqual(exp, obs)
# check that lang passed to the wine installer is set up correctly
mock_wine_extract.side_effect = lambda game, installer, lang: self.assertEqual(exp, lang)
installer.extract_windows(game, installer_path, "en")

@mock.patch('shutil.which')
@mock.patch('subprocess.Popen')
def test2_get_lang_with_innoextract(self, mock_subprocess):
def test2_get_lang_with_innoextract(self, mock_subprocess, mock_which):
"""[scenario: innoextract --list-languages returns locale ids]"""
lines = [" - fr-FR\n", " - jp-JP\n", " - en-US\n", " - ru-RU\n", ""] # last is 'EOF'

mock_subprocess().poll.return_value = 0
mock_subprocess().stdout.readline.return_value = " - fr-FR\n - jp-JP\n - en-US\n - ru-RU"
mock_subprocess().stdout.readline.side_effect = lambda: lines.pop(0)
mock_which.return_value = '/bin/innoextract'
installer_path = "/home/makson/.cache/minigalaxy/download/Absolute Drift/setup_absolute_drift_1.0f_(64bit)_(47863).exe"
exp = "jp-JP"
obs = installer.match_game_lang_to_installer(installer_path, "jp")
self.assertEqual(exp, obs)

@mock.patch('shutil.which')
@mock.patch('subprocess.Popen')
def test3_get_lang_with_innoextract(self, mock_subprocess):
def test3_get_lang_with_innoextract(self, mock_subprocess, mock_which):
"""[scenario: innoextract --list-languages returns language names]"""
lines = [" - english: English\n", " - german: Deutsch\n", " - french: Français\n", ""] # last is 'EOF'
mock_subprocess().poll.return_value = 0
mock_subprocess().stdout.readline.return_value = " - english: English\n - german: Deutsch\n - french: Français"
mock_subprocess().stdout.readline.side_effect = lambda: lines.pop(0)
mock_which.return_value = '/bin/innoextract'
installer_path = "/home/makson/.cache/minigalaxy/download/Absolute Drift/setup_absolute_drift_1.0f_(64bit)_(47863).exe"
exp = "french"
obs = installer.match_game_lang_to_installer(installer_path, "fr")
self.assertEqual(exp, obs)


@mock.patch('shutil.which')
@mock.patch('subprocess.Popen')
def test4_get_lang_with_innoextract(self, mock_subprocess):
def test4_get_lang_with_innoextract(self, mock_subprocess, mock_which):
"""[scenario: innoextract --list-languages can't be matched - default en-US is used]"""
mock_subprocess().poll.return_value = 0
mock_subprocess().stdout.readline.return_value = " - fr-FR\n - jp-JP\n - en-US\n - ru-RU"
mock_subprocess().stdout.readline.return_value = ""
mock_which.return_value = '/bin/innoextract'
installer_path = "/home/makson/.cache/minigalaxy/download/Absolute Drift/setup_absolute_drift_1.0f_(64bit)_(47863).exe"
exp = "en-US"
obs = installer.match_game_lang_to_installer(installer_path, "")
obs = installer.match_game_lang_to_installer(installer_path, "en")
self.assertEqual(exp, obs)

@mock.patch('subprocess.Popen')
Expand Down

0 comments on commit 00759e4

Please sign in to comment.