lutris/tests/test_installer.py

52 lines
1.7 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
2013-07-11 12:53:12 +00:00
class MockInterpreter(ScriptInterpreter):
"""A script interpreter mock."""
2014-04-22 22:44:58 +00:00
script = {'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):
2014-04-22 22:44:58 +00:00
script = {
'runner': 'wine',
2014-04-22 22:44:58 +00:00
'installer': 'bar',
2015-03-04 14:28:05 +00:00
'name': 'baz',
'game_slug': 'baz',
2014-04-22 22:44:58 +00:00
}
interpreter = ScriptInterpreter(script, 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',
'installer': {},
2015-03-04 14:28:05 +00:00
'name': 'missing_runner',
'game_slug': 'missing-runner'
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):
2014-04-22 22:44:58 +00:00
interpreter = MockInterpreter({}, 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):
""" """
2014-04-22 22:44:58 +00:00
interpreter = MockInterpreter({}, 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.")