2013-05-25 05:48:03 +00:00
|
|
|
from unittest import TestCase
|
- Replaced pipenv with poetry
- Updated min version check in setup.py to Python 3.6
- Updated isort config file and calls to align with v5.x
- Added init-hook for gi imports in .pylintrc to avoid invalid no-member issues
- Makefile: added lock, show-tree, bandit, black, mypy; updated test, cover, dev, isort, autopep8, check, isort-check, flake8, pylint; removed req, requirements;
- Updated .travis.yml to use poetry and make
- Added my email in AUTHORS
- Updated CONTRIBUTING.md
- Updated lint_python.yml to use poetry and make, reorganized instructions to have all install related steps first
- sorted imports: lutris, lutris-wrapper, cleanup_prefix.py and multiple files in tests dir
2021-10-24 18:42:06 +00:00
|
|
|
|
2015-10-03 18:07:54 +00:00
|
|
|
from lutris.installer.errors import ScriptingError
|
- Replaced pipenv with poetry
- Updated min version check in setup.py to Python 3.6
- Updated isort config file and calls to align with v5.x
- Added init-hook for gi imports in .pylintrc to avoid invalid no-member issues
- Makefile: added lock, show-tree, bandit, black, mypy; updated test, cover, dev, isort, autopep8, check, isort-check, flake8, pylint; removed req, requirements;
- Updated .travis.yml to use poetry and make
- Added my email in AUTHORS
- Updated CONTRIBUTING.md
- Updated lint_python.yml to use poetry and make, reorganized instructions to have all install related steps first
- sorted imports: lutris, lutris-wrapper, cleanup_prefix.py and multiple files in tests dir
2021-10-24 18:42:06 +00:00
|
|
|
from lutris.installer.interpreter import ScriptInterpreter
|
2013-05-25 05:48:03 +00:00
|
|
|
|
2017-05-01 09:17:33 +00:00
|
|
|
TEST_INSTALLER = {
|
|
|
|
'script': {
|
2018-11-19 01:53:10 +00:00
|
|
|
'game': {
|
|
|
|
'exe': 'test'
|
|
|
|
}
|
2017-05-01 09:17:33 +00:00
|
|
|
},
|
|
|
|
'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):
|
2015-10-03 18:07:54 +00:00
|
|
|
"""A script interpreter mock."""
|
2017-04-14 02:33:12 +00:00
|
|
|
runner = 'linux'
|
2013-07-11 12:53:12 +00:00
|
|
|
|
|
|
|
|
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)
|
2020-01-28 03:37:19 +00:00
|
|
|
self.assertEqual(interpreter.installer.game_name, 'Doom')
|
|
|
|
self.assertFalse(interpreter.installer.get_errors())
|
2013-05-25 05:48:03 +00:00
|
|
|
|
|
|
|
def test_move_requires_src_and_dst(self):
|
2014-04-22 22:44:58 +00:00
|
|
|
script = {
|
|
|
|
'foo': 'bar',
|
2020-01-28 03:37:19 +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',
|
2020-01-28 03:37:19 +00:00
|
|
|
'slug': 'some-slug',
|
|
|
|
'runner': 'linux',
|
2017-04-19 00:45:17 +00:00
|
|
|
'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:
|
2020-04-26 16:42:38 +00:00
|
|
|
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.")
|