2012-11-09 14:41:11 +00:00
|
|
|
import logging
|
2015-11-13 08:34:11 +00:00
|
|
|
from unittest.mock import patch
|
2012-11-09 14:41:11 +00:00
|
|
|
|
2014-08-12 22:35:47 +00:00
|
|
|
from lutris.config import LutrisConfig
|
2012-11-09 14:41:11 +00:00
|
|
|
from lutris import runners
|
2014-10-09 20:20:30 +00:00
|
|
|
from test_pga import DatabaseTester
|
2012-11-09 14:41:11 +00:00
|
|
|
|
|
|
|
LOGGER = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
2014-10-09 20:20:30 +00:00
|
|
|
class ImportRunnerTest(DatabaseTester):
|
2012-11-09 14:41:11 +00:00
|
|
|
def test_runner_modules(self):
|
|
|
|
runner_list = runners.__all__
|
|
|
|
self.assertIn("linux", runner_list)
|
|
|
|
self.assertIn("wine", runner_list)
|
2017-05-15 01:03:35 +00:00
|
|
|
self.assertIn("libretro", runner_list)
|
2014-04-07 08:28:29 +00:00
|
|
|
self.assertIn("fsuae", runner_list)
|
2012-11-09 14:41:11 +00:00
|
|
|
|
|
|
|
def test_import_module(self):
|
|
|
|
for runner_name in runners.__all__:
|
|
|
|
runner_class = runners.import_runner(runner_name)
|
|
|
|
self.assertEqual(runner_class().__class__.__name__, runner_name)
|
|
|
|
|
|
|
|
def test_options(self):
|
|
|
|
for runner_name in runners.__all__:
|
|
|
|
LOGGER.info("Importing %s", runner_name)
|
|
|
|
runner_class = runners.import_runner(runner_name)
|
|
|
|
runner = runner_class()
|
|
|
|
self.assertTrue(hasattr(runner, 'game_options'),
|
|
|
|
"%s doesn't have game options" % runner_name)
|
2012-11-10 02:40:03 +00:00
|
|
|
self.assertTrue(hasattr(runner, 'runner_options'))
|
2012-11-09 14:41:11 +00:00
|
|
|
for option in runner.game_options:
|
|
|
|
self.assertIn('type', option)
|
|
|
|
self.assertFalse(option['type'] == 'single')
|
2014-08-12 22:35:47 +00:00
|
|
|
|
|
|
|
def test_get_system_config(self):
|
|
|
|
def fake_yaml_reader(path):
|
2014-08-17 16:10:26 +00:00
|
|
|
if not path:
|
|
|
|
return {}
|
2014-08-12 22:35:47 +00:00
|
|
|
if 'system.yml' in path:
|
2014-08-13 08:24:56 +00:00
|
|
|
return {'system': {'resolution': '640x480'}}
|
2014-08-12 22:35:47 +00:00
|
|
|
return {}
|
|
|
|
|
|
|
|
with patch('lutris.config.read_yaml_from_file') as yaml_reader:
|
|
|
|
yaml_reader.side_effect = fake_yaml_reader
|
|
|
|
wine_runner = runners.import_runner('wine')
|
|
|
|
wine = wine_runner()
|
2015-05-04 12:55:06 +00:00
|
|
|
self.assertEqual(wine.system_config.get('resolution'), '640x480')
|
2014-08-12 22:35:47 +00:00
|
|
|
|
|
|
|
def test_runner_config_overrides_system_config(self):
|
|
|
|
def fake_yaml_reader(path):
|
2014-08-17 16:10:26 +00:00
|
|
|
if not path:
|
|
|
|
return {}
|
2014-08-12 22:35:47 +00:00
|
|
|
if 'system.yml' in path:
|
|
|
|
return {'resolution': '640x480'}
|
|
|
|
if 'wine.yml' in path:
|
|
|
|
return {'system': {'resolution': '800x600'}}
|
|
|
|
return {}
|
|
|
|
|
|
|
|
with patch('lutris.config.read_yaml_from_file') as yaml_reader:
|
|
|
|
yaml_reader.side_effect = fake_yaml_reader
|
|
|
|
wine_runner = runners.import_runner('wine')
|
|
|
|
wine = wine_runner()
|
2015-05-04 12:55:06 +00:00
|
|
|
self.assertEqual(wine.system_config.get('resolution'), '800x600')
|
2014-08-12 22:35:47 +00:00
|
|
|
|
|
|
|
def test_game_config_overrides_all(self):
|
|
|
|
def fake_yaml_reader(path):
|
2014-08-17 16:10:26 +00:00
|
|
|
if not path:
|
|
|
|
return {}
|
2014-08-12 22:35:47 +00:00
|
|
|
if 'system.yml' in path:
|
2014-08-13 08:24:56 +00:00
|
|
|
return {'system': {'resolution': '640x480'}}
|
2014-08-12 22:35:47 +00:00
|
|
|
if 'wine.yml' in path:
|
|
|
|
return {'system': {'resolution': '800x600'}}
|
|
|
|
if 'rage.yml' in path:
|
|
|
|
return {'system': {'resolution': '1920x1080'}}
|
|
|
|
return {}
|
|
|
|
|
|
|
|
with patch('lutris.config.read_yaml_from_file') as yaml_reader:
|
|
|
|
yaml_reader.side_effect = fake_yaml_reader
|
|
|
|
wine_runner = runners.import_runner('wine')
|
2015-11-04 10:50:47 +00:00
|
|
|
game_config = LutrisConfig(game_config_id='rage',
|
|
|
|
runner_slug='wine')
|
2014-08-12 22:35:47 +00:00
|
|
|
wine = wine_runner(game_config)
|
2015-05-04 12:55:06 +00:00
|
|
|
self.assertEqual(wine.system_config.get('resolution'), '1920x1080')
|
2014-08-13 08:46:11 +00:00
|
|
|
|
|
|
|
def test_system_config_with_no_system_yml(self):
|
|
|
|
def fake_yaml_reader(path):
|
2014-08-17 16:10:26 +00:00
|
|
|
if not path:
|
|
|
|
return {}
|
2014-08-13 08:46:11 +00:00
|
|
|
if 'system.yml' in path:
|
|
|
|
return {}
|
|
|
|
if 'wine.yml' in path:
|
|
|
|
return {'system': {'resolution': '800x600'}}
|
|
|
|
if 'rage.yml' in path:
|
2014-08-13 09:12:41 +00:00
|
|
|
return {'system': {'resolution': '1680x1050'},
|
|
|
|
'runner': 'wine'}
|
2014-08-13 08:46:11 +00:00
|
|
|
return {}
|
|
|
|
|
|
|
|
with patch('lutris.config.read_yaml_from_file') as yaml_reader:
|
|
|
|
yaml_reader.side_effect = fake_yaml_reader
|
|
|
|
wine_runner = runners.import_runner('wine')
|
2015-11-04 10:50:47 +00:00
|
|
|
game_config = LutrisConfig(runner_slug='wine',
|
|
|
|
game_config_id='rage')
|
|
|
|
self.assertEqual(game_config.game_config_id, 'rage')
|
2015-04-20 18:50:34 +00:00
|
|
|
self.assertEqual(game_config.runner_slug, 'wine')
|
2014-08-13 08:46:11 +00:00
|
|
|
wine = wine_runner(game_config)
|
2015-05-04 12:55:06 +00:00
|
|
|
self.assertEqual(wine.system_config.get('resolution'), '1680x1050')
|