2016-09-28 21:44:32 +00:00
|
|
|
import os
|
2015-11-13 08:34:11 +00:00
|
|
|
from collections import OrderedDict
|
2013-07-11 07:18:15 +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
|
|
|
|
2023-05-22 21:29:52 +00:00
|
|
|
from lutris.util.wine import wine
|
- 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.util import fileio, strings, system
|
2022-03-16 04:14:31 +00:00
|
|
|
from lutris.util.steam import vdfutils
|
2013-07-11 07:18:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
class TestFileUtils(TestCase):
|
|
|
|
def test_file_ids_are_correctly_transformed(self):
|
|
|
|
file_id = 'foo-bar'
|
2013-10-07 07:11:20 +00:00
|
|
|
self.assertEqual(system.python_identifier(file_id), 'foo-bar')
|
2013-07-11 07:18:15 +00:00
|
|
|
|
|
|
|
file_id = '${foo-bar}'
|
2013-10-07 07:11:20 +00:00
|
|
|
self.assertEqual(system.python_identifier(file_id), '${foo_bar}')
|
2013-07-11 07:18:15 +00:00
|
|
|
|
|
|
|
file_id = '${foo-bar} ${a-b}'
|
2013-10-07 07:11:20 +00:00
|
|
|
self.assertEqual(system.python_identifier(file_id), '${foo_bar} ${a_b}')
|
2013-07-11 07:18:15 +00:00
|
|
|
|
|
|
|
file_id = '${foo-bar} a-b'
|
2013-10-07 07:11:20 +00:00
|
|
|
self.assertEqual(system.python_identifier(file_id), '${foo_bar} a-b')
|
2013-07-11 07:18:15 +00:00
|
|
|
|
|
|
|
file_id = '${foo-bar-bang}'
|
2013-10-07 07:11:20 +00:00
|
|
|
self.assertEqual(system.python_identifier(file_id), '${foo_bar_bang}')
|
2013-07-11 07:18:15 +00:00
|
|
|
|
|
|
|
file_id = '${foo-bar bang}'
|
2013-10-07 07:11:20 +00:00
|
|
|
self.assertEqual(system.python_identifier(file_id), '${foo-bar bang}')
|
2013-07-11 12:42:30 +00:00
|
|
|
|
|
|
|
def test_file_ids_are_substitued(self):
|
|
|
|
fileid = '${foo-bar}'
|
|
|
|
_files = {
|
|
|
|
'foo-bar': "/foo/bar"
|
|
|
|
}
|
2013-10-07 07:11:20 +00:00
|
|
|
self.assertEqual(system.substitute(fileid, _files), "/foo/bar")
|
2013-11-17 04:27:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
class TestSteamUtils(TestCase):
|
|
|
|
def test_dict_to_vdf(self):
|
2015-11-13 08:34:11 +00:00
|
|
|
appstate = OrderedDict()
|
|
|
|
userconfig = OrderedDict()
|
|
|
|
userconfig['gameid'] = "13240"
|
|
|
|
userconfig['name'] = "Unreal Tournament"
|
|
|
|
appstate['UserConfig'] = userconfig
|
|
|
|
appstate['StateFlags'] = '4'
|
|
|
|
appstate['appID'] = '13240'
|
|
|
|
dict_data = OrderedDict()
|
|
|
|
dict_data['AppState'] = appstate
|
|
|
|
|
2013-11-17 04:27:33 +00:00
|
|
|
expected_vdf = """"AppState"
|
|
|
|
{
|
|
|
|
\t"UserConfig"
|
|
|
|
\t{
|
|
|
|
\t\t"gameid"\t\t"13240"
|
|
|
|
\t\t"name"\t\t"Unreal Tournament"
|
|
|
|
\t}
|
|
|
|
\t"StateFlags"\t\t"4"
|
|
|
|
\t"appID"\t\t"13240"
|
|
|
|
}"""
|
2022-03-16 04:14:31 +00:00
|
|
|
vdf_data = vdfutils.to_vdf(dict_data)
|
2013-11-17 04:27:33 +00:00
|
|
|
self.assertEqual(vdf_data.strip(), expected_vdf.strip())
|
2014-01-24 18:59:40 +00:00
|
|
|
|
|
|
|
|
|
|
|
class TestStringUtils(TestCase):
|
2020-06-11 13:45:35 +00:00
|
|
|
def test_slugify_with_nonwestern_name(self):
|
|
|
|
name = 'メイド☆ぱらだいす ~目指せ!メイドナンバーワン!~'
|
|
|
|
slug = strings.slugify(name)
|
|
|
|
self.assertTrue(len(slug) > 0)
|
|
|
|
|
2014-01-24 18:59:40 +00:00
|
|
|
def test_add_url_tags(self):
|
|
|
|
self.assertEqual(strings.add_url_tags("foo bar"), "foo bar")
|
|
|
|
self.assertEqual(
|
|
|
|
strings.add_url_tags("foo http://lutris.net bar"),
|
|
|
|
"foo <a href=\"http://lutris.net\">http://lutris.net</a> bar"
|
|
|
|
)
|
|
|
|
self.assertEqual(
|
|
|
|
strings.add_url_tags("http://lutris.net"),
|
|
|
|
"<a href=\"http://lutris.net\">http://lutris.net</a>"
|
|
|
|
)
|
|
|
|
text = "foo http://lutris.net bar http://strycore.com"
|
|
|
|
expected = (
|
|
|
|
'foo <a href="http://lutris.net">http://lutris.net</a> '
|
|
|
|
'bar <a href="http://strycore.com">http://strycore.com</a>'
|
|
|
|
)
|
|
|
|
self.assertEqual(strings.add_url_tags(text), expected)
|
2016-08-20 03:23:34 +00:00
|
|
|
|
2019-01-12 10:24:03 +00:00
|
|
|
def test_get_formatted_playtime(self):
|
2020-09-25 05:08:23 +00:00
|
|
|
self.assertEqual(strings.get_formatted_playtime(None), strings.NO_PLAYTIME)
|
2019-01-12 10:24:03 +00:00
|
|
|
self.assertEqual(strings.get_formatted_playtime(1.0), "1 hour")
|
|
|
|
self.assertEqual(strings.get_formatted_playtime(2.0), "2 hours")
|
2023-08-26 00:00:39 +00:00
|
|
|
self.assertEqual(strings.get_formatted_playtime('1.04'), "1 hour 2 minutes")
|
2021-01-14 05:12:42 +00:00
|
|
|
self.assertEqual(strings.get_formatted_playtime('-'), strings.NO_PLAYTIME)
|
2019-01-12 10:24:03 +00:00
|
|
|
self.assertEqual(strings.get_formatted_playtime(0.5), "30 minutes")
|
2023-08-26 00:00:39 +00:00
|
|
|
self.assertEqual(strings.get_formatted_playtime(1.5), "1 hour 30 minutes")
|
|
|
|
self.assertEqual(strings.get_formatted_playtime(45.90), "45 hours 53 minutes")
|
2016-08-20 03:23:34 +00:00
|
|
|
|
2020-10-06 06:17:13 +00:00
|
|
|
|
2016-08-20 03:23:34 +00:00
|
|
|
class TestVersionSort(TestCase):
|
2018-05-08 09:50:49 +00:00
|
|
|
def test_parse_version(self):
|
2023-05-22 21:29:52 +00:00
|
|
|
self.assertEqual(wine.parse_wine_version("3.6-staging"), ([3, 6], '-staging', ''))
|
2018-05-08 09:50:49 +00:00
|
|
|
|
2016-08-20 03:23:34 +00:00
|
|
|
def test_versions_are_correctly_sorted(self):
|
|
|
|
versions = ['1.8', '1.7.4', '1.9.1', '1.9.10', '1.9.4']
|
2023-05-22 21:29:52 +00:00
|
|
|
versions = wine.version_sort(versions)
|
2016-08-20 03:23:34 +00:00
|
|
|
self.assertEqual(versions[0], '1.7.4')
|
|
|
|
self.assertEqual(versions[1], '1.8')
|
|
|
|
self.assertEqual(versions[2], '1.9.1')
|
|
|
|
self.assertEqual(versions[3], '1.9.4')
|
|
|
|
self.assertEqual(versions[4], '1.9.10')
|
|
|
|
|
|
|
|
def test_version_sorting_supports_extra_strings(self):
|
|
|
|
versions = [
|
|
|
|
'1.8', '1.8-staging',
|
|
|
|
'1.7.4', '1.9.1',
|
|
|
|
'1.9.10-staging', '1.9.10',
|
|
|
|
'1.9.4', 'staging-1.9.4'
|
|
|
|
]
|
2023-05-22 21:29:52 +00:00
|
|
|
versions = wine.version_sort(versions)
|
2016-08-20 03:23:34 +00:00
|
|
|
self.assertEqual(versions[0], '1.7.4')
|
|
|
|
self.assertEqual(versions[1], '1.8')
|
|
|
|
self.assertEqual(versions[2], '1.8-staging')
|
|
|
|
self.assertEqual(versions[3], '1.9.1')
|
|
|
|
self.assertEqual(versions[4], '1.9.4')
|
|
|
|
self.assertEqual(versions[5], 'staging-1.9.4')
|
|
|
|
self.assertEqual(versions[6], '1.9.10')
|
|
|
|
self.assertEqual(versions[7], '1.9.10-staging')
|
|
|
|
|
|
|
|
def test_versions_can_be_reversed(self):
|
|
|
|
versions = ['1.9', '1.6', '1.7', '1.8']
|
2023-05-22 21:29:52 +00:00
|
|
|
versions = wine.version_sort(versions, reverse=True)
|
2016-08-20 03:23:34 +00:00
|
|
|
self.assertEqual(versions[0], '1.9')
|
|
|
|
self.assertEqual(versions[3], '1.6')
|
2016-09-28 21:44:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
class TestEvilConfigParser(TestCase):
|
|
|
|
def setUp(self):
|
|
|
|
self.config_path = os.path.join(os.path.dirname(__file__), 'test.ini')
|
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
if os.path.exists(self.config_path):
|
|
|
|
os.remove(self.config_path)
|
|
|
|
|
|
|
|
def test_config_parse_can_write_to_disk(self):
|
|
|
|
parser = fileio.EvilConfigParser(dict_type=fileio.MultiOrderedDict)
|
|
|
|
parser.add_section('Test')
|
|
|
|
parser.set('Test', 'key', 'value')
|
|
|
|
with open(self.config_path, 'wb') as config:
|
|
|
|
parser.write(config)
|
2016-10-20 22:48:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
class TestUnpackDependencies(TestCase):
|
|
|
|
def test_single_dependency(self):
|
|
|
|
string = 'quake'
|
|
|
|
dependencies = strings.unpack_dependencies(string)
|
|
|
|
self.assertEqual(dependencies, ['quake'])
|
|
|
|
|
|
|
|
def test_multiple_dependencies(self):
|
|
|
|
string = 'quake, quake-1,quake-steam, quake-gog '
|
|
|
|
dependencies = strings.unpack_dependencies(string)
|
|
|
|
self.assertEqual(dependencies, ['quake', 'quake-1', 'quake-steam', 'quake-gog'])
|
|
|
|
|
|
|
|
def test_dependency_options(self):
|
|
|
|
string = 'quake, quake-1,quake-steam | quake-gog|quake-humble '
|
|
|
|
dependencies = strings.unpack_dependencies(string)
|
|
|
|
self.assertEqual(dependencies, ['quake', 'quake-1', ('quake-steam', 'quake-gog', 'quake-humble')])
|
|
|
|
|
|
|
|
def test_strips_extra_commas(self):
|
|
|
|
string = ', , , ,, ,,,,quake, quake-1,quake-steam | quake-gog|quake-humble |||| , |, | ,|,| , '
|
|
|
|
dependencies = strings.unpack_dependencies(string)
|
|
|
|
self.assertEqual(dependencies, ['quake', 'quake-1', ('quake-steam', 'quake-gog', 'quake-humble')])
|
2017-12-14 06:37:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
class TestSubstitute(TestCase):
|
|
|
|
def test_can_sub_game_files_with_dashes_in_key(self):
|
|
|
|
replacements = {'steam-data': '/tmp'}
|
|
|
|
self.assertEqual(system.substitute('--path=$steam-data', replacements), '--path=/tmp')
|