Skip to content

Commit a7d4cf0

Browse files
committed
test: fix check_env tests
1 parent de557b3 commit a7d4cf0

File tree

1 file changed

+56
-10
lines changed

1 file changed

+56
-10
lines changed

umu/umu_test.py

+56-10
Original file line numberDiff line numberDiff line change
@@ -3552,24 +3552,70 @@ 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+
with patch.object(umu_run, "get_umu_proton", new_callable=mock_get_umu_proton):
35603570
os.environ["WINEPREFIX"] = self.test_file
3561-
umu_run.check_env(self.env, thread_pool)
3571+
result = umu_run.check_env(self.env, self.test_session_pools)
3572+
self.assertTrue(result, self.env)
3573+
self.assertEqual(os.environ["GAMEID"], mock_gameid)
3574+
self.assertEqual(os.environ["GAMEID"], self.env["GAMEID"])
3575+
self.assertEqual(os.environ["PROTONPATH"], mock_protonpath)
3576+
self.assertEqual(os.environ["PROTONPATH"], mock_protonpath)
3577+
self.assertTrue(
3578+
Path(os.environ["WINEPREFIX"]).is_dir(), "Expected WINEPREFIX to exist"
3579+
)
35623580

35633581
def test_env_vars_none(self):
35643582
"""Tests check_env when setting no env vars.
35653583
3566-
GAMEID should be the only strictly required env var
3584+
Expects PROTONPATH, GAMEID, and WINEPREFIX to be set for the below
3585+
command line:
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 and WINE prefix is created
35683602
with (
3569-
self.assertRaisesRegex(ValueError, "GAMEID"),
3570-
ThreadPoolExecutor() as thread_pool,
3603+
patch.object(umu_run, "get_umu_proton", new_callable=mock_get_umu_proton),
3604+
patch.object(Path, "mkdir", return_value=mock_set_wineprefix()),
35713605
):
3572-
umu_run.check_env(self.env, thread_pool)
3606+
result = umu_run.check_env(self.env, self.test_session_pools)
3607+
self.assertTrue(result, self.env)
3608+
self.assertEqual(os.environ["GAMEID"], mock_gameid)
3609+
self.assertEqual(os.environ["GAMEID"], self.env["GAMEID"])
3610+
self.assertEqual(os.environ["PROTONPATH"], mock_protonpath)
3611+
self.assertEqual(os.environ["PROTONPATH"], self.env["PROTONPATH"])
3612+
self.assertEqual(os.environ["WINEPREFIX"], mock_wineprefix)
3613+
self.assertEqual(os.environ["WINEPREFIX"], self.env["WINEPREFIX"])
3614+
3615+
# Assert only PROTONPATH as WINEPREFIX involves $HOME
3616+
self.assertTrue(
3617+
self.test_proton_dir.is_dir(), "Expected PROTONPATH to exist"
3618+
)
35733619

35743620

35753621
if __name__ == "__main__":

0 commit comments

Comments
 (0)