lutris/tests/test_installer.py

66 lines
2 KiB
Python
Raw Normal View History

2013-05-25 05:48:03 +00:00
from unittest import TestCase
from lutris.installer.interpreter import ScriptInterpreter
from lutris.installer.errors import ScriptingError
2013-05-25 05:48:03 +00:00
2017-05-01 09:17:33 +00:00
TEST_INSTALLER = {
'script': {
'game': 'test'
},
'version': 'test',
'game_slug': 'test',
'name': 'test',
'slug': 'test',
'runner': 'linux'
}
2013-05-25 05:48:03 +00:00
2013-07-11 12:53:12 +00:00
class MockInterpreter(ScriptInterpreter):
"""A script interpreter mock."""
2017-04-14 02:33:12 +00:00
runner = 'linux'
2013-07-11 12:53:12 +00:00
def is_valid(self):
return True
2013-05-25 05:48:03 +00:00
class TestScriptInterpreter(TestCase):
def test_script_with_correct_values_is_valid(self):
2017-04-14 02:33:12 +00:00
installer = {
'runner': 'linux',
'script': {'exe': 'doom'},
'name': 'Doom',
'slug': 'doom',
'game_slug': 'doom',
2017-04-19 00:45:17 +00:00
'version': 'doom-gzdoom'
2014-04-22 22:44:58 +00:00
}
2017-04-14 02:33:12 +00:00
interpreter = ScriptInterpreter(installer, None)
2013-05-25 05:48:03 +00:00
self.assertFalse(interpreter.errors)
self.assertTrue(interpreter.is_valid())
def test_move_requires_src_and_dst(self):
2014-04-22 22:44:58 +00:00
script = {
'foo': 'bar',
2017-04-14 02:33:12 +00:00
'script': [],
2015-03-04 14:28:05 +00:00
'name': 'missing_runner',
2017-04-19 00:45:17 +00:00
'game_slug': 'missing-runner',
'version': 'bar-baz'
2014-04-22 22:44:58 +00:00
}
2013-05-25 05:48:03 +00:00
with self.assertRaises(ScriptingError):
2014-04-22 22:44:58 +00:00
interpreter = ScriptInterpreter(script, None)
2013-05-25 05:48:03 +00:00
interpreter._get_move_paths({})
2013-05-25 11:08:39 +00:00
def test_get_command_returns_a_method(self):
2017-05-01 09:17:33 +00:00
interpreter = MockInterpreter(TEST_INSTALLER, None)
2013-07-11 12:53:12 +00:00
command, params = interpreter._map_command({'move': 'whatever'})
2016-08-04 22:49:38 +00:00
self.assertIn("bound method CommandsMixin.move", str(command))
2013-05-25 11:08:39 +00:00
self.assertEqual(params, "whatever")
def test_get_command_doesnt_return_private_methods(self):
""" """
2017-05-01 09:17:33 +00:00
interpreter = MockInterpreter(TEST_INSTALLER, None)
2013-05-25 11:08:39 +00:00
with self.assertRaises(ScriptingError) as ex:
2013-07-11 12:53:12 +00:00
command, params = interpreter._map_command(
2013-05-25 11:08:39 +00:00
{'_substitute': 'foo'}
)
self.assertEqual(ex.exception.message,
2016-03-11 16:55:05 +00:00
"The command \"substitute\" does not exist.")