From bf7d7f91a1fc00c33758fc4f9648d672a0c38fda Mon Sep 17 00:00:00 2001 From: Antoine Mazeas Date: Wed, 18 Jan 2023 00:07:19 +0100 Subject: [PATCH] Add test for handling noop when missing lib Signed-off-by: Antoine Mazeas --- lutris/util/moddb.py | 4 ++-- tests/test_moddb_helper.py | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/lutris/util/moddb.py b/lutris/util/moddb.py index 9e37f0391..b456607c5 100644 --- a/lutris/util/moddb.py +++ b/lutris/util/moddb.py @@ -18,8 +18,8 @@ def _try_import_moddb_library(): logger.warn('The moddb library is not available, though the installer is attempting to install a file hosted on moddb.com. The moddb.com URLs will not be transformed, and rather passed as-is.') class ModDB: - def __init__(self, parse_page_method: types.MethodType=None): - self.moddb_lib = _try_import_moddb_library() + def __init__(self, parse_page_method: types.MethodType=None, moddb_lib: types.ModuleType=_try_import_moddb_library()): + self.moddb_lib = moddb_lib self.parse = parse_page_method if self.parse is None and self.moddb_lib is not None: self.parse = self.moddb_lib.parse_page diff --git a/tests/test_moddb_helper.py b/tests/test_moddb_helper.py index 4792eae53..463d34bd9 100644 --- a/tests/test_moddb_helper.py +++ b/tests/test_moddb_helper.py @@ -40,6 +40,13 @@ class ModDBHelperTests(unittest.TestCase): hlpr = ModDB(custom) self.assertEqual(hlpr.parse, custom) + ## missing moddb lib handling + def test_transform_url_missing_lib_noop(self): + moddb_url = 'https://www.moddb.com/downloads/mirror/somethingsomething' + hlpr = ModDB(moddb_lib=None) + transformed = hlpr.transform_url(moddb_url) + self.assertEqual(transformed, moddb_url) + ## transform_url def test_transform_url_url_is_mirror_with_www_throws(self): moddb_url = 'https://www.moddb.com/downloads/mirror/somethingsomething'