Skip to content

Commit 45bd59d

Browse files
authored
test: fix check_env tests (#383)
1 parent 902adc8 commit 45bd59d

File tree

1 file changed

+57
-10
lines changed

1 file changed

+57
-10
lines changed

umu/umu_test.py

+57-10
Original file line numberDiff line numberDiff line change
@@ -3552,24 +3552,71 @@ def test_env_vars_proton(self):
35523552
self.assertFalse(os.environ["PROTONPATH"])
35533553

35543554
def test_env_vars_wine(self):
3555-
"""Test check_env when setting only $WINEPREFIX."""
3556-
with (
3557-
self.assertRaisesRegex(ValueError, "GAMEID"),
3558-
ThreadPoolExecutor() as thread_pool,
3559-
):
3555+
"""Test check_env when setting only $WINEPREFIX.
3556+
3557+
Expects GAMEID and PROTONPATH to be set for the command line:
3558+
"""
3559+
result = None
3560+
mock_gameid = "umu-default"
3561+
mock_protonpath = str(self.test_proton_dir)
3562+
3563+
def mock_get_umu_proton():
3564+
os.environ["PROTONPATH"] = mock_protonpath
3565+
return self.env
3566+
3567+
# Mock setting the PROTONPATH
3568+
# When running `WINEPREFIX=/some/path umu-run foo.exe` Proton is installed
3569+
# and the GAMEID is 'umu-default'
3570+
with patch.object(umu_run, "get_umu_proton", new_callable=mock_get_umu_proton):
35603571
os.environ["WINEPREFIX"] = self.test_file
3561-
umu_run.check_env(self.env, thread_pool)
3572+
result = umu_run.check_env(self.env, self.test_session_pools)
3573+
self.assertTrue(result, self.env)
3574+
self.assertEqual(os.environ["GAMEID"], mock_gameid)
3575+
self.assertEqual(os.environ["GAMEID"], self.env["GAMEID"])
3576+
self.assertEqual(os.environ["PROTONPATH"], mock_protonpath)
3577+
self.assertEqual(os.environ["PROTONPATH"], mock_protonpath)
3578+
self.assertTrue(
3579+
Path(os.environ["WINEPREFIX"]).is_dir(), "Expected WINEPREFIX to exist"
3580+
)
35623581

35633582
def test_env_vars_none(self):
35643583
"""Tests check_env when setting no env vars.
35653584
3566-
GAMEID should be the only strictly required env var
3585+
Expects PROTONPATH, GAMEID, and WINEPREFIX to be set
35673586
"""
3587+
result = None
3588+
mock_gameid = "umu-default"
3589+
mock_protonpath = str(self.test_proton_dir)
3590+
mock_wineprefix = "/home/foo/Games/umu/umu-default"
3591+
3592+
def mock_get_umu_proton():
3593+
os.environ["PROTONPATH"] = mock_protonpath
3594+
return self.env
3595+
3596+
def mock_set_wineprefix():
3597+
os.environ["WINEPREFIX"] = mock_wineprefix
3598+
return
3599+
3600+
# Mock setting the PROTONPATH and the WINEPREFIX creation
3601+
# When running `umu-run foo.exe` Proton is installed WINE prefix is created
3602+
# where the directory is 'umu-default', and the GAMEID is 'umu-default'
35683603
with (
3569-
self.assertRaisesRegex(ValueError, "GAMEID"),
3570-
ThreadPoolExecutor() as thread_pool,
3604+
patch.object(umu_run, "get_umu_proton", new_callable=mock_get_umu_proton),
3605+
patch.object(Path, "mkdir", return_value=mock_set_wineprefix()),
35713606
):
3572-
umu_run.check_env(self.env, thread_pool)
3607+
result = umu_run.check_env(self.env, self.test_session_pools)
3608+
self.assertTrue(result, self.env)
3609+
self.assertEqual(os.environ["GAMEID"], mock_gameid)
3610+
self.assertEqual(os.environ["GAMEID"], self.env["GAMEID"])
3611+
self.assertEqual(os.environ["PROTONPATH"], mock_protonpath)
3612+
self.assertEqual(os.environ["PROTONPATH"], self.env["PROTONPATH"])
3613+
self.assertEqual(os.environ["WINEPREFIX"], mock_wineprefix)
3614+
self.assertEqual(os.environ["WINEPREFIX"], self.env["WINEPREFIX"])
3615+
3616+
# Assert only PROTONPATH as WINEPREFIX involves $HOME
3617+
self.assertTrue(
3618+
self.test_proton_dir.is_dir(), "Expected PROTONPATH to exist"
3619+
)
35733620

35743621

35753622
if __name__ == "__main__":

0 commit comments

Comments
 (0)