ulwgl_test: update tests for new usage

- Update the check_env tests for new usage when PROTONPATH is not set by mocking the callout.
This commit is contained in:
R1kaB3rN 2024-02-16 12:12:00 -08:00
parent f6aa2f31e9
commit d457847920
No known key found for this signature in database

View File

@ -1037,20 +1037,27 @@ class TestGameLauncher(unittest.TestCase):
result, Namespace, "Expected a Namespace from parse_arg" result, Namespace, "Expected a Namespace from parse_arg"
) )
def test_env_proton_dir(self): def test_env_proton_nodir(self):
"""Test check_env when $PROTONPATH is not a directory. """Test check_env when $PROTONPATH is not set on failing to setting it.
An ValueError should occur if the value is not a directory An FileNotFoundError should be raised when we fail to set PROTONPATH
""" """
with self.assertRaisesRegex(ValueError, "PROTONPATH"): result = None
# Mock getting the Proton
with self.assertRaises(FileNotFoundError):
with patch.object(
ulwgl_run,
"get_ulwgl_proton",
return_value=self.env,
):
os.environ["WINEPREFIX"] = self.test_file os.environ["WINEPREFIX"] = self.test_file
os.environ["GAMEID"] = self.test_file os.environ["GAMEID"] = self.test_file
os.environ["PROTONPATH"] = "./foo" result = ulwgl_run.check_env(self.env)
ulwgl_run.check_env(self.env) # Mock setting it on success
self.assertFalse( os.environ["PROTONPATH"] = self.test_file
Path(os.environ["PROTONPATH"]).is_dir(), self.assertTrue(result is self.env, "Expected the same reference")
"Expected PROTONPATH to not be a directory", self.assertFalse(os.environ["PROTONPATH"])
)
def test_env_wine_dir(self): def test_env_wine_dir(self):
"""Test check_env when $WINEPREFIX is not a directory. """Test check_env when $WINEPREFIX is not a directory.
@ -1119,10 +1126,20 @@ class TestGameLauncher(unittest.TestCase):
def test_env_vars_proton(self): def test_env_vars_proton(self):
"""Test check_env when setting only $WINEPREFIX and $GAMEID.""" """Test check_env when setting only $WINEPREFIX and $GAMEID."""
with self.assertRaisesRegex(ValueError, "PROTONPATH"): with self.assertRaisesRegex(FileNotFoundError, "Proton"):
os.environ["WINEPREFIX"] = self.test_file os.environ["WINEPREFIX"] = self.test_file
os.environ["GAMEID"] = self.test_file os.environ["GAMEID"] = self.test_file
ulwgl_run.check_env(self.env) # Mock getting the Proton
with patch.object(
ulwgl_run,
"get_ulwgl_proton",
return_value=self.env,
):
os.environ["WINEPREFIX"] = self.test_file
os.environ["GAMEID"] = self.test_file
result = ulwgl_run.check_env(self.env)
self.assertTrue(result is self.env, "Expected the same reference")
self.assertFalse(os.environ["PROTONPATH"])
def test_env_vars_wine(self): def test_env_vars_wine(self):
"""Test check_env when setting only $WINEPREFIX.""" """Test check_env when setting only $WINEPREFIX."""