Files
darling-lol/tests/test_client_in_game_tricks.py
T
3AvisD 4faa622336 feat(launcher): select client-in-game mode from preferences
Add RCLOL_CLIENT_IN_GAME_TRICKS=1 as the practical launcher switch. It reads
lol-user-experience from LCULocalPreferences.yaml:

- potatoModeEnabled false or unreadable: no action;
- closeLeagueClientDuringGame true: close the client UI;
- closeLeagueClientDuringGame false: hide the client windows.

The existing close and hide switches remain low-level options when the
automatic switch is not set. The hide helper accepts the master switch, and
the resolver plus preference cases are covered by tests and documentation.

The local .desktop entry was validated with the master switch; the installed
preferences select hide on this machine.
2026-10-22 14:56:03 -06:00

70 lines
2.5 KiB
Python

"""Select the automatic client-in-game mode from LCULocalPreferences.yaml."""
import importlib.util
import io
import os
from pathlib import Path
import tempfile
import unittest
from unittest.mock import patch
ROOT = Path(__file__).resolve().parents[1]
spec = importlib.util.spec_from_file_location(
'client_in_game_tricks', ROOT / 'tools/client-in-game-tricks.py')
tricks = importlib.util.module_from_spec(spec)
spec.loader.exec_module(tricks)
class ClientInGameTricksTests(unittest.TestCase):
def setUp(self):
self.temp = tempfile.TemporaryDirectory()
self.addCleanup(self.temp.cleanup)
self.path = Path(self.temp.name) / 'LCULocalPreferences.yaml'
def write(self, optimization=None, close=None):
lines = ['lol-user-experience:', ' data:']
if optimization is not None:
lines.append(f' potatoModeEnabled: {optimization}')
if close is not None:
lines.append(f' closeLeagueClientDuringGame: {close}')
self.path.write_text('\n'.join(lines) + '\n')
def test_close_when_both_preferences_are_true(self):
self.write(True, True)
self.assertEqual(tricks.mode(self.path), 'close')
def test_hide_when_optimizations_are_on_and_close_is_false(self):
self.write(True, False)
self.assertEqual(tricks.mode(self.path), 'hide')
def test_hide_when_close_preference_is_missing(self):
self.write(True)
self.assertEqual(tricks.mode(self.path), 'hide')
def test_none_when_optimizations_are_off(self):
self.write(False, True)
self.assertEqual(tricks.mode(self.path), 'none')
def test_none_when_optimizations_are_missing_or_file_is_unreadable(self):
self.write(None, True)
self.assertEqual(tricks.mode(self.path), 'none')
self.assertEqual(tricks.mode(self.path.with_name('missing.yaml')), 'none')
def test_last_duplicate_value_wins_and_quotes_are_accepted(self):
self.path.write_text(
'potatoModeEnabled: false\n'
'closeLeagueClientDuringGame: false\n'
'potatoModeEnabled: "true"\n'
'closeLeagueClientDuringGame: "true"\n')
self.assertEqual(tricks.mode(self.path), 'close')
def test_main_prints_mode(self):
self.write(True, False)
output = io.StringIO()
with patch('sys.stdout', output):
self.assertEqual(tricks.main([str(self.path)]), 0)
self.assertEqual(output.getvalue().strip(), 'hide')
if __name__ == '__main__':
unittest.main()